ErolDude

Untitled

Jan 20th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using std::cout;
  4. using std::cin;
  5. using std::string;
  6. string encryptcharacter {"~"};
  7.  
  8. string encrypt(string buffer)
  9. {
  10.  
  11. for(int i=0; i<(int)buffer.size(); i++) {
  12. if (i%2==0) {
  13. buffer[i]+=3;
  14. }
  15. if (i%3==0) {
  16. buffer[i]+=2;
  17. } else {
  18. buffer[i]+=1;
  19. }
  20.  
  21. }
  22.  
  23.  
  24. buffer.insert(0,encryptcharacter);
  25. return buffer;
  26. }
  27.  
  28. string decrypt(string buffer)
  29. {
  30.  
  31. buffer.erase(buffer.begin());
  32.  
  33. for(int i=0; i<(int)buffer.size(); i++) {
  34.  
  35. if (i%2==0) {
  36. buffer[i]-=3;
  37. }
  38. if (i%3==0) {
  39. buffer[i]-=2;
  40. } else {
  41. buffer[i]-=1;
  42. }
  43. }
  44.  
  45. return buffer;
  46. }
  47.  
  48. int main()
  49. {
  50.  
  51. string buffer;
  52. cout<<"Encrypter/Decrypter V1.5 by Baho and biNS. ETF 2016"<<std::endl;
  53.  
  54. while(true) {
  55.  
  56.  
  57.  
  58. getline(cin,buffer);
  59.  
  60. if(buffer[0]==encryptcharacter[0]) {
  61. //decrypt(buffer);
  62. buffer=decrypt(buffer);
  63. cout<<buffer<<std::endl;
  64. } else if(buffer.size()!=0) {
  65. //encrypt(buffer);
  66. buffer=encrypt(buffer);
  67. cout<<buffer<<std::endl;
  68. } else {
  69. cout<<"Greska, prazan string"<<std::endl;
  70. }
  71.  
  72. }
  73.  
  74.  
  75.  
  76. return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment