Created
February 11, 2018 11:00
-
-
Save 0xDaksh/fe6eec0b193b704ee66a2d3f664e5d59 to your computer and use it in GitHub Desktop.
CaesarCipher turned into C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <fstream> | |
#include <stdlib.h> | |
using namespace std; | |
/* | |
Ceaser Cipher | |
- Julius Caesar (Inventor of July & CeaserCipher) | |
So He basically shifted each letter in a way that the enemy thinks that it's meaningless wordless. | |
He applied the shift by 3, and the two parties knew in advance that they have to shift the letters by 3. | |
Let's use it here! | |
*/ | |
class CaesarCipher { | |
// parameters / props of the class | |
int shifts; | |
string message; | |
// Methods | |
public: | |
void start(); | |
void getDetails(); | |
void performCipher(); | |
void end(); | |
}; | |
void CaesarCipher::start() { | |
getDetails(); | |
performCipher(); | |
end(); | |
} | |
void CaesarCipher::getDetails() { | |
cout<<"Please Enter the Message to be CaesarCiphered: "; | |
getline(cin, message); | |
cout<<"\nBy What amount do you want to shift: "; | |
cin>>shifts; | |
if (shifts <= 0) { | |
cout<<"\nYou can't shift your string by 0 or a negative number"; | |
exit(0); | |
} | |
} | |
void CaesarCipher::performCipher() { | |
for(int i = 0; i < message.length(); i++) { | |
message[i] = char(message[i] + shifts); | |
} | |
} | |
void CaesarCipher::end() { | |
cout<<"\nThe Ciphered Message is: "; | |
cout<<message<<endl; | |
} | |
int main() { | |
CaesarCipher instance; | |
cout<<"###@@@--- Welcome to the Ceaser Cipher ---@@@###\n"; | |
instance.start(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment