-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrack.c
68 lines (51 loc) · 1.28 KB
/
crack.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
57
58
59
60
61
62
63
64
65
66
67
68
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <assert.h>
#include <stdint.h>
#include <string.h>
#include "otp.h"
uint8_t*
otp_crack(char *plaintext, uint8_t *encryption)
{
int i, length;
uint8_t *key;
length = strlen(plaintext);
key = (uint8_t*)calloc(length, sizeof(uint8_t));
for (i = 0; i < length; i++) {
key[i] = plaintext[i] ^ encryption[i];
}
return key;
}
int
main(int argc, char *argv[])
{
int option,
length;
char *key_string = NULL,
*plaintext = NULL,
*ciphertext = NULL;
uint8_t *key = NULL,
*encryption = NULL;
while ((option = getopt(argc, argv, "c:p:")) != -1) {
switch (option) {
case 'c':
ciphertext = optarg;
break;
case 'p':
plaintext = optarg;
break;
}
}
assert( ciphertext && plaintext );
length = strlen(plaintext);
assert( (strlen(ciphertext) / 2) == length );
encryption = hex_to_bytes(ciphertext);
key = otp_crack(plaintext, encryption);
key_string = bytes_to_hex(key, length);
printf("%s\n", key_string);
free(key);
free(key_string);
free(encryption);
return 0;
}