Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <stdlib.h>
  4. #include <windows.h>
  5. #include <map>
  6. #include <cmath>
  7. #include <string>
  8. #include <conio.h>
  9. #include <sstream>
  10.  
  11. using namespace std;
  12. string text = "u fat lol";
  13. string encryptedText;
  14. string text2;
  15. int spaces = 0;
  16. int offset;
  17. int multipliers = 2;
  18.  
  19. char getOption()
  20. {
  21. system("cls");
  22. char option;
  23. cout << "Enter 'e' to encrypt text..." << setw(42) << "Enter 'd' to decrypt text..." << setw(35) << "Enter 'x' to exit..." << endl;
  24. cin >> option;
  25.  
  26. return option;
  27. }
  28.  
  29. string encrypt(string &text, int offset)
  30. {
  31. NewOrSetLine:char NewOrSet;
  32. cout << "\n\nDo you want to use new text or text set in code?\nn : New text";
  33. if (text.length() != 0){
  34. cout << "\nc : Text in code (text: '"<<text<<"')\n";}else{
  35. cout << "\n - There is no text set in code." << endl;}
  36. cin >> NewOrSet;
  37. if (NewOrSet == 'n' || NewOrSet == 'N') {
  38. cout << "\nEnter text to encrypt without spaces: " << endl; cin >> text; }
  39. else if (NewOrSet == 'c' || NewOrSet == 'C'){
  40. text = text;}else{goto NewOrSetLine;}
  41.  
  42. if (offset == 0){
  43. cout << "\nEnter offset number(int)( some offsets might not work! ): " << endl; cin >> offset;
  44. }
  45.  
  46. string result = "";
  47.  
  48. for (int i = 0; i<text.length(); i++)
  49. {
  50. if (isupper(text[i])){
  51. for (int j = 0; j<2; j++){
  52. result += char(int(text[i] + offset + j));
  53. result += char(int(text[i] = 72));
  54. result += char(int(text[i] + (offset + j) + multipliers));
  55. result += char(int(text[i] = 81));
  56. }
  57. }
  58.  
  59. else if (int(text[i] == 32)){
  60. result += char(int(51));
  61. spaces++;
  62. }
  63.  
  64. else {
  65. for (int k = 0; k<2; k++){
  66. result += char(int(text[i] + offset + k));
  67. result += char(int(text[i] = 88));
  68. result += char(int(text[i] + (offset + k) + multipliers));
  69. result += char(int(text[i] = 34));
  70. }
  71. }
  72. }
  73. cout << endl;
  74. cout << "Number of spaces in text: " << spaces << endl;
  75. text2 = text;
  76. return result;
  77. }
  78.  
  79. string decrypt(string encryptedText, int offset)
  80. {
  81. string result = "";
  82. cout << "Enter Encrypted Text: ";
  83. cin >> encryptedText;
  84. cout << endl;
  85. cout << "Enter offset: ";
  86. cin >> offset;
  87. int n = 0;
  88. cout << endl;
  89. cout << "encry text: " << encryptedText << endl;
  90.  
  91. for (int i=0; i<50000; i++){
  92. if (encryptedText.length() > n+1) {
  93. if (int(encryptedText[0 + n] == 51)){
  94. result += char(int(32));
  95. n += 1; }
  96. if (encryptedText.length() > n+1) {
  97. result += char(int(encryptedText[0 + n] - offset));
  98. n += 8; }
  99.  
  100. }else{
  101. break;
  102. }
  103. }
  104. return result;
  105. }
  106.  
  107. int main()
  108. {
  109.  
  110. getoptions:
  111. char TheOption = getOption();
  112.  
  113. if (TheOption == 'e' || TheOption == 'E'){
  114. cout << "Encrypted Text: " << encrypt(text, offset);
  115. cout << endl;
  116. cout << "Press any key to continue..." << endl;
  117. getch();
  118. goto getoptions;
  119. }
  120. else if (TheOption == 'd' || TheOption == 'D'){
  121. cout << "Decrypted Text: " << decrypt(encryptedText, offset);
  122. cout << endl;
  123. cout << "Press any key to continue..." << endl;
  124. getch();
  125. goto getoptions;
  126. }
  127. else if (TheOption == 'x' || TheOption == 'X'){
  128. return 0;
  129. }
  130. else {
  131. goto getoptions;
  132. }
  133. return 0;
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement