forked from gouravthakur39/beginners-C-program-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EncryptDecryptXOR.c
33 lines (23 loc) · 879 Bytes
/
EncryptDecryptXOR.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
#include<stdio.h>
#include<string.h>
char XORkey[12] = {'F','P','k','k','Y','P','l','p','V','P','L','z'};
void encryptDecrypt();
int main() {
char sampleString[] = " This contains highly sensitive message\n" \
" coordinates : 23.445, 34.443\n" \
" All further messages MUST be send via\n" \
" XOR encryption only - Long Live Revolution!!\n" ;
printf("\nEncrypted String :\n");
encryptDecrypt(sampleString);
printf("\nDecyrpted String :\n");
encryptDecrypt(sampleString);
return 0;
}
void encryptDecrypt(char inputString[]) {
int i = 0;
int len = strlen(inputString);
for (i = 0; i < len; i++) {
inputString[i] = inputString[i] ^ XORkey[i % (sizeof(XORkey)/sizeof(char))];
printf("%c", inputString[i]);
}
}