-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaesercipher.cpp
More file actions
49 lines (37 loc) · 865 Bytes
/
caesercipher.cpp
File metadata and controls
49 lines (37 loc) · 865 Bytes
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
#include<iostream>
using namespace std;
string encrypt(string s1,int key)
{
int newkey=key%26,codevalue;
int len=s1.length();
char ar[len],data;
for(int i=0;i<len;i++)
{
codevalue=int(s1[i]);
codevalue=codevalue+key;
if(codevalue>122)
{
int newcodevalue;
newcodevalue = (codevalue%122);
data =char(newcodevalue);
ar[i]=data;
}
data =char(codevalue);
ar[i]=data;
}
cout<<"\n--Decrypted key is";
for(int j=0;j<=len;j++)
{
cout<<ar[j];
}
}
int main(){
string s1;
int key;
cout<<"\nEnter the string to encypt----";
cin>>s1;
cout<<"\nEnter the encrytion key";
cin>>key;
encrypt(s1,key);
return 0;
}