Just to try to expand my skills, how basic they might be, I decided to try basic encryption/decryption. This is my start at encryption... And it IS basic. Haha.
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
usingnamespace std;
int _tmain(int argc, _TCHAR* argv[])
{
string given, encrypted;
int length, key;
// Input
cout << "Please type what is to be encrypted:" << endl;
getline(cin, given);
length = given.length(); // Get length of string
cout << endl << "Please enter the encryption key: ";
cin >> key; // number by which characters will be changed
for(int a = 0; a < length; a++) // the main loop
encrypted[a] = given[a] + key;
// Output
cout << endl << "Your given text is: " << endl << encrypted << endl << endl;
system("pause");
return 0;
}
When I run this, I get an error message "string subscript out of range". I've tried things like converting the strings to char arrays, which have a whole other problem themselves, and by now, a few hours on google. Including staring at my screen and going through each line multiple times. I'm at a huge loss. Any help is well appreciated, including anything about my coding not really related to this problem.