Skip to content

Commit 8dab349

Browse files
committed
added symmetric_key_encryption.c in cryptographic algos
1 parent f73a65e commit 8dab349

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#include<iostream.h>
2+
#include<stdio.h>
3+
#include<string.h>
4+
#include<stdlib.h>
5+
int main()
6+
{
7+
int key1,key2;
8+
char s,wish;
9+
int choice;
10+
printf("\nExpt No.3 \tSYMMETRIC ENCRYPTION AND DECRYPTION\t18/02/2013");
11+
do {
12+
cout<<"\n1:Sender side\n2:Receiver side\n3:exit(0)";
13+
cout<<"\nEnter your choice:";
14+
cin>>choice;
15+
16+
printf("\nAt Sender side:");
17+
printf("\nEnter the key:");
18+
scanf("%d",&key1);
19+
20+
printf("\nAt Receiver side:");
21+
printf("\nEnter the key:");
22+
scanf("%d",&key2);
23+
printf("\nEnter the message:");
24+
s=getchar();
25+
26+
if(key1==key2)
27+
{
28+
printf("\nKeys Match..you can proceed communication");
29+
30+
}
31+
else
32+
{
33+
printf("\nKeys do not match...connection lost.....");
34+
exit(0);
35+
}
36+
switch(choice)
37+
{
38+
case 1:
39+
40+
41+
// printf("\nEncrypted text is: ");
42+
while(s!='\n')
43+
{
44+
if(s==' ')
45+
putchar(s);
46+
else
47+
{
48+
putchar(s+key1);
49+
}
50+
s=getchar();
51+
}
52+
putchar(s);
53+
break;
54+
case 2:
55+
56+
while(s!='\n')
57+
{
58+
if(s==' ')
59+
putchar(s);
60+
else{
61+
putchar(s-key2);
62+
}
63+
s=getchar();
64+
}
65+
putchar(s);
66+
break;
67+
default:
68+
exit(0);
69+
}
70+
printf("\nDo you want to continue communnication:?(y or Y)");
71+
scanf("%c",&wish);
72+
} while(wish=='y'||wish=='Y');
73+
return 0;
74+
}

0 commit comments

Comments
 (0)