I am currently doing a project for school (comparison between runntime of two cryptographic functions). So I searched for AES. I found this nice looking solution: https://www.c-plusplus.net/forum/148732
Now when I am using as a key aes
and as plaintext also aes
, then I get a strange result with characters that are not a-z
.
My full project can be viewed at: https://gogs.4seul.de/root/CryptLaufzeit
void MainWindow::on_pushButtonAesCalc_clicked()
{
//Check if key and plaintext is given (if not -> display alert,if yes -> save in vars)
QString key=ui->lineEditAesKey->text();
QString plaintext=ui->lineEditAesPlaintext->text();
if (key != "" && plaintext != "") {
//Time measure start
std::chrono::time_point<std::chrono::system_clock> start, end;
start = std::chrono::system_clock::now();
//Create AES Object
//char array for key and plaintext; length is size_t type and length of char array
size_t sizeKey = key.size();
size_t sizePlain = plaintext.size();
char *plainCharArr = new char [sizePlain];
char *keyCharArr = new char [sizeKey];
memcpy( keyCharArr, key.toStdString().c_str() ,sizeKey);
memcpy( plainCharArr, plaintext.toStdString().c_str() ,sizePlain);
aes AES;
sizePlain = AES.encrypt(&plainCharArr,sizePlain,keyCharArr);
//Time measure end
end = std::chrono::system_clock::now();
std::chrono::duration<double> elapsed_seconds = end-start;
std::time_t end_time = std::chrono::system_clock::to_time_t(end);
//Rerun everything and get steps in between (optional)
//Set values
QMessageBox msgBoxTest;
msgBoxTest.setText(plaintext + "|" + plainCharArr);
msgBoxTest.exec();
} else {
//Display Dialog
QMessageBox msgBox;
msgBox.setText("Bitte fülle alle Felder aus!");
msgBox.exec();
}
}