-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyless Cipher.cpp
More file actions
48 lines (38 loc) · 767 Bytes
/
Copy pathKeyless Cipher.cpp
File metadata and controls
48 lines (38 loc) · 767 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
//Keyless Cipher
#include<iostream>
using namespace std;
int main(){
string str;
int i=0,len=0;int k=0;
cout << "Enter Plaintext: " ;
getline(cin,str);
len = str.length();
char Cipher[len];
for(i=0;i<len;i++){
if(i%2 == 0){
Cipher[k] = str[i];
k++;
}
}
for(i=0;i<len;i++){
if(i%2 != 0){
Cipher[k] = str[i];
k++;
}
}
cout <<"\nThe Encrypted Text of the given plain text is: " << Cipher<<"\n";
char Plain[len];
if(len%2!=0){
k=0;
for(i=0;i<=len/2;i++){
Plain[k] = Cipher[i]; k++;
Plain[k] = Cipher[i+int(len/2)+1];k++;
}}
else if(len%2==0){
k=0;
for(i=0;i<len/2;i++){
Plain[k] = Cipher[i]; k++;
Plain[k] = Cipher[i+int(len/2)]; k++;
}}
cout <<"The Decrypted Text of the given cipher text is: "<< Plain;
}