-
Notifications
You must be signed in to change notification settings - Fork 123
Expand file tree
/
Copy pathEncrypt and Decrypt Strings.cpp
More file actions
45 lines (39 loc) · 945 Bytes
/
Copy pathEncrypt and Decrypt Strings.cpp
File metadata and controls
45 lines (39 loc) · 945 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
class Encrypter {
public:
unordered_set<string> dict;
unordered_map<char,string> en;
unordered_map<string,vector<char>> dy;
Encrypter(vector<char>& keys, vector<string>& values, vector<string>& dictionary) {
for(auto& t:dictionary)
{ dict.insert(t);}
for(int i=0;i<keys.size();i++)
{
char c=keys[i];
string s=values[i];
en[c]=s;
dy[s].push_back(c);
}
}
string encrypt(string word1) {
string ans="";
for(char c:word1)
{
ans+=en[c];
}
return ans;
}
int decrypt(string word2) {
int cnt=0;
for(auto t:dict)
{
string ans="";
for(int i=0;i<t.size();i++)
{
ans+=en[t[i]];
}
if(ans==word2)
cnt++;
}
return cnt;
}
};