Necto

шифр вижинера

Jul 26th, 2023
972
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cmath>
  4. #include <thread>
  5. #include <vector>
  6.  
  7. std::string alp = "abcdefghijklmnopqrstuvwxyz";
  8. std::string message = "koh rhkbv woe tzp efscw soqzld yt jmub sigsdsyae";
  9.  
  10. void decipher(const std::string& key, int num) {
  11.     std::string result = message;
  12.     for (int i = 0, j = 0; i < message.length(); ++i, j %= key.length()) {
  13.         if (result[i] == ' ')
  14.             continue;
  15.         result[i] = alp[(message[i] + (alp.length() - key[j++])) % alp.length()];
  16.     }
  17.     if (result.find(" you ") != std::string::npos)
  18.         std::cout << key << " " << result << " " << num << '\n';
  19. }
  20.  
  21. void func(int num) {
  22.     for (int i = (num - 1) * std::pow(26, 5) / 12; i < num * std::pow(26, 5) / 12; ++i) {
  23.         std::string key = "";
  24.         for (int j = 0; j < 5; ++j)
  25.             key += alp[i / static_cast<int>(std::pow(26, 5 - j - 1)) % 26];
  26.         decipher(key, num);
  27.     }
  28. }
  29.  
  30. int main(int argc, char* argv[]) {
  31.     std::vector<std::thread> ths;
  32.  
  33.     for (int i = 1; i <= 12; ++i)
  34.         ths.push_back(std::thread(func, i));
  35.  
  36.     for (int i = 0; i < 12; ++i)
  37.         ths[i].join();
  38.  
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment