Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include <string>
- using namespace std;
- string encode_ceaser(string input, int key) {
- string output = "";
- for(int i = 0; i < input.length(); i++) {
- char c = (input[i]-97+key)%26;
- output +=c+97;
- }
- return output;
- }
- string decode_ceaser(string input, int key) {
- string output = "";
- for(int i = 0; i < input.length(); i++) {
- int c = (input[i]-97-key);
- if(c < 0)
- c += 26;
- output +=(char)(c+97);
- }
- return output;
- }
- int main()
- {//gnsgjsungskj : ahmadmohamed
- cout << decode_ceaser("bjerxabfruufrwcqnorsqc ", 9) << endl;
- char alphabets[26];
- char a = 'a';
- for(int i = 0; i < 26; i++) {
- alphabets[i] = a++;
- cout << (char)(a-1) << ' ';
- }
- cout << endl;
- int key = 8;
- for(int i = 0; i < 26; i++) {
- int c = (i-key);
- if(i - key < 0)
- c += 26;
- cout << alphabets[c] << ' ';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement