hf mf fchk - output style
[RRG-proxmark3.git] / tools / hitag2crack / crack3 / ht2crack3test.c
blob8d48cc914f29c2de3ef13eb85167bb110c8acf74
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
5 #include "hitagcrypto.h"
6 #include "ht2crackutils.h"
8 int main(int argc, char *argv[]) {
9 Hitag_State hstate;
10 FILE *fp;
11 char *line = NULL;
12 size_t linelen = 0;
13 long len = 0;
14 char *nr = NULL;
15 char *ar = NULL;
16 uint32_t arval;
17 uint32_t ks;
18 char *key;
19 char *uid;
21 if (argc < 4) {
22 printf("%s nRaRfile KEY UID\n", argv[0]);
23 exit(1);
26 fp = fopen(argv[1], "r");
27 if (!fp) {
28 printf("cannot open file\n");
29 exit(1);
32 if (!strncmp(argv[2], "0x", 2)) {
33 key = argv[2] + 2;
34 } else {
35 key = argv[2];
38 if (!strncmp(argv[3], "0x", 2)) {
39 uid = argv[3] + 2;
40 } else {
41 uid = argv[3];
44 while ((len = getline(&line, &linelen, fp)) > 0) {
45 if (len > 16) {
46 ar = strchr(line, ' ');
47 *ar = 0x00;
48 ar++;
49 ar[strlen(ar) - 1] = 0x00;
50 if (!strncmp(line, "0x", 2)) {
51 nr = line + 2;
52 } else {
53 nr = line;
55 hitag2_init(&hstate, rev64(hexreversetoulonglong(key)), rev32(hexreversetoulong(uid)), rev32(hexreversetoulong(nr)));
57 arval = strtol(ar, NULL, 16);
58 ks = hitag2_nstep(&hstate, 32);
61 if ((arval ^ ks) != 0xffffffff) {
62 printf("FAIL! nR = %s, aR = %s\n", line, ar);
63 } else {
64 printf("SUCCESS! nR = %s, aR = %s\n", line, ar);
69 fclose(fp);
71 return 0;