-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterface.c
41 lines (33 loc) · 950 Bytes
/
interface.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
#include "interface.h"
bool requestInput(char* hash){
printf("R\n");
fflush(stdout);
int cnt = scanf("%s", hash);
//check if command is accepted
if (cnt==0 || strcmp(hash, "NAK")==0){
hash[0]='\0';
return false;
}
//duplicate input to get large input string
for(int j=0;j<INPUT_MULT;j++)
for(int i=0;i<UNIQUE_INPUT_SIZE;i++)
hash[j*UNIQUE_INPUT_SIZE+i]=hash[i];
hash[INPUT_SIZE]='\0';//terminate input string
return true;
}
bool validateHash(char* hash, char* nonce){
//send verify command
hash[UNIQUE_INPUT_SIZE]='\0';
if (nonce[0]!='\0')
printf("V %s %s\n",hash, nonce);
else
printf("V %s NONE\n",hash); //send no match was found
fflush(stdout);
//check response
char response[10];
int cnt = scanf("%s", response);
if (cnt!=0 && strcmp(response, "ACK")==0){
return true;
}
return false;
}