-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdecifradorsubs.cpp
More file actions
103 lines (91 loc) · 3.16 KB
/
Copy pathdecifradorsubs.cpp
File metadata and controls
103 lines (91 loc) · 3.16 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
#include <iostream>
#include <string>
#include <vector>
using namespace std;
string decifrarComUnder(string cifrado, string chave){
string alfabeto = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
int pos;
for(unsigned int i = 0; i < cifrado.length(); i++){
pos = chave.find(cifrado[i]);
if(pos != string::npos){
cifrado[i] = alfabeto[pos];
}else
if(cifrado[i]!=' '){
cifrado[i] = '_';
}
}
return cifrado;
}
string decifrar(string cifrado, string chave){
string alfabeto = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
int pos;
for(unsigned int i = 0; i < cifrado.length(); i++){
pos = chave.find(cifrado[i]);
if(pos != string::npos){
cifrado[i] = alfabeto[pos];
}
}
return cifrado;
}
void percorrer(string cifrado){
vector<string> possiveisComputador;
vector<string> possiveisSeguranca;
vector<string> possiveisAlfabetos;
string substring;
string alfabeto = "______________________________________________________________";
string normal = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
if(cifrado.size()>=10){
for(unsigned int i = 0; i < cifrado.length()-9; i++){
substring = cifrado.substr(i, 10);
//checa se a substring pode ser "computador"
if(substring[1] == substring[8]){
possiveisComputador.push_back(substring);
}
}
}
if(cifrado.size()>=9){
for(unsigned int i = 0; i < cifrado.length()-8; i++){
substring = cifrado.substr(i, 9);
//checa se a substring pode ser "seguranca"
if(substring[5] == substring[8]){
possiveisSeguranca.push_back(substring);
}
}
}
string plainText;
for(unsigned int i = 0; i < possiveisSeguranca.size() ;i++){
for(unsigned int j = 0; j < possiveisComputador.size() ;j++){
if(possiveisComputador[j][4]==possiveisSeguranca[i][3]
&&possiveisComputador[j][9]==possiveisSeguranca[i][4]
&&possiveisComputador[j][0]==possiveisSeguranca[i][7]){
alfabeto[0] = possiveisSeguranca[i][5];
alfabeto[2] = possiveisSeguranca[i][7];
alfabeto[3] = possiveisComputador[j][7];
alfabeto[4] = possiveisSeguranca[i][1];
alfabeto[6] = possiveisSeguranca[i][2];
alfabeto[12] = possiveisComputador[j][2];
alfabeto[13] = possiveisSeguranca[i][6];
alfabeto[14] = possiveisComputador[j][1];
alfabeto[15] = possiveisComputador[j][3];
alfabeto[17] = possiveisComputador[j][9];
alfabeto[18] = possiveisSeguranca[i][0];
alfabeto[19] = possiveisComputador[j][5];
alfabeto[20] = possiveisComputador[j][4];
plainText = decifrar(cifrado, alfabeto);
cout<<"possivel alfabeto"<<endl;
cout<<normal<<endl;
cout<<alfabeto<<endl;
cout << "Texto semi-decifrado: \n" << plainText << endl;
plainText = decifrarComUnder(cifrado, alfabeto);
cout << plainText << endl;
}
alfabeto = "______________________________________________________________";
}
}
}
int main(){
string textoCifrado;
getline(cin, textoCifrado);
percorrer(textoCifrado);
return 0;
}