OIQ

Untitled

OIQ
Oct 5th, 2021 (edited)
343
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <string>
  2. #include <iostream>
  3.  
  4. std::string rotate(const std::string &alp, std::string str, int n) {
  5.     for (int i = 0; i < str.size(); i++) {
  6.         int index = str[i] - 'A';
  7.         str[i] = alp[(index + n) % alp.size()];
  8.     }
  9.  
  10.     return str;
  11. }
  12.  
  13. int main() {
  14.     std::string alp(26, ' ');
  15.  
  16.     for (size_t i = 0; i < 26; i++) {
  17.         alp[i] = static_cast<char>('A' + i);
  18.     }
  19.  
  20.     std::string str = "NWLAHYCRXW";
  21.  
  22.     for (int i = 1; i <= 26; i++) {
  23.         std::string encode = rotate(alp, str, i);
  24.         std::cout << encode << " " << 26 - i << "\n";
  25.     }
  26. }
RAW Paste Data Copied