Skip to content
Snippets Groups Projects
Commit b72ebb50 authored by Marcela Ribeiro de Oliveira's avatar Marcela Ribeiro de Oliveira
Browse files

implementado filtro 2 e corrigindo filtro 2 e 3

parent 740ca981
No related branches found
No related tags found
No related merge requests found
...@@ -8,3 +8,4 @@ void parser(std::string &text); ...@@ -8,3 +8,4 @@ void parser(std::string &text);
int filter1(std::string text); int filter1(std::string text);
int filter2(std::string text); int filter2(std::string text);
int filter3(std::string text); int filter3(std::string text);
int filter4(std::string text);
casa cas
...@@ -26,6 +26,7 @@ int main(int argc, char *argv[]){ ...@@ -26,6 +26,7 @@ int main(int argc, char *argv[]){
crip = text.str(); crip = text.str();
parser(crip); parser(crip);
std::cout << crip << std::endl;
dict.open(dictName, std::ifstream::in); dict.open(dictName, std::ifstream::in);
if(!dict.good()){ if(!dict.good()){
...@@ -36,9 +37,9 @@ int main(int argc, char *argv[]){ ...@@ -36,9 +37,9 @@ int main(int argc, char *argv[]){
while(std::getline(dict, aux)){ while(std::getline(dict, aux)){
keys << aux; keys << aux;
key = keys.str(); key = keys.str();
crip = playfair(crip, key, DECRYPT); std::string cypher = playfair(crip, key, DECRYPT);
if(filter(crip)==ACCEPTED){ if(filter(cypher)==ACCEPTED){
std::cout << key << ": " << crip << std::endl; std::cout << key << ": " << cypher << std::endl;
} }
keys.str(""); keys.str("");
keys.clear(); keys.clear();
...@@ -63,7 +64,14 @@ int filter(std::string text){ ...@@ -63,7 +64,14 @@ int filter(std::string text){
// //
// ) // )
// { elimina texto: muda pra proxima chave} // { elimina texto: muda pra proxima chave}
return (filter1(text) && filter2(text) && filter3(text)); if(filter1(text) == REJECTED)
return REJECTED;
else if(filter2(text) == REJECTED)
return REJECTED;
else if(filter3(text) == REJECTED)
return REJECTED;
else
return filter4(text);
} }
int isVowel(char c){ int isVowel(char c){
...@@ -75,8 +83,7 @@ int isVowel(char c){ ...@@ -75,8 +83,7 @@ int isVowel(char c){
int filter1(std::string text){ int filter1(std::string text){
int rej = REJECTED; int rej = REJECTED;
for(int i=0; i<4; ++i){ for(int i=0; i<4; ++i){
if(text[i] == 'a' || text[i] == 'e' || text[i] == 'i' || text[i] == 'o' || if(isVowel(text[i])){
text[i] == 'u'){
rej = ACCEPTED; rej = ACCEPTED;
break; break;
} }
...@@ -90,7 +97,7 @@ int filter2(std::string text){ ...@@ -90,7 +97,7 @@ int filter2(std::string text){
for(i=0; i<text.size()-3; ++i){ for(i=0; i<text.size()-3; ++i){
char l = text[i]; char l = text[i];
int lim=3, cont=0; int lim=3, cont=0;
if ( l=='o') if (( l=='o') || (l=='e'))
continue; continue;
for(j=i+1; j<i+lim; ++j){ for(j=i+1; j<i+lim; ++j){
if(text[j]=='x'){ if(text[j]=='x'){
...@@ -130,7 +137,32 @@ int filter3(std::string text){ ...@@ -130,7 +137,32 @@ int filter3(std::string text){
break; break;
} }
} }
if(cont==5){ if(cont==4){
rej = REJECTED;
break;
}
}
return rej;
}
int filter4(std::string text){
size_t i, j;
int rej = ACCEPTED;
for(i=0; i<text.size()-7; ++i){
int lim = 7, cont = 0;
char l = text[i];
if(isVowel(l))
++cont;
for(j=i+1; j<i+lim; ++j){
if(text[j]=='x'){
++lim;
}else if(isVowel(text[j])){
++cont;
}else if(!isVowel(text[j])){
break;
}
}
if(cont==7){
rej = REJECTED; rej = REJECTED;
break; break;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment