-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
88 lines (78 loc) · 2.22 KB
/
mainwindow.cpp
File metadata and controls
88 lines (78 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "mainwindow.h"
#include "ui_mainwindow.h"
/*
================
MainWindow::MainWindow
Constructor
================
*/
MainWindow::MainWindow(QApplication *app) :
QMainWindow(),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->setWindowTitle("AES-128 Encryption");
connect(ui->buttonQuit, SIGNAL(clicked()), app, SLOT(quit()));
}
/*
================
MainWindow::~MainWindow
Destructor
================
*/
MainWindow::~MainWindow()
{
delete ui;
}
/*
================
MainWindow::on_buttonEncrypt_clicked
Encrypts the text in lineEditInput using key in lineEditKey
and displays result in lineEditEncrypted
================
*/
void MainWindow::on_buttonEncrypt_clicked()
{
int returncode = aes.InputForEncrypt(ui->lineEditInput->toPlainText().toStdString(), ui->lineEditKey->text().toStdString());
if (returncode == 1) {
ui->statusBar->showMessage("There's nothing in 'Input'");
}
else if (returncode == 2) {
ui->statusBar->showMessage("Key should have less than 16 symbols");
}
else if (returncode == 3) {
ui->statusBar->showMessage("Key is empty");
}
else {
ui->statusBar->clearMessage();
string str = aes.Encrypt();
ui->lineEditEncrypted->clear();
ui->lineEditEncrypted->append(QString::fromUtf8( str.data(), str.size() ));
}
}
/*
================
MainWindow::on_buttonDecrypt_clicked
Decrypts the text in lineEditEncrypt using key in lineEditKey
and displays result in lineEditDecrypt
================
*/
void MainWindow::on_buttonDecrypt_clicked()
{
int returncode = aes.InputForDecrypt(ui->lineEditEncrypted->toPlainText().toStdString(), ui->lineEditKey->text().toStdString());
if (returncode == 1) {
ui->statusBar->showMessage("Number of symbols in 'Encrypted' should be divisible by 32");
}
else if (returncode == 2) {
ui->statusBar->showMessage("Key should have less than 16 symbols");
}
else if (returncode == 3) {
ui->statusBar->showMessage("Key is empty");
}
else {
ui->statusBar->clearMessage();
string str = aes.Decrypt();
ui->lineEditDecrypted->clear();
ui->lineEditDecrypted->append(QString::fromUtf8( str.data(), str.size() ));
}
}