forked from kothariji/competitive-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsymmetric_key_encryption.c
74 lines (67 loc) · 1.23 KB
/
symmetric_key_encryption.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include<iostream.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
int key1,key2;
char s,wish;
int choice;
printf("\nExpt No.3 \tSYMMETRIC ENCRYPTION AND DECRYPTION\t18/02/2013");
do {
cout<<"\n1:Sender side\n2:Receiver side\n3:exit(0)";
cout<<"\nEnter your choice:";
cin>>choice;
printf("\nAt Sender side:");
printf("\nEnter the key:");
scanf("%d",&key1);
printf("\nAt Receiver side:");
printf("\nEnter the key:");
scanf("%d",&key2);
printf("\nEnter the message:");
s=getchar();
if(key1==key2)
{
printf("\nKeys Match..you can proceed communication");
}
else
{
printf("\nKeys do not match...connection lost.....");
exit(0);
}
switch(choice)
{
case 1:
// printf("\nEncrypted text is: ");
while(s!='\n')
{
if(s==' ')
putchar(s);
else
{
putchar(s+key1);
}
s=getchar();
}
putchar(s);
break;
case 2:
while(s!='\n')
{
if(s==' ')
putchar(s);
else{
putchar(s-key2);
}
s=getchar();
}
putchar(s);
break;
default:
exit(0);
}
printf("\nDo you want to continue communnication:?(y or Y)");
scanf("%c",&wish);
} while(wish=='y'||wish=='Y');
return 0;
}