Advertisement
avr39ripe

cppVizhinerCipher

Mar 3rd, 2021
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. char* vizhiner(char* str, const char* key, bool mode = true, int alphaLength = 26)
  4. {
  5.     char* origStr{ str };
  6.     size_t keyLength{ strlen(key) };
  7.     int keyPos{ 0 };
  8.     while (*str)
  9.     {
  10.         //if (mode)
  11.         //{
  12.         //    *str++ = ('A' + (*str + *(key + keyPos)) % alphaLength);
  13.         //}
  14.         //else
  15.         //{
  16.         //    *str++ = ('A' + (*str + alphaLength - *(key + keyPos)) % alphaLength);
  17.         //}
  18.         *str++ = ('A' + (*str + (mode ? *(key + keyPos++) : alphaLength - *(key + keyPos++))) % alphaLength);
  19.         //++keyPos;
  20.         keyPos %= keyLength;
  21.     }
  22.     return origStr;
  23. }
  24.  
  25.  
  26. int main()
  27. {
  28.  
  29.     //std::cout << char('A' + (('T' + 'E') % 26)) << '\n';
  30.     //std::cout << char('A' + ('X' + 26 - 'E') % 26) << '\n';
  31.     /*const int alphaLength{ 10 };
  32.  
  33.     for (int y{ 0 }; y < alphaLength; ++y)
  34.     {
  35.         for (int x{ 0 }; x < alphaLength; ++x)
  36.         {
  37.             std::cout << char('A' + ((y + x) % alphaLength)) << ' ';
  38.         }
  39.         std::cout << '\n';
  40.     }*/
  41.     char str[]{ "ATTACKATDAWN" };
  42.     char key[]{ "LEMON" };
  43.     std::cout << vizhiner(str, key) << '\n';
  44.     std::cout << vizhiner(str, key, false) << '\n';
  45.  
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement