Abdulg

Caesar Cipher

Feb 11th, 2014
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. /*
  2. Made for Jonas and Callum by their favourite
  3. Compiled using g++ under Debian GNU/Linux
  4. */
  5.  
  6. #include<iostream>
  7. #include<vector>
  8. #include<string.h>
  9. #include<stdio.h>
  10.  
  11. #define PUSH 3
  12.  
  13. using namespace std;
  14.  
  15. int main()
  16. {
  17.     string Input = "string Input";
  18.     cout << "Please enter your sentence: \n>";
  19.     getline(cin,Input);
  20.    
  21.     char Buffer[1024];
  22.     char Output[1024];
  23.     strcpy(Buffer,Input.c_str());
  24.    
  25.     for (int i = 0; i < Input.length(); i++)
  26.     {
  27.     Buffer[i] = tolower(Buffer[i]); //you're getting lowercase
  28.     if (Buffer[i] < 61) Output[i] = Buffer[i];
  29.     else if (Buffer[i] > 122 - PUSH) Output[i] = Buffer[i] + PUSH - 26;
  30.     else Output[i] = Buffer[i] += PUSH;
  31.     }
  32.     cout << "\nYour 'encrypted' string is: ";
  33.     for(int i = 0; i <= Input.length(); i++) cout << Output[i];
  34.     cout << endl;
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment