Skip to content

Commit

Permalink
Fix indentation
Browse files Browse the repository at this point in the history
  • Loading branch information
faheel authored Feb 2, 2017
1 parent 17262a8 commit 987277b
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions Networking/SubstitutionCipher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,35 @@
using namespace std;

string substitution_cipher(const string &plain_text, const int &shift) {
string cipher_text;

char shifted_char;
for (size_t i = 0; i < plain_text.size(); i++) {
if (plain_text[i] >= 'a' and plain_text[i] <= 'z')
shifted_char = 'a' + ((int(plain_text[i]) + shift - int('a')) % 26);
else if (plain_text[i] >= 'A' and plain_text[i] <= 'Z')
shifted_char = 'A' + ((int(plain_text[i]) + shift - int('A')) % 26);
else if (plain_text[i] >= '0' and plain_text[i] <= '9')
shifted_char = '0' + ((int(plain_text[i]) + shift - int('0')) % 10);
else
shifted_char = plain_text[i];
cipher_text += shifted_char;
}

return cipher_text + '\0';
string cipher_text;

char shifted_char;
for (size_t i = 0; i < plain_text.size(); i++) {
if (plain_text[i] >= 'a' and plain_text[i] <= 'z')
shifted_char = 'a' + ((int(plain_text[i]) + shift - int('a')) % 26);
else if (plain_text[i] >= 'A' and plain_text[i] <= 'Z')
shifted_char = 'A' + ((int(plain_text[i]) + shift - int('A')) % 26);
else if (plain_text[i] >= '0' and plain_text[i] <= '9')
shifted_char = '0' + ((int(plain_text[i]) + shift - int('0')) % 10);
else
shifted_char = plain_text[i];
cipher_text += shifted_char;
}

return cipher_text + '\0';
}

int main() {
string plain_text;
cout << "Enter plain text : ";
getline(cin, plain_text);
string plain_text;
cout << "Enter plain text : ";
getline(cin, plain_text);

int shift;
cout << "Enter shift amount : ";
cin >> shift;
int shift;
cout << "Enter shift amount : ";
cin >> shift;

string cipher_text = substitution_cipher(plain_text, shift);
cout << "Cipher text : " << cipher_text << "\n";
string cipher_text = substitution_cipher(plain_text, shift);
cout << "Cipher text : " << cipher_text << "\n";

return 0;
return 0;
}

0 comments on commit 987277b

Please sign in to comment.