Advertisement
Krefeld187

Untitled

Jan 17th, 2021
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.24 KB | None | 0 0
  1. /*********
  2. -*- Made by VoxelPixel
  3. -*- For YouTube Tutorial
  4. -*- https://github.com/VoxelPixel
  5. -*- Support me on Patreon: https://www.patreon.com/voxelpixel
  6. *********/
  7.  
  8. #include <iostream>
  9. #include <string>
  10.  
  11. using namespace std;
  12.  
  13. //we'll be using ASCII in this
  14.  
  15. string schlüssel(int wahl, string dat, int schlüssel)
  16. {
  17. int choice;
  18. /*
  19. cout << "1. Encryption" << endl << "2. Decryption" << endl << "Enter choice(1,2): ";
  20. cin >> choice;
  21. cin.ignore();
  22. */
  23. choice = wahl;
  24. if (choice == 1) {
  25. // encryption
  26. string msg;
  27. /*cout << "Message can only be alphabetic" << endl;
  28. cout << "Enter message: ";
  29. getline(cin, msg);
  30.  
  31. msg = dat;
  32. */
  33. int key;
  34. /*
  35. cout << "Enter key (0-25): ";
  36. cin >> key;
  37. cin.ignore();
  38. */
  39. key = schlüssel;
  40. string encryptedText = msg;
  41.  
  42. for (int i = 0; i < msg.size(); i++) {
  43.  
  44. if (msg[i] == 32) {
  45. continue; //32 is ASCII of space character, we will ignore it
  46. }
  47. else {
  48.  
  49. if ((msg[i] + key) > 122) {
  50. //after lowercase z move back to a, z's ASCII is 122
  51. int temp = (msg[i] + key) - 122;
  52. encryptedText[i] = 96 + temp;
  53. }
  54. else if (msg[i] + key > 90 && msg[i] <= 96) {
  55. //after uppercase Z move back to A, 90 is Z's ASCII
  56. int temp = (msg[i] + key) - 90;
  57. encryptedText[i] = 64 + temp;
  58. }
  59. else {
  60. //in case of characters being in between A-Z & a-z
  61. encryptedText[i] += key;
  62. }
  63.  
  64. } //if
  65. } // for
  66.  
  67. //cout << "Encrypted Message: " << encryptedText;
  68. return encryptedText;
  69.  
  70. }
  71. else if (choice == 2) {
  72. //decryption
  73.  
  74. string encpMsg;
  75. /*cout << "Message can only be alphabetic" << endl;
  76. cout << "Enter encrypted text: ";
  77. getline(cin, encpMsg);
  78. */
  79. encpMsg = dat;
  80. int dcyptKey;
  81. /*cout << "Enter key (0-25): ";
  82. cin >> dcyptKey;
  83. cin.ignore();
  84. */
  85. dcyptKey = schlüssel;
  86. string decryptedText = encpMsg;
  87.  
  88. for (int i = 0; i < encpMsg.size(); i++) {
  89. if (encpMsg[i] == 32) {
  90. continue; //ignoring space
  91. }
  92. else {
  93. if ((encpMsg[i] - dcyptKey) < 97 && (encpMsg[i] - dcyptKey) > 90) {
  94. int temp = (encpMsg[i] - dcyptKey) + 26;
  95. decryptedText[i] = temp;
  96. }
  97. else if ((encpMsg[i] - dcyptKey) < 65) {
  98. int temp = (encpMsg[i] - dcyptKey) + 26;
  99. decryptedText[i] = temp;
  100. }
  101. else {
  102. decryptedText[i] = encpMsg[i] - dcyptKey;
  103. }
  104. }
  105. }
  106.  
  107. // cout << "Decrypted Message: " << decryptedText << endl;
  108. return decryptedText;
  109. }
  110. else {
  111. cout << "Invalid choice";
  112. }
  113.  
  114. }
  115.  
  116. int arr[26];
  117.  
  118. void buchzähler(string dat, int max)
  119. {
  120. string alp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  121. //int lanalp = sizeof(alp) / sizeof(string);
  122. //int laenge = sizeof(dat) / sizeof(string);
  123. //cout << lanalp << " " <<laenge << endl;
  124. for (int i = 0; i < max; ++i)
  125. {
  126. for (int z = 0; z < 26; ++z)
  127. {
  128. if (dat[i] == alp[z])
  129. arr[z] += 1;
  130. }
  131.  
  132. }
  133. }
  134.  
  135.  
  136. int main()
  137. {
  138. /* for (int i = 1; i <= 23; ++i)
  139. {
  140. string temp = schlüssel(2, "QNFRVAMVTRVAFPUEVSGYVPUTRFVPUREGRCBEGENRGPNRFNEFQNFMHYROMRV", i);
  141. cout << i << " : " << temp << endl;
  142. }
  143. */
  144. buchzähler("QNFRVAMVTRVAFPUEVSGYVPUTRFVPUREGRCBEGENRGPNRFNEFQNFMHYROMRV", 59);
  145. buchzähler("GRARAGFGNAQVFGNHSZHRAMRAHROREYVRSREGQVRVAFRVARZYRGMGRAYRORA", 59);
  146. buchzähler("FWNUETRCENRTGJHEQRAFVRMRVTRARVARUNTRERCREFBAZVGUBUREFGVEAHA", 59);
  147. buchzähler("QYNATRZSNYGVTRZUNYFNHSQRETEHAQYNTRQREZHRAMNOOVYQHATRAJHEQRR", 59);
  148. buchzähler("VAVAGHFPHYHZTRSHAQRAREWRGMGVAGHEVAORSVAQYVPUREXBCSNHFXNYXFG", 59);
  149. buchzähler("RVANYFMRVGTRABRFFVFPURFCBEGENRGPNRFNEFVQRAGVSVMVREGCBFGHZRQ", 59);
  150. buchzähler("NEFGRYYHATRASVAQRAFVPUJVRQREHZNHSZHRAMRAQRARARVAXBCSVZINGVX", 59);
  151. buchzähler("NARAGFCEVPUGQNFCBEGENRGVFGQRHGYVPUVQRNYVFVREGRENYFQVRMHYROM", 59);
  152. buchzähler("RVGRARAGFGNAQRARAQVRVQRNYVFVREHATQREQNEFGRYYHATQRFQVIHFVHYV", 59);
  153. buchzähler("HFFRGMGRFVPUVANHTHFGRVFPUREMRVGSBEGRVTRAFGNRAQVTVFGRVAJBUYV", 59);
  154. buchzähler("ANRTLCGRARAGFGNAQRARECBEGENRGXBCSNHFTEHRAFPUVRSREVAQRENAGVX", 59);
  155. buchzähler("RAFNZZYHATOREYVA", 16);
  156.  
  157. string alp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  158. int stan[26] = {6,2,2,5,17,2,3,5,8,1,1,3,2,10,2,1,1,7,7,6,4,1,1,1,1,1};
  159. //int temp = 0;
  160. double res = 0.0;
  161. for (int i = 0; i < 26; ++i)
  162. {
  163. double temp = (double)arr[i] / 6.65;
  164. //temp += arr[i];
  165. res += temp;
  166. cout << alp[i] << ": " << temp << "%" <<" Durchschnitt Standard : " << stan[i] <<"%"<< endl;
  167. }
  168. cout << res << endl;
  169. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement