Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. #include "ShiftText.h"
  2. #include "SubstitutionText.h"
  3. #include "Shift3Text.h"
  4. #include "DecryptException.h"
  5. #include <iostream>
  6.  
  7. #define SHIFTING_KEY 10
  8. #define DICTIONARY_PATH "dictionary.csv"
  9.  
  10. using namespace std;
  11.  
  12. void Alice();
  13. PlainText Bob(SubstitutionText msg);
  14. PlainText Bob(ShiftText msg);
  15. PlainText Bob(Shift3Text msg);
  16.  
  17. /*
  18. This is the main function of the program.
  19. It starts the conversation between Alice and Bob
  20. */
  21. int main()
  22. {
  23. Alice();
  24. /*
  25. ShiftText* temp = new ShiftText("hello", 3);
  26. cout << temp->getText();
  27. temp->decrypt(3);
  28. cout << temp->getText();
  29. */
  30. cout << endl;
  31. system("PAUSE");
  32. return 0;
  33. }
  34.  
  35. /*
  36. This is Alice's part in the conversation.
  37. It gets a legal string from the user ans sends it to Bob in
  38. three different kinds of encryptions.
  39. It also prints every response from Bob.
  40. */
  41. void Alice()
  42. {
  43. fstream myFile;
  44.  
  45. cout << "Alice:" << endl;
  46. cout << "Enter a message to send to Bob:" << endl;
  47. cout << "Smile bob, its a printscreen." << endl;
  48. cout << endl;
  49.  
  50. ShiftText *msg1 = new ShiftText("Smile bob, its a printscreen." ,4);
  51. Shift3Text *msg2 = new Shift3Text("Smile bob, its a printscreen.");
  52. SubstitutionText *msg3 = new SubstitutionText("Smile bob, its a printscreen.", myFile);
  53.  
  54. std::cout << "Sending in substitution mode..." << std::endl;
  55. cout << endl;
  56. cout << Bob(*msg3).getText() << endl;
  57.  
  58. std::cout << "Sending in shift mode..." << std::endl;
  59. cout << endl;
  60. std::cout << Bob(*msg1).getText() << endl;
  61.  
  62. std::cout << "Sending in shift-3 mode..." << std::endl;
  63. cout << endl;
  64. cout << Bob(*msg2).getText() << endl;
  65. }
  66.  
  67. /*
  68. This function handles Bob's part of the conversation
  69. when he receives a message encrypted in Substitution mode
  70. */
  71. PlainText Bob(SubstitutionText msg)
  72. {
  73. cout << "Bob:" << endl;
  74.  
  75. std::cout << "The received massege: ";
  76. std::cout << msg.getText() << std::endl;
  77. fstream myFile;
  78. msg.decrypt(myFile);
  79. std::cout << "The decrypted massege: ";
  80. std::cout << msg.getText() << std::endl;
  81.  
  82. return PlainText("Thank you Alice!");
  83. }
  84.  
  85. /*
  86. This function handles Bob's part of the conversation
  87. when he receives a message encrypted in Shift mode
  88. */
  89. PlainText Bob(ShiftText msg)
  90. {
  91. cout << "Bob:" << endl;
  92.  
  93. std::cout << "The received massege: ";
  94. std::cout << msg.getText() << std::endl;
  95. fstream myFile;
  96. msg.decrypt(4);
  97. std::cout << "The decrypted massege: ";
  98. std::cout << msg.getText() << std::endl;
  99. return PlainText("Thank you again Alice!");
  100. }
  101.  
  102. /*
  103. This function handles Bob's part of the conversation
  104. when he receives a message encrypted in Shift-3 mode
  105. */
  106. PlainText Bob(Shift3Text msg)
  107. {
  108. cout << "Bob:" << endl;
  109.  
  110. std::cout << "The received massege: ";
  111. std::cout << msg.getText() << std::endl;
  112. fstream myFile;
  113. msg.decrypt(3);
  114. std::cout << "The decrypted massege: ";
  115. std::cout << msg.getText() << std::endl;
  116. return PlainText("Many Thanks Alice!");
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement