-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathotp_enc.c
85 lines (43 loc) · 1.79 KB
/
otp_enc.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
/**************************************************
* Joshua Reed
* EECS OregonState
* CS 344 Operating Systems
* Program otp_enc.c
* This program accepts a key file, a plaintext file,
* and a port number. It reads these files and sends the
* info to otp_enc_d.c to be encoded
*************************************************/
#include "oneheader.h" // function prototypes are in here
int main(int argc, char *argv[])
{
/* Check for appropriate number arguements for usage */
if (argc < 3)error("Usage otp_enc plaintextfile keytextfile portno\n",1);
FILE *pTextFP,*keyTextFP; // File pointers
/* Open files for reading */
pTextFP = fopen(argv[1],"r");
keyTextFP = fopen(argv[2],"r");
/* Check that the files opened successfully */
if(pTextFP==NULL)error("ERROR opening plaintext file for input",2);
if(keyTextFP==NULL)error("ERROR opening keytext file for input",2);
/* Check that the keytext file is at least as big as the plaintext file */
if(fSize(pTextFP)>fSize(keyTextFP))error("ERROR pText is larger than keyText",2);
/* Check the files for out of range chars */
if(checkContents(pTextFP))error("ERROR pText contains bad char data",2);
if(checkContents(keyTextFP))error("ERROR pText contains bad char data",2);
/* Setup a socket */
int sockfd = sockSetup(atoi(argv[3]));
/* Authorize server by listening for one time code */
sendAuth(sockfd,"encAck"); // exits if not correct server
/* Transmit key and ptext files */
sendFile(pTextFP,sockfd);
sendFile(keyTextFP,sockfd);
/* close open files */
fclose(pTextFP);
fclose(keyTextFP);
/* Receive cipher text */
char cipherText[290000]; // This should be made dynamic in a professional program
receive(cipherText,sockfd);
close(sockfd);
printf("%s\n", cipherText);
return (0);
}