Here is a little encryptor I wrote, I'm just asking for people to tell me what is good practice and what's not. Also, I mean the code, not the actual encryption (because it's just a dumb thing).
#include "stdafx.h"
#include <iostream>
#include <stdexcept>
using namespace std;
int encrypter(int input);
int decrypter(int input);
bool whatToDoFunc();
int main()
{
try
{
bool keepGoing = true;
while (keepGoing)
{
bool success = whatToDoFunc(); char redo;
cout << "Press 'y' to redo or anykey to exit" << endl;
cin >> redo;
if (success == true && (redo == 'y' || redo == 'Y'))
keepGoing == true;
else
keepGoing = false;
}
}
catch (runtime_error err)
{
cout << err.what() << endl;
char exitCon;
cout << "Enter anykey to exit" << endl;
cin >> exitCon;
return -1;
}
return 0;
}
bool whatToDoFunc()
{
int input;
char whatToDo;
cout << "Welcome to the JeGo encrypter what do you want to do encrypt or decrypy? Enter E or D\n" << endl;
cin >> whatToDo;
if (whatToDo == 'e' || whatToDo == 'E')
{
cout << "Enter the number you want to encrypt" << endl;
cin >> input;
int inputEncrypted = encrypter(input);
cout << "Your number encrypted is " << inputEncrypted << endl;
}
else
{
if (whatToDo == 'd' || whatToDo == 'D')
{
cout << "Enter the already encrypted number" << endl;
cin >> input;
int numDecrypted = decrypter(input);
cout << "Your number decrypted is " << numDecrypted << endl;
}
else
{
cerr << "Error" << endl;
throw runtime_error("Your input was invalid");
}
}
return true;
}
int encrypter(int input)
{
int inputEncrypted;
inputEncrypted = ((((input * 2) + 7) + 5) + 8);
if (inputEncrypted % 2 == 0)
++inputEncrypted;
else
inputEncrypted = inputEncrypted + (13 + 13) + (11 + 11);
return inputEncrypted;
}
int decrypter(int inputEncrypted)
{
int decryptedNum = 0;
if (inputEncrypted % 2 == 1)
--inputEncrypted;
else
{
(11 - 11) - (13 - 13) - inputEncrypted;
}
decryptedNum = ((((inputEncrypted - 8) - 5) - 7) / 2);
return decryptedNum;
}
Please tell me what I could do to make it better or just nicer design! :)
(11 - 11) - (13 - 13) - inputEncrypted;
does absolutely nothing. \$\endgroup\$inputEncrypted
to a negative number. \$\endgroup\$