Skip to content

Commit

Permalink
revised specification, updated readme, refactored main loop and imple…
Browse files Browse the repository at this point in the history
…mentation
  • Loading branch information
calebTree committed Aug 20, 2021
1 parent f8704ad commit 1802db2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
.idea/
CMakeLists.txt
cmake-build-debug/
.run
.run
*.exe
*.o
*~
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Julius Caesar's Substitution Cipher!
# Caleb's Caesar Shift/Substitution Cipher!
Enter an integer (key) to left shift the normal alphabet by that number of positions.
Then, enter a message to encrypt using your new cipher alphabet.
🔥 FYI a key of 13 is effectively ROT-13.
Expand Down
5 changes: 1 addition & 4 deletions caesar-cipher.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#include "caesar-cipher.h"

// https://www.tutorialspoint.com/cplusplus-program-to-implement-caesar-cypher
// https://www.asciihex.com/

using namespace std;

void encryption(const string &plainAlpha) {
Expand All @@ -20,7 +17,7 @@ void encryption(const string &plainAlpha) {
cin >> key;
}
cin.ignore(numeric_limits<streamsize>::max(), '\n'); // discard \n
cout << "Enter the message to encrypt: "; // input message to encrypt
cout << "Enter the message to encrypt: "; // input message to encrypt
getline(cin, message);

// shift alphabet [key] letters to the left
Expand Down
18 changes: 9 additions & 9 deletions caesar-cipher.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@
using namespace std;

void encryption(const string&);
// Function to display encrypt interface
// Postcondition: const string is the alphabet displayed in plain then in ciphered
// Function to display encrypt interface.
// Postcondition: const string is the alphabet displayed in plain then in ciphered.

void decryption(const string&);
// Function to display decrypt interface
// Postcondition: const string is the alphabet displayed in plain then in ciphered
// Function to display decrypt interface.
// Postcondition: const string is the alphabet displayed in plain then in ciphered.

string cipherAlpha(int&, const string&);
// Function to generate cipher alphabet.
// Postcondition: const string is shifted left by const int positions
// Postcondition: const string is alphabet shifted left by int positions.

string cipherMessage(const string&, int&);
// Function to encrypt the message
// Postcondition: string message shifted left by int positions
// Function to encrypt the message.
// Postcondition: const string is message shifted left by int positions.

string decrypt(const string&, int&);
// Function to decrypt the message
// Postcondition: string ciphertext shifted back to the right by int positions
// Function to decrypt the message.
// Postcondition: const string is ciphertext shifted back by int positions.
4 changes: 2 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ int main() {
int option;
string plainAlpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

while (cin) {
for(;;) {
cout << "(1) Encrypt, (2) Decrypt, (0) Quit: ";
cin >> option;
if (!cin) {
if (cin.fail()) {
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << "Error! Invalid input." << endl;
Expand Down

0 comments on commit 1802db2

Please sign in to comment.