forked from kokke/tiny-AES-c
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrute.c
56 lines (51 loc) · 2.14 KB
/
brute.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "aes.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
const uint8_t iv[16] = {0xa0, 0x72, 0xa5, 0xb0, 0xf4, 0xb7, 0x15, 0xbf, 0x23, 0xb9, 0x7b, 0x1c, 0xec, 0xe8, 0x17, 0xf2};
const uint8_t key[16] = {0x9f, 0x24, 0xd4, 0x31, 0x8b, 0x92, 0xa6, 0x5f, 0x35, 0x37, 0xa0, 0x26, 0x59, 0xb9, 0x53, 0x40};
uint8_t a[8] = {4, 198, 168, 137, 49, 105, 188, 62};
uint8_t output[1130] = {0};
uint8_t input[112] = {0xa5, 0x34, 0xe6, 0x1d, 0xb3, 0xe6, 0xc, 0xcf, 0xa9, 0xc3, 0xb6, 0x29, 0xfc, 0x8d, 0x49, 0x2f, 0x4a, 0xa0, 0x7d, 0x65, 0xc7, 0x56, 0xec, 0xd6, 0x1f, 0x76, 0x41, 0x3d, 0xa5, 0xad, 0x4c, 0xb8, 0x93, 0x93, 0xb5, 0x77, 0x7e, 0x5c, 0x57, 0x2a, 0x76, 0x79, 0x82, 0x30, 0x9a, 0xe7, 0x9d, 0x5f, 0x44, 0xa2, 0x3e, 0xb7, 0x1f, 0x4c, 0x8f, 0xee, 0x33, 0x90, 0xdb, 0xa9, 0xa4, 0x51, 0x70, 0xc0, 0x86, 0xf7, 0xf1, 0x2b, 0xc6, 0xb, 0xd5, 0x5b, 0xcb, 0x4c, 0x36, 0x6e, 0x61, 0x7b, 0xc7, 0xd6, 0xf9, 0x28, 0x2f, 0x4a, 0xdb, 0xb4, 0xdf, 0x94, 0x76, 0xa7, 0x9e, 0x33, 0x5e, 0x3d, 0xc0, 0x87, 0x1a, 0x87, 0x9e, 0xdb, 0x3f, 0x61, 0x83, 0x83, 0x91, 0xb, 0x95, 0xc9, 0xba, 0x4e, 0xdf, 0x4a};
uint8_t tinput[112];
void swap(int i, int j)
{
// printf("%d %d\n", i, j);
// printf("%02x %02x %02x %02x %02x %02x %02x %02x\n", a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7]);
uint8_t temp;
temp = a[i];
// printf("%02x %02x", a[i], a[j]);
a[i] = a[j];
a[j] = temp;
// printf("%02x %02x %02x %02x %02x %02x %02x %02x\n", a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7]);
}
int k;
void permute(uint8_t *a, int l, int r)
{
int i;
if (l == r) {
memcpy(tinput, input, 112);
AES_CBC_decrypt_buffer(output, tinput, 112, key, iv, a);
k++;
// printf("%02x %02x %02x %02x %02x %02x %02x %02x\n", a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7]);
int q;
for (q = 0; q < 100; q++) {
if(output[q] == 'S' && output[q+1] == 'E')
printf("%s\n", output);
}
}
else
{
for (i = l; i <= r; i++)
{
swap(l, i);
permute(a, l+1, r);
swap(l, i); //backtrack
}
}
}
int main() {
k = 0;
permute(a, 0, 7);
printf("%d\n", k);
}