I have a basic encryption program that I have written, it takes input from the user from their encrypted text, usually in the form of Unicode characters. But when I do this:
cout << "Your decrypted string is : " << decryptstring(text, key) << endl;
è
-118
cout << "Your decrypted string is : " << decryptstring("è", key) << endl;
getline(cin, text);
#include <iostream>
#include <string>
#include <vector>
using namespace std;
string decryptstring(string text, string key)
{
//Declare variables
int i = 1;
int result;
int tmp;
int tmp2;
vector < char > arr;
//Start decryption
while(i <= text.length())
{
/*
Get letter from the string and get letter from key
and use Vigenere cipher to decrypt the data.
*/
tmp = text[i - 1];
tmp2 = key[i - 1];
cout << tmp << endl;
//Get encrypted value
result = tmp - tmp2;
//Change it into readable stuff
arr.push_back(result);
//Increment i
i++;
}
string str(arr.begin(), arr.end());
return str;
}
You need to use wide characters for unicode.
So have decryptstring
thus:
std::wstring decryptstring(const std::wstring& text, const std::wstring& key) {
// Do stuff
return text;
}
Then
std::wcout << L"Your decrypted string is : " << decryptstring(text, key) < std::endl;
std::wcout << L"Your decrypted string is : " << decryptstring(L"è", key) << std::endl;
Where
std::wstring text; // is declared before use