-1

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();
    }
}
halfer
  • 19,824
  • 17
  • 99
  • 186
school_guy
  • 300
  • 2
  • 14

1 Answers1

2

AES is an encryption algorithm. The function is not closed on [a-zA-Z0-9]. Meaning you can get any value between 0 and 256 in the encrypted string.

If you still want to visualize the encrypted output (for comparison and verification purpose), I will suggest convert each byte to hexadecimal representation which contains only readable characters.

See this, to know how to convert byte buffers to hexadecimal.

Community
  • 1
  • 1
Ajay Brahmakshatriya
  • 8,993
  • 3
  • 26
  • 49