MSzopa

Szyfry

Apr 17th, 2020
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.54 KB | None | 0 0
  1. string SzyfrJ(int a, string text) {
  2.     string ret = "";
  3.     for (int i = 0; i < text.length(); i++) {
  4.         char b = tolower(text[i]);
  5.         if (b != 32) {
  6.             if (b + a > 122) {
  7.                 ret += 97 - (122 - (b + a));
  8.             }
  9.             else {
  10.                 ret += (b + a);
  11.             }
  12.         }
  13.         else {
  14.             ret += ' ';
  15.         }
  16.     }
  17.     return ret;
  18. }
  19. string Szyfr357(string text) {
  20.     int szyfr = 0;
  21.     int liczby[] = { 3,5,7 };
  22.     for (int i = 0; i < text.length(); i++) {
  23.         text[i] += liczby[szyfr];
  24.         szyfr++;
  25.         if (szyfr > 2)
  26.             szyfr = 0;
  27.     }
  28.     return text;
  29. }
  30. string DeSzyfr357(string text) {
  31.     int szyfr = 0;
  32.     int liczby[] = { 3,5,7 };
  33.     for (int i = 0; i < text.length(); i++) {
  34.         text[i] -= liczby[szyfr];
  35.         szyfr++;
  36.         if (szyfr > 2)
  37.             szyfr = 0;
  38.     }
  39.     return text;
  40. }
  41. string SzyfrKlucz(string szyfr, string text) {
  42.     int a = 0;
  43.     for (int i = 0; i < text.length(); i++) {
  44.         int d = 0;
  45.         stringstream ss;
  46.         ss << szyfr[a];
  47.         ss >> d;
  48.         text[i] += d;
  49.         a++;
  50.         if (a > szyfr.length()-1)
  51.             a = 0;
  52.     }
  53.     return text;
  54. }
  55. string DeSzyfrKlucz(string szyfr, string text) {
  56.     int a = 0;
  57.     for (int i = 0; i < text.length(); i++) {
  58.         int d = 0;
  59.         stringstream ss;
  60.         ss << szyfr[a];
  61.         ss >> d;
  62.         text[i] -= d;
  63.         a++;
  64.         if (a > szyfr.length() - 1)
  65.             a = 0;
  66.     }
  67.     return text;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment