forked from csfx-py/hacktober2020
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncryption.cpp
More file actions
36 lines (35 loc) · 722 Bytes
/
Encryption.cpp
File metadata and controls
36 lines (35 loc) · 722 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
#include<bits/stdc++.h>
using namespace std;
string encrypt(string s)
{
int n = s.length();
string res = "";
for(int i=0;i<n;i++)
{
int ascii = ((s[i] - 'v') + (i*i*i)%256)%256;
res += char(ascii);
}
return res;
}
string decode(string s)
{
int n = s.length();
string res = "";
for(int i=0;i<n;i++)
{
int ascii = ((s[i] - (i*i*i))%256 + 'v') % 256;
res += char(ascii);
}
return res;
}
int main()
{
string s;
cout<<"Enter plain text : ";
cin>>s;
s = encrypt(s);
cout<<"Encoded : "<<s<<endl;
cout<<"------------------------------------------------------"<<endl;
cout<<"Decoded : "<<decode(s)<<endl;
return 0;
}