-
Notifications
You must be signed in to change notification settings - Fork 0
/
ceiser cipher.txt
45 lines (43 loc) · 1.02 KB
/
ceiser cipher.txt
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<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ll a,b,c,x,y,z,n;
string s,s1,s2;
cout<<"message : ";
while(cin>>s)
{
cout<<" number of keys :";
cin>>n;
vector<ll>v;
for(int i=0; i<n; i++)
cin>>x,v.push_back(x);
s1="";
for(int i=0; i<s.size(); i++)
{
if(isupper(s[i]))
s1+=char(((s[i]-'A'+v[i%n])%26)+'A');
else s1+=char(((s[i]-'a'+v[i%n])%26)+'a');
}
cout<<"encrypted message :"<<s1<<endl;
s2="";
for(int i=0; i<s1.size(); i++)
{
if(isupper(s1[i]))
{
x=(s1[i]-'A'-v[i%n]);
if(x<0) x+=26;
s2+=char(x+'A');
}
else
{
x=(s1[i]-'a'-v[i%n]);
if(x<0) x+=26;
s2+=char(x+'a');
}
}
cout<<"decrypted message :"<<s2<<endl;
}
return 0;
}