Skip to content

Instantly share code, notes, and snippets.

@misodengaku
Created January 17, 2014 13:18
Show Gist options
  • Save misodengaku/8473232 to your computer and use it in GitHub Desktop.
Save misodengaku/8473232 to your computer and use it in GitHub Desktop.
crypto100 keysearch
#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