-
Notifications
You must be signed in to change notification settings - Fork 1
/
VigenereCipher.c
45 lines (37 loc) · 964 Bytes
/
VigenereCipher.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
#include <linux/string.h>
//#include <stdlib.h>
int vcEncrypt(char* message, char* key){
int msize = strlen(message);
int ksize = strlen(key);
char msgcpy[msize];
strcpy(msgcpy, message);
//char* ans = malloc((msize+1) * sizeof(char));
int i = 0;
for (i = 0; i < msize; i++) {
message[i] = msgcpy[i] + key[i%ksize];
}
return 10;
}
int vcDecrypt(char* message, char* key){
int msize = strlen(message);
int ksize = strlen(key);
char msgcpy[msize];
strcpy(msgcpy, message);
//char* ans = malloc((msize+1) * sizeof(char));
int i = 0;
for (i = 0; i < msize; i++) {
message[i] = msgcpy[i] - key[i%ksize];
}
return 10;
}
int main(){
char message[1024];
strcpy(message, "Brains");
printf("%s\n", message );
char* key = "\n";
vcEncrypt(message,key);
printf("encrypted - %s\n", message);
vcDecrypt(message,key);
printf("%s\n", message );
//printf("%s -> %s -> %s using %s \n", message, enc, dec, key);
}