コード例 #1
0
int main() {
  uint16 desired = TARGET;
  scramble_item mst, current;
  uint8 found;

  for (int i = 7; i >= 0; i--) {
    printf("phase @d: desired @x\n", i, desired);
    found = 0;

    for (uint32 j = 0; j <= UINT16_MAX; j++) {
        current.i = j >> STATE_BITS;
        mst.i = j & TARGET_MASK;

        switch (i) {
        case 0:
          mst = phase_0(current, mst);
          break;
        case 1:
          mst = phase_1(mst, current);
          break;
        case 2:
          mst = phase_2(current, mst);
          break;
        case 3:
          mst = phase_3(mst, current);
          break;
        case 4:
          mst = phase_4(current, mst);
          break;
        case 5:
          mst = phase_5(mst, current);
          break;
        case 6:
          mst = phase_6(current, mst);
          break;
        case 7:
          mst = phase_7(mst, current);
          break;
        default:
          _terminate(-1);
        }

        mst.i &= TARGET_MASK;
        printf("\r@x", mst.i);

        if (mst.i == desired) {
          printf("\rinput @x instate @x\n", current.i, j & TARGET_MASK);
          found = 1;
          desired = j & TARGET_MASK;
          break;
        }
    }

    if (!found) {
      printf("\ndidn't find :( :( :( \n");
      _terminate(-1);
    }
  }
}
コード例 #2
0
void scramble_add(uint16 payload) {
  scramble_item current;
  current.i = payload;

  if (scramble_steps == 0) {
    state.i = 0;
  }

  switch (scramble_steps) {
  case 0:
    state = phase_0(current, state);
    break;
  case 1:
    state = phase_1(state, current);
    break;
  case 2:
    state = phase_2(current, state);
    break;
  case 3:
    state = phase_3(state, current);
    break;
  case 4:
    state = phase_4(current, state);
    break;
  case 5:
    state = phase_5(state, current);
    break;
  case 6:
    state = phase_6(current, state);
    break;
  case 7:
    state = phase_7(state, current);
    break;
  default:
    _terminate(-1);
  }

  state.i &= TARGET_MASK;

  scramble_steps++;
}
コード例 #3
0
ファイル: bomb.c プロジェクト: heapsters/le-bomb
int main(int argc, char *argv[])
{
    char *input;

    /* Note to self: remember to port this bomb to Windows and put a
     * fantastic GUI on it. */

    /* When run with no arguments, the bomb reads its input lines
     * from standard input. */
    if (argc == 1) {
	     infile = stdin;
    }

    /* When run with one argument <file>, the bomb reads from <file>
     * until EOF, and then switches to standard input. Thus, as you
     * defuse each phase, you can add its defusing string to <file> and
     * avoid having to retype it. */
    else if (argc == 2) {
	     if (!(infile = fopen(argv[1], "r"))) {
	        printf("%s: Error: Couldn't open %s\n", argv[0], argv[1]);
	        exit(8);
	      }
    }

    /* You can't call the bomb with more than 1 command line argument. */
    else {
	     printf("Usage: %s [<input_file>]\n", argv[0]);
	     exit(8);
    }

    /* Do all sorts of secret stuff that makes the bomb harder to defuse. */
    initialize_bomb();

    printf("Welcome to my fiendish little bomb. You have 6 phases with\n");
    printf("which to blow yourself up. Have a nice day!\n");

    /* Hmm...  Six phases must be more secure than one phase! */
    input = read_line();             /* Get input                   */
    phase_1(input);                  /* Run the phase               */
    phase_defused();                 /* Drat!  They figured it out!
				      * Let me know how they did it. */
    printf("Phase 1 defused. How about the next one?\n");

    /* The second phase is harder.  No one will ever figure out
     * how to defuse this... */
    input = read_line();
    phase_2(input);
    phase_defused();
    printf("That's number 2.  Keep going!\n");

    /* I guess this is too easy so far.  Some more complex code will
     * confuse people. */
    input = read_line();
    phase_3(input);
    phase_defused();
    printf("Halfway there!\n");

    /* Oh yeah?  Well, how good is your math?  Try on this saucy problem! */
    input = read_line();
    phase_4(input);
    phase_defused();
    printf("So you got that one.  Try this one.\n");

    /* Round and 'round in memory we go, where we stop, the bomb blows! */
    input = read_line();
    phase_5(input);
    phase_defused();
    printf("Good work!  On to the next...\n");

    /* This phase will never be used, since no one will get past the
     * earlier ones.  But just in case, make this one extra hard. */
    input = read_line();
    phase_6(input);
    phase_defused();

    /* Wow, they got it!  But isn't something... missing?  Perhaps
     * something they overlooked?  Mua ha ha ha ha! */

    return 0;
}
コード例 #4
0
ファイル: bomb.c プロジェクト: bipinprasad/vishal
int main(int argc, char *argv[])
{
    char *input;

    /* When run with no arguments, the bomb reads its input lines
     * from standard input. */
    if (argc == 1) {
	infile = stdin;
    }

    /* When run with one argument <file>, the bomb reads from <file>
     * until EOF, and then switches to standard input. Thus, as you
     * defuse each phase, you can add its defusing string to <file> and
     * avoid having to retype it. */
    else if (argc == 2) {
	if (!(infile = fopen(argv[1], "r"))) {
	    printf("%s: Error: Couldn't open %s\n", argv[0], argv[1]);
	    exit(8);
	}
    }

    /* You can't call the bomb with more than 1 command line argument. */
    else {
	printf("Usage: %s [<input_file>]\n", argv[0]);
	exit(8);
    }

    initialize_bomb();

    printf("Welcome to your cs154 \"bomb\". It has 6 phases, which must be\n");
    printf("\"defused\" in sequence by entering correct strings. Good luck.\n");

    input = read_line();             /* Get input                   */
    phase_1(input);                  /* Run the phase               */
    phase_defused();
    printf("Phase 1 defused. How about the next one?\n");

    input = read_line();
    phase_2(input);
    phase_defused();
    printf("Phase 2 done. Keep going!\n");

    input = read_line();
    phase_3(input);
    phase_defused();
    printf("Phase 3 cleared. Halfway there!\n");

    input = read_line();
    phase_4(input);
    phase_defused();
    printf("Phase 4 passed. Try this one.\n");

    input = read_line();
    phase_5(input);
    phase_defused();
    printf("Phase 5 finished. On to the next...\n");

    input = read_line();
    phase_6(input);
    phase_defused();

    /* All phases done.  But isn't something... missing?  Something secret,
       something extra that might have been overlooked? */

    return 0;
}