Zweide-Altunik

Enigma Password

Dec 2nd, 2024 (edited)
9
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.86 KB | Source Code | 0 0
  1. // I made an enigma password machine!
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. char wlr1[32] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
  5. char wlr2[32] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
  6. char wlr3[32] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
  7. char wlr4[32] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
  8. char wlr5[32] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
  9. char wlr6[32] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
  10. char rflr[32] = {'d', 'n', 'z', 'a', 'h', 'w', 'm', 'e', 'y', 'u', 'q', 's', 'g', 'b', 't', 'v', 'k', 'x', 'l', 'o', 'j', 'p', 'f', 'r', 'i', 'c'};
  11.  
  12. char wll1[32] = {'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'z', 'x', 'c', 'v', 'b', 'n', 'm'};
  13. char wll2[32] = {'m', 'n', 'b', 'v', 'c', 'x', 'z', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'p', 'o', 'i', 'u', 'y', 't', 'r', 'e', 'w', 'q'};
  14. char wll3[32] = {'q', 'e', 't', 'u', 'o', 'a', 'd', 'g', 'j', 'l', 'x', 'v', 'n', 'w', 'r', 'y', 'i', 'p', 's', 'f', 'h', 'k', 'z', 'c', 'b', 'm'};
  15. char wll4[32] = {'b', 'n', 'm', 'v', 'c', 'z', 'x', 'g', 'h', 'j', 'k', 'l', 'f', 'd', 's', 'a', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'e', 'w', 'q'};
  16. char wll5[32] = {'p', 'o', 'i', 'u', 'y', 't', 'r', 'e', 'w', 'q', 'l', 'k', 'j', 'h', 'g', 'f', 'd', 's', 'a', 'm', 'n', 'b', 'v', 'c', 'x', 'z'};
  17. char wll6[32] = {'z', 'y', 'x', 'w', 'v', 'u', 't', 's', 'r', 'q', 'p', 'o', 'n', 'm', 'l', 'k', 'j', 'i', 'h', 'g', 'f', 'e', 'd', 'c', 'b', 'a'};
  18. char rfll[32] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
  19. int startp[8] = {0, 0, 0, 0, 0};
  20.  
  21. string str;
  22. int len;
  23.  
  24. void enc10(char a)
  25. {
  26.     for (int i = 0; i < 26; i++)
  27.     {
  28.         if (wll1[(i + startp[1]) % 26] == a)
  29.         {
  30.             cout << char(wlr1[i]);
  31.             break;
  32.         }
  33.     }
  34. }
  35.  
  36. void enc9(char a)
  37. {
  38.     for (int i = 0; i < 26; i++)
  39.     {
  40.         if (wll2[(i + startp[2]) % 26] == a)
  41.         {
  42.             enc10(wlr2[i]);
  43.             break;
  44.         }
  45.     }
  46. }
  47.  
  48. void enc8(char a)
  49. {
  50.     for (int i = 0; i < 26; i++)
  51.     {
  52.         if (wll3[(i + startp[3]) % 26] == a)
  53.         {
  54.             enc9(wlr3[i]);
  55.             break;
  56.         }
  57.     }
  58. }
  59.  
  60. void enc7(char a)
  61. {
  62.     for (int i = 0; i < 26; i++)
  63.     {
  64.         if (wll4[(i + startp[4]) % 26] == a)
  65.         {
  66.             enc8(wlr4[i]);
  67.             break;
  68.         }
  69.     }
  70. }
  71.  
  72. void enc6(char a)
  73. {
  74.     for (int i = 0; i < 26; i++)
  75.     {
  76.         if (wll5[(i + startp[5]) % 26] == a)
  77.         {
  78.             enc7(wlr5[i]);
  79.             break;
  80.         }
  81.     }
  82. }
  83.  
  84. void enc11(char a)
  85. {
  86.     for (int i = 0; i < 26; i++)
  87.     {
  88.         if (wll6[(i + startp[5]) % 26] == a)
  89.         {
  90.             enc7(wlr6[i]);
  91.             break;
  92.         }
  93.     }
  94. }
  95.  
  96. void reflect(char a)
  97. {
  98.     for (int i = 0; i < 26; i++)
  99.     {
  100.         if (rflr[i] == a)
  101.         {
  102.             enc6(rfll[i]);
  103.         }
  104.     }
  105. }
  106.  
  107. void enc5(char a)
  108. {
  109.     for (int i = 0; i < 26; i++)
  110.     {
  111.         if (wlr5[(i + 26 - startp[5]) % 26] == a)
  112.         {
  113.             reflect (wll5[i]);
  114.             break;
  115.         }
  116.     }
  117. }
  118.  
  119. void enc4(char a)
  120. {
  121.     for (int i = 0; i < 26; i++)
  122.     {
  123.         if (wlr4[(i + 26 - startp[4]) % 26] == a)
  124.         {
  125.             enc5(wll4[i]);
  126.             break;
  127.         }
  128.     }
  129. }
  130.  
  131. void enc3(char a)
  132. {
  133.     for (int i = 0; i < 26; i++)
  134.     {
  135.         if (wlr3[(i + 26 - startp[3]) % 26] == a)
  136.         {
  137.             enc4(wll3[i]);
  138.             break;
  139.         }
  140.     }
  141. }
  142.  
  143. void enc2(char a)
  144. {
  145.     for (int i = 0; i < 26; i++)
  146.     {
  147.         if (wlr2[(i + 26 - startp[2]) % 26] == a)
  148.         {
  149.             enc3(wll2[i]);
  150.             break;
  151.         }
  152.     }
  153. }
  154.  
  155. void enc0(char a)
  156. {
  157.     for (int i = 0; i < 26; i++)
  158.     {
  159.         if (wlr6[(i + 26 - startp[2]) % 26] == a)
  160.         {
  161.             enc3(wll6[i]);
  162.             break;
  163.         }
  164.     }
  165. }
  166.  
  167. void enc1(char a)
  168. {
  169.     if (isupper((int)(a)))
  170.     {
  171.         a += 32;
  172.     }
  173.     if (islower((int)(a)))
  174.     {
  175.         for (int i = 0; i < 26; i++)
  176.         {
  177.             if (wlr1[(i + 26 - startp[1]) % 26] == a)
  178.             {
  179.                 enc2(wll1[i]);
  180.                 break;
  181.             }
  182.         }
  183.         startp[1] += 1;
  184.         if (startp[1] == 26)
  185.         {
  186.             startp[2] += 1;
  187.             startp[1] = 0;
  188.             if (startp[2] == 26)
  189.             {
  190.                 startp[3] += 1;
  191.                 startp[2] = 0;
  192.                 if (startp[3] == 26)
  193.                 {
  194.                     startp[4] += 1;
  195.                     startp[3] = 0;
  196.                     if (startp[4] == 26)
  197.                     {
  198.                         startp[5] += 1;
  199.                         startp[4] = 0;
  200.                         if (startp[5] == 26)
  201.                         {
  202.                             startp[5] = 0;
  203.                         }
  204.                     }
  205.                 }
  206.             }
  207.         }
  208.     }
  209.     else
  210.     {
  211.         cout << a;
  212.     }
  213. }
  214.  
  215. /*
  216.  * 所以enc11和enc0有何作用?
  217.  */
  218.  
  219. // -----------------------------------------------------------
  220.  
  221. int main()
  222. {
  223.     cout << "输入加/解密内容" << endl;
  224.     getline(cin, str);
  225.     cout << endl;
  226.     len = str.length();
  227.     for (int i = 0; i < len; i++)
  228.     {
  229.         enc1(str[i]);
  230.     }
  231.     return 0;
  232. }
Advertisement
Add Comment
Please, Sign In to add comment