Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
CaesarCipher turned into C++
#include <iostream>
#include <fstream>
#include <stdlib.h>
using namespace std;
/*
Ceaser Cipher
- Julius Caesar (Inventor of July &amp; 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