Advertisement
Guest User

CEASERCODE123

a guest
Feb 21st, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. #include<iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5.  
  6. string encode_ceaser(string input, int key) {
  7. string output = "";
  8. for(int i = 0; i < input.length(); i++) {
  9. char c = (input[i]-97+key)%26;
  10. output +=c+97;
  11. }
  12. return output;
  13. }
  14.  
  15. string decode_ceaser(string input, int key) {
  16. string output = "";
  17. for(int i = 0; i < input.length(); i++) {
  18. int c = (input[i]-97-key);
  19. if(c < 0)
  20. c += 26;
  21. output +=(char)(c+97);
  22. }
  23. return output;
  24. }
  25.  
  26. int main()
  27. {//gnsgjsungskj : ahmadmohamed
  28.  
  29. cout << decode_ceaser("bjerxabfruufrwcqnorsqc ", 9) << endl;
  30.  
  31. char alphabets[26];
  32. char a = 'a';
  33. for(int i = 0; i < 26; i++) {
  34. alphabets[i] = a++;
  35. cout << (char)(a-1) << ' ';
  36. }
  37. cout << endl;
  38. int key = 8;
  39. for(int i = 0; i < 26; i++) {
  40. int c = (i-key);
  41. if(i - key < 0)
  42. c += 26;
  43.  
  44.  
  45.  
  46. cout << alphabets[c] << ' ';
  47. }
  48.  
  49.  
  50. return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement