39 lines
935 B
C
39 lines
935 B
C
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include "spn.h"
|
||
|
|
||
|
int main(int argc, char const *argv[])
|
||
|
{
|
||
|
unsigned char ungarbled[5] = {'t','e','s','t','!'};
|
||
|
unsigned char garbled[5] = {0x52, 0xA3, 0x63, 0x52, 0x6B};
|
||
|
|
||
|
unsigned char perm[8] = {5,2,0,4,6,1,7,3};
|
||
|
unsigned char subst[16] = {3,8,14,1,12,5,10,0,2,7,9,11,4,6,15,13};
|
||
|
|
||
|
unsigned char iperm[8], isubst[16];
|
||
|
|
||
|
for (int i = 0; i < 8; i++) {
|
||
|
iperm[perm[i]] = i;
|
||
|
}
|
||
|
|
||
|
for (int i = 0; i < 16; i++) {
|
||
|
isubst[subst[i]] = i;
|
||
|
}
|
||
|
|
||
|
for (unsigned short key = 0; key < 65535; key++) {
|
||
|
int found = 0;
|
||
|
for (int j = 0; j < 5; j++) {
|
||
|
unsigned char w = decrypt(garbled[j], key, iperm, isubst);
|
||
|
//if (w != ungarbled[j]) break;
|
||
|
if (w == ungarbled[j]) found++;
|
||
|
}
|
||
|
|
||
|
|
||
|
if (found == 5) {
|
||
|
printf("key found: %04x\n", key);
|
||
|
//break;
|
||
|
}
|
||
|
}
|
||
|
return 0;
|
||
|
}
|