Created
January 17, 2014 13:18
-
-
Save misodengaku/8473232 to your computer and use it in GitHub Desktop.
crypto100 keysearch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
#include <string.h> | |
#define KEYLENGTH 256 | |
int main(int argc, char **argv) { | |
FILE* input; | |
FILE* output; | |
FILE* cipher; | |
char k[KEYLENGTH + 1]; //"CENSORED"; | |
char c, p, o, t = 0; | |
int i = 0, j; | |
if (argc != 3) { | |
printf("USAGE: %s INPUT CIPHER\n", argv[0]); | |
return 0; | |
} | |
input = fopen(argv[1], "rb"); | |
cipher = fopen(argv[2], "rb"); | |
k[0] = 0; | |
while ((p = fgetc(input)) != EOF) { | |
o = fgetc(cipher) & 0xFF; | |
for (j = 0; j < 256; j++){ | |
c = (p + (j ^ t) + i*i) & 0xff; | |
if(o == c) | |
break; | |
} | |
if (o != c){ | |
printf("Key not found!\n"); | |
return; | |
} | |
k[i % KEYLENGTH] = j; | |
printf("%s\n", k); | |
t = p; | |
i++; | |
k[i] = 0; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment