Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- std::string XorCypherBreaker(const std::vector<char> &cryptogram, int key_length, const std::vector<std::string> &dictionary){
- int count = 0;
- std::string to_decrypt;
- std::vector<std::string> results;
- int tab[dictionary.size()];
- for(int i = 0; i < dictionary.size(); i++) tab[i] = 0;
- for(int i = 0; i < key_length; i++) to_decrypt += 'a';
- for(int i = 1; i < 2; i++){
- for(auto n : cryptogram){
- to_decrypt[count] = char(i)^n;
- tolower(to_decrypt[count]);
- count++;
- if(count == key_length){
- count = 0;
- for(int j = 0; j < dictionary.size(); j++)if(dictionary[i] == to_decrypt) tab[i]++;
- }
- }
- }
- int max=0, max_index=0;
- for(int i = 0; i < dictionary.size(); i++){
- if(max > tab[i]) {
- max = tab[i];
- max_index = i;
- }
- }
- return dictionary[max_index];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement