-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencDec.c
More file actions
41 lines (32 loc) · 1.46 KB
/
encDec.c
File metadata and controls
41 lines (32 loc) · 1.46 KB
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
#define BLOCKSIZE 16
#include <stdio.h> /* for fprintf, sprintf */
#include <stdlib.h> /* for exit */
#include <errno.h> /* error handling */
#include <string.h> /* for ? */
#include "encDec_funcs.h"
/* compile with: make */
/* check memory leak with: valgrind --leak-check=yes */
int main(int argc, char *argv[]) {
char *ifile = NULL; /* to point to input file name */
FILE *fip = NULL; /* to point to opened input file */
char *ofile = NULL; /* to point to output file name */
FILE *fop = NULL; /* to point to opened output file */
char *kfile = NULL; /* to point to key file name */
FILE *fkp = NULL; /* to point to opened key file */
unsigned char block[BLOCKSIZE]; /* to hold bytes read from input file */
unsigned char key[BLOCKSIZE]; /* to hold key for encryption/decryption read from key file */
parseArgs(argc, argv, &ifile, &ofile, &kfile); /* parse arguments and return pointers to filenames */
fip = Fopen(ifile, "r");
fop = Fopen(ofile, "w");
fkp = Fopen(kfile, "r");
readKey(key, BLOCKSIZE, fkp); /* read the key for encryption/decryption */
encryptDecrypt(block, key, BLOCKSIZE, fip, fop); /* encrypt/decrypt the input file and write to output file */
Fclose(fip);
Fclose(fop);
Fclose(fkp);
/* Freeing memory to prevent memory leak */
free(ifile);
free(ofile);
free(kfile);
return 0;
}