-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathceasor.cpp
111 lines (111 loc) · 2.29 KB
/
ceasor.cpp
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
while(1)
{
char capital[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char small[27]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
string c;
int i,j,shift,x,choice,test;
f:
cout<<"Enter ur choice:->"<<endl;
cout<<"1. Encrypt"<<endl;
cout<<"2. Dcrypt"<<endl;
cout<<"3. exit"<<endl;
cin>>choice;
while (!cin)
{
cout<<"ERROR!! Enter a number"<<endl;
cout<<"Opening Options--"<<endl;
cout<<"Enter ur choice:->"<<endl;
cout<<"1. Encrypt"<<endl;
cout<<"2. Dcrypt"<<endl;
cout<<"3. exit"<<endl;
cin.clear();
cin.ignore(10000,'\n');
cout<<endl;
cin>>choice;
}
if(choice>=4||choice==0)
{
cout<<"ERROR!! Input from above sequence of digits only:"<<endl;
goto f;
}
switch(choice)
{
case 1:
cin.ignore(10000,'\n');
cout<<"Enter your plaintext:->";
getline(cin,c);
cout<<endl;
cout<<"Enter shift also:->";
cin>>shift;
cout<<endl;
cin.ignore(1000,'\n');
cout<<"Encrypted text is:->";
for(i=0;c[i]!='\0';i++)
{
for(j=0;j<26;j++)
{
if(c[i]==small[j])
{
x=(j+shift)%26;
cout<<small[x];
}
else if(c[i]==capital[j])
{
x=(j+shift)%26;
cout<<small[x];
}
}
}
cout<<endl;
break;
case 2:
cin.ignore(10000,'\n');
cout<<"Enter your ciphertext to get plaintext:->";
getline(cin,c);
cout<<endl;
cout<<"Enter shift also:->";
cin>>shift;
cout<<endl;
cin.ignore(1000,'\n');
cout<<endl<<"Decrypted text is:->";
for(i=0;c[i]!='\0';i++)
{
for(j=0;j<26;j++)
{
if(c[i]==small[j])
{
test=(j-shift);
if(test<0)
{
test=-test;
}
x=test%26;
cout<<small[x];
}
else if(c[i]==capital[j])
{
test=(j-shift);
if(test<0)
{
test=-test;
}
x=test%26;
cout<<small[x];
}
}
}
cout<<endl;
break;
case 3:
{
goto end;
}
}
}end:
return 0;
}