-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
54 lines (40 loc) · 879 Bytes
/
main.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
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "port.h"
#include "rawmode.h"
#include "calc.h"
/*************
* Main loop *
*************/
int main(int argc, char **argv)
{
uint8_t *key;
int secretLen;
if (argc != 2)
{
fprintf(stderr, "Usage : %s <key>\n", argv[0]);
return EXIT_FAILURE;
}
#ifndef _WIN32
mode_raw(1);
#endif
int epoch = 0;
int epoch_new = 0;
key = get_shared_secret(argv[1], &secretLen);
while(1)
{
if(mx_kbhit() != 0)
break;
epoch_new = (int)time(NULL) / 30;
if (epoch_new != epoch)
printf("\rCode : %06d\r\n", compute_code(key, secretLen, epoch_new));
epoch = epoch_new;
printf("\r%02d", 30 - (int)time(NULL) % 30);
fflush(stdout);
mx_sleep(100);
}
mode_raw(0);
printf("\n");
return EXIT_SUCCESS;
}