Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. std::string XorCypherBreaker(const std::vector<char> &cryptogram, int key_length, const std::vector<std::string> &dictionary){
  2. int count = 0;
  3. std::string to_decrypt;
  4. std::vector<std::string> results;
  5. int tab[dictionary.size()];
  6. for(int i = 0; i < dictionary.size(); i++) tab[i] = 0;
  7. for(int i = 0; i < key_length; i++) to_decrypt += 'a';
  8.  
  9. for(int i = 1; i < 2; i++){
  10. for(auto n : cryptogram){
  11. to_decrypt[count] = char(i)^n;
  12. tolower(to_decrypt[count]);
  13. count++;
  14. if(count == key_length){
  15. count = 0;
  16. for(int j = 0; j < dictionary.size(); j++)if(dictionary[i] == to_decrypt) tab[i]++;
  17. }
  18. }
  19. }
  20. int max=0, max_index=0;
  21.  
  22. for(int i = 0; i < dictionary.size(); i++){
  23. if(max > tab[i]) {
  24. max = tab[i];
  25. max_index = i;
  26. }
  27. }
  28. return dictionary[max_index];
  29.  
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement