Guest User

Untitled

a guest
Apr 1st, 2020
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. string Zaszyfrowanie(string);
  5. string Odszyfrowanie(string);
  6. const int ile = 3;
  7.  
  8. int main()
  9. {
  10. string slowo;
  11. cout << "podaj slowo do zaszyfrowania: ";
  12. cin >> slowo;
  13. cin.ignore();
  14. cout << "zaszyfrowane dane: " << Zaszyfrowanie(slowo) << "\n";
  15. cout << "A odszyfrowane to: " << Odszyfrowanie(Zaszyfrowanie(slowo))
  16. return 0;
  17. }
  18.  
  19. string Zaszyfrowanie(string slowo)
  20. {
  21. int t;
  22. for(int i = 0; i < slowo.length(); i++)
  23. {
  24. t = slowo[i] + ile;
  25.  
  26. if(t <65)
  27. slowo[i] +=(26 +ile);
  28. else if (t > 90)
  29. slowo[i] -=(26-ile);
  30. else
  31. slowo[i] +=ile;
  32. }
  33. return slowo;
  34. }
  35. string Odszyfrowanie(string slowo)
  36. {
  37. int t;
  38.  
  39. for(int i = 0; i < slowo.length(); i++)
  40. {
  41. t = slowo[i]- ile;
  42.  
  43. if(t <65)
  44. slowo[i]+=(26 -ile);
  45. else if (t > 90)
  46. slowo[i] -=(26+ile);
  47. else
  48. slowo[i] +=ile;
  49. }
  50. return slowo;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment