Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. class Vig {
  5. public:
  6. string k;
  7. Vig(string k) {
  8. for (int i = 0; i < k.size(); ++i) {
  9. if (k[i] >= 'A' && k[i] <= 'Z')
  10. this->k += k[i];
  11. else if (k[i] >= 'a' && k[i] <= 'z')
  12. this->k += k[i] + 'A' - 'a';
  13. }
  14. }
  15. string encryption(string t) {
  16. string output;
  17. for (int i = 0, j = 0; i < t.length(); ++i) {
  18. char c = t[i];
  19. if (c >= 'a' && c <= 'z')
  20. c += 'A' - 'a';
  21. else if (c < 'A' || c > 'Z')
  22. continue;
  23. output += (c + k[j] - 2 * 'A') % 26 + 'A';
  24. j = (j + 1) % k.length();
  25. }
  26. return output;
  27. }
  28. string decryption(string t) {
  29. string output;
  30. for (int i = 0, j = 0; i < t.length(); ++i) {
  31. char c = t[i];
  32. if (c >= 'a' && c <= 'z')
  33. c += 'A' - 'a';
  34. else if (c < 'A' || c > 'Z')
  35. continue;
  36. output += (c - k[j] + 26) % 26 + 'A';
  37. j = (j + 1) % k.length();
  38. }
  39. return output;
  40. }
  41. };
  42. int main() {
  43. Vig v("WELCOME");
  44. string ori ="Laganapetica";
  45. string encrypt = v.encryption(ori);
  46. string decrypt = v.decryption(encrypt);
  47. cout << "Original Message: "<<ori<< endl;
  48. cout << "Encrypted Message: " << encrypt << endl;
  49. cout << "Decrypted Message: " << decrypt << endl;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement