-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencrypt.cpp
More file actions
104 lines (94 loc) · 2.17 KB
/
encrypt.cpp
File metadata and controls
104 lines (94 loc) · 2.17 KB
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
// Bintang Fadhli Muhammad
#include <iostream>
#include <string>
using namespace std;
class enkripsi{
private :
string sandi;
public :
void set(string masuk){
this->sandi=masuk;
}
string get(){
return this->sandi;
}
void kunci(int sandi){
char bantu;
for(int i=0;this->sandi[i]!='\0';++i){
bantu=this->sandi[i];
if(bantu>='a' && bantu<='z'){
bantu=bantu+sandi;
if(bantu>'z'){
bantu=bantu-'z'+'a'-1;
}
this->sandi[i]=bantu;
}
else if(bantu>= 'A' && bantu<= 'Z'){
bantu=bantu+sandi;
if(bantu>'Z'){
bantu=bantu-'Z'+'A'- 1;
}
this->sandi[i]=bantu;
}
}
}
void buka(int sandi){
char bantu;
for(int i=0;this->sandi[i]!='\0';++i){
bantu=this->sandi[i];
if(bantu>='a' && bantu<='z'){
bantu=bantu-sandi;
if(bantu<'a'){
bantu=bantu+'z'-'a'+1;
}
this->sandi[i]=bantu;
}
else if(bantu>='A' && bantu<='Z'){
bantu=bantu-sandi;
if(bantu>'a'){
bantu=bantu+'Z'-'A'+1;
}
this->sandi[i]=bantu;
}
}
}
};
int main(){
enkripsi super;
int choice, sandi;
string masuk;
system("color 3F");
cout<<"Input Your String : ";
getline(cin,masuk);
super.set(masuk);
do{
system("cls");
cout<<"Encryption Tools"<<endl;
cout<<"=========================="<<endl;
cout<<"Your string : "<<super.get()<<endl;
cout<<"=========================="<<endl;
cout<<"1. Input New String"<<endl;
cout<<"2. Encryption"<<endl;
cout<<"3. Decryption"<<endl;
cout<<"4. Exit"<<endl<<endl;
cout<<"Input your choice : ";
cin>>choice;
cout<<endl;
switch(choice){
case 1: cout<<"Input Your New String : ";
getchar();
getline(cin,masuk);
super.set(masuk);
break;
case 2: cout<<"Enter the number of Key Encryption : ";
cin>>sandi;
super.kunci(sandi);
break;
case 3: cout<<"Enter the number of Key Decryption : ";
cin>>sandi;
super.buka(sandi);
break;
}
}while(choice!=4);
return 0;
}