Example #1
0
void single_byte_xor(char *hexString){
  int elements = 64;
  //char hex[16] = {'0','1','2', '3', '4','5','6','7','8','9', 'a', 'b', 'c', 'd', 'e', 'f'};
  char hex[64] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N','O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0','1','2', '3', '4','5','6','7','8','9' };

  int length = strlen(hexString);
  int i, j;

  for ( i = 0; i < elements; i++){
    char buffer[length];
    char letter = hex[i];

    if ( letter >= 64 || letter <= 90){
      for ( j = 0; j < length; j+=2){
          int num = (int)letter;
          buffer[j] = (num/10) + '0';
          buffer[j+1] = (num - (num/10)*10) + '0';
      }
    }
    else {
      for ( j = 0; j < length; j++)
          buffer[j] = letter;
    }

    buffer[length] = '\0';

    //xor string
    char *result = fixed_xor(hexString, buffer);
    printf("Character used: %c\n", letter);
    printf("buffer 1: %s\nbuffer 2: %s\n", buffer, hexString);
    printf("%s\n\n", result );
    //printf("Hex: %s\n\n", result );

  }
}
Example #2
0
void challenge_27()
{
	unsigned char ct[128] = {0}, pt[128] = {0};
	int length = source_27(NULL, 0, ct);

	int i;
	for (i = 0; i < 16; ++i) {
		ct[i + 16] = 0;
		ct[i + 32] = ct[i];
	}

	int result = receiver_27(ct, length, pt);

	unsigned char key[16] = {0};
	if (result) {
		fixed_xor(pt, pt + 32, 16, key);
		if (memcmp(get_static_key(), key, 16) == 0) {
			print_str("Key recovered.");
		} else {
			print_str("Key incorrect.");
		}
	} else {
		print_str("No high-ASCII error received.");
	}
}
Example #3
0
TEST test_fixed_xor(void)
{
    uint8_t buff[] = {0x13, 0x37};
    uint8_t expected[] = {0x00, 0x00};

    uint8_t *outbuff = NULL;

    // Positive tests.
    ASSERT_EQm("fixed_xor didn't work", CALL_OK, fixed_xor(sizeof(buff), buff, buff, &outbuff));
    ASSERT_EQm("Result didn't match expected", 0, memcmp(outbuff, expected, sizeof(buff)));

    // Negative tests.
    ASSERT_EQm("Bad length fail", CALL_BAD_INPUT, fixed_xor(0, NULL, NULL, NULL));

    ASSERT_EQm("Valid buff1 fail", CALL_BUFFER_NULL, fixed_xor(sizeof(buff), buff, NULL, NULL));
    ASSERT_EQm("Valid buff2 fail", CALL_BUFFER_NULL, fixed_xor(sizeof(buff), buff, buff, NULL));

    PASS();
}
Example #4
0
TEST set1_challenge2(void)
{
    char *buff1 = "1c0111001f010100061a024b53535009181c";
    char *buff2 = "686974207468652062756c6c277320657965";
    char *expected = "746865206b696420646f6e277420706c6179";

    uint8_t *buff1_bytes = (uint8_t *)malloc(strlen(buff1));
    uint8_t *buff2_bytes = (uint8_t *)malloc(strlen(buff2));
    uint8_t *expected_bytes = (uint8_t *)malloc(strlen(expected));

    size_t numbytes = strlen(expected) / 2;

    if(buff1_bytes == NULL || buff2_bytes == NULL || expected_bytes == NULL) {
        FAILm("Unable to allocate buffers.");
    }

    retval_t retval = hex2bytes(buff1, numbytes, buff1_bytes);
    if(retval != CALL_OK) {
        FAILm("Unable to convert buff1 to bytes.");
    }
    retval = hex2bytes(buff2, numbytes, buff2_bytes);
    if(retval != CALL_OK) {
        FAILm("Unable to convert buff2 to bytes.");
    }
    retval = hex2bytes(expected, numbytes, expected_bytes);
    if(retval != CALL_OK) {
        FAILm("Unable to convert expected to bytes.");
    }

    uint8_t *result = NULL;
    retval = fixed_xor(numbytes, buff1_bytes, buff2_bytes, &result);
    if(retval != CALL_OK) {
        FAILm("fixed_xor() failed");
    }

    ASSERT_EQm("Result didn't match expected", 0, memcmp(result, expected_bytes, numbytes));

    free(result);
    free(expected_bytes);
    free(buff2_bytes);
    free(buff1_bytes);

    PASS();
}