You are viewing a single comment's thread. Return to all comments →
int CalcXOR(int &x, char &ch){ int y=int(ch); return (x | y) & (~x | ~y); } bool Check(int x){ if(isalnum(x)||(strchr(" (;:,.'?-!)",x)!=NULL)) return true; else return false; } int main(){ int n; cin>>n; int *enc_ascii=new int[n]; for(int i=0;i<n;i++){ cin>>enc_ascii[i]; } char ch1='a',ch2='a',ch3='a'; for(bool br_co=false;ch1<='z';ch1++){ for(int i=0;i<n;i+=3){ if(!Check(CalcXOR(enc_ascii[i],ch1))){ br_co=false; break; } else{ br_co=true; } } if(br_co){ break; } } for(bool br_co=false;ch2<='z';ch2++){ for(int i=1;i<n;i+=3){ if(!Check(CalcXOR(enc_ascii[i],ch2))){ br_co=false; break; } else{ br_co=true; } } if(br_co){ break; } } for(bool br_co=false;ch3<='z';ch3++){ for(int i=2;i<n;i+=3){ if(!Check(CalcXOR(enc_ascii[i],ch3))){ br_co=false; break; } else{ br_co=true; } } if(br_co){ break; } } cout<<ch1<<ch2<<ch3; return 0; }
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #59: XOR decryption
You are viewing a single comment's thread. Return to all comments →
C++ Solution