I created my first ciphering program, which uses a quadratic equation as the encrypting algorithm. My goal was to make the code as minimalistic and readable as possible- what do you guys think? I am beginner, so please tell if this code represents any bad practices.
#include <iostream>
#include <string>
#include <cstdlib>
#include <math.h>
#include <map>
using namespace std;
int main()
{
std::map <char,int> val;
val['A','a'] = 1; val['H','h'] = 8; val['O','o'] = 15; val['V','v'] = 22;
val['B','b'] = 2; val['I','i'] = 9; val['P','p'] = 16; val['W','w'] = 23;
val['C','c'] = 3; val['J','j'] = 10; val['Q','q'] = 17; val['X','x'] = 24;
val['D','d'] = 4; val['K','k'] = 11; val['R','r'] = 18; val['Y','y'] = 25;
val['E','e'] = 5; val['L','l'] = 12; val['S','s'] = 19; val['Z','z'] = 26;
val['F','f'] = 6; val['M','m'] = 13; val['T','t'] = 20;
val['G','g'] = 7; val['N','n'] = 14; val['U','u'] = 21;
string alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
string sentence;
int a,b,c,x,y;
cout << "Enter a sentence to encode:" << endl;
getline(cin,sentence);
cout << "Input each modulus of encoding function: ax^2 + bx + c" << endl;
cout << "a = "; cin >> a;
cout << "b = "; cin >> b;
cout << "c = "; cin >> c;
for (unsigned i = 0; i <= sentence.length(); i ++)
{
x = (val[sentence[i]]);
y = a * pow(x,2) + b * x + c;
if ((y >= 0)&&(sentence[i] != ' '))
sentence[i] = alphabet[y % alphabet.length()];
if ((y < 0)&&(sentence[i] != ' '))
sentence[i] = alphabet[-(y % alphabet.length())];
}
cout << sentence;
}
