Skip to content

Instantly share code, notes, and snippets.

@0xDaksh
Created February 11, 2018 11:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0xDaksh/fe6eec0b193b704ee66a2d3f664e5d59 to your computer and use it in GitHub Desktop.
Save 0xDaksh/fe6eec0b193b704ee66a2d3f664e5d59 to your computer and use it in GitHub Desktop.
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