all repos — cryptopals-challenges @ 08b7de53f2f279ab297af47e39a65a8bc7eccf32

cryptopals-challenges

set1/src/ch3-brute-force.c

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>

int main()
{
	uint8_t i = 0;
	size_t k;
	int8_t ciphertext[] = "\x1b\x37\x37\x33\x31\x36\x3f\x78\x15\x1b\x7f\x2b"
	                      "\x78\x34\x31\x33\x3d\x78\x39\x78\x28\x37\x2d\x36"
	                      "\x3c\x78\x37\x3e\x78\x3a\x39\x3b\x37\x36";
	int8_t attempt[sizeof(ciphertext) - 1];

	do {
		printf("i = %d\n", i);
		for (k = 0; k < sizeof(attempt); ++k) {
			attempt[k] = ciphertext[k] ^ i;
		}
		for (k = 0; k < sizeof(attempt); ++k) {
			putchar(attempt[k]);
		}
		putchar('\n');
		++i;
	} while (i < 255);

	return EXIT_SUCCESS;
}