-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
159 lines (127 loc) · 4.14 KB
/
mainwindow.cpp
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <algorithm>
#include <QInputDialog>
#include <QFileDialog>
#include <QClipboard>
mainWindow::mainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::mainWindow)
{
ui->setupUi(this);
}
mainWindow::~mainWindow()
{
delete ui;
}
//AES
void mainWindow::on_aes_btn_crypt_clicked()
{
QString text = ui->aes_crypt->toPlainText();
QString password = ui->aes_pass_left->text();
params << root + "/AES/Rijndael.py" << "-m=e" << "-p=" + password << "-t=" + text;
p.setProcessChannelMode(QProcess::MergedChannels);
p.start("python3", params);
p.waitForFinished(-1);
QString p_stdout = p.readAll();
ui->aes_crypt->setPlainText(p_stdout);
params.clear();
}
void mainWindow::on_aes_btn_decrypt_clicked()
{
QString text = ui->aes_decrypt->toPlainText();
text.replace("\n", ""); //Verhindert Verfälschung der Eingabe durch Leerzeilen
text.replace(" ", ""); //Verhindert Verfälschung der Eingabe durch Leerzeichen
QString password = ui->aes_pass_right->text();
params << root + "/AES/Rijndael.py" << "-m=d" << "-p=" + password << "-t=" + text;
p.setProcessChannelMode(QProcess::MergedChannels);
p.start("python3", params);
p.waitForFinished(-1);
QString p_stdout = p.readAll();
ui->aes_decrypt->setPlainText(p_stdout);
params.clear();
}
void mainWindow::on_aes_btn_copy_left_clicked()
{
QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(ui->aes_crypt->toPlainText());
}
void mainWindow::on_aes_btn_copy_right_clicked()
{
QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(ui->aes_decrypt->toPlainText());
}
void mainWindow::on_aes_clear_left_clicked()
{
ui->aes_crypt->clear();
}
void mainWindow::on_aes_clear_right_clicked()
{
ui->aes_decrypt->clear();
}
//RSA
void mainWindow::on_rsa_btn_keygen_clicked()
{
bool status;
QString keyname = QInputDialog::getText(this, "RSA Keygen", "Keyname:", QLineEdit::Normal, "NewKey", &status);
if (status && !keyname.isEmpty())
{
params << "/home/jan/Dokumente/PU/RSA/TEST/RSA.py" << "-m=1" << "-n=" + keyname;
p.setProcessChannelMode(QProcess::MergedChannels);
p.start("python3", params);
p.waitForFinished(-1);
params.clear();
msgbox.setText("Schlüssel erfolgreich erstellt und abgelegt.");
msgbox.exec();
}
}
void mainWindow::on_rsa_select_pubkey_clicked()
{
QString fileName = QFileDialog::getOpenFileName(this, "Select Keypair", root + "/GUI/build_debug/keys/", "JSON Key-Files (*.json)");
ui->rsa_pubkey->setText(fileName);
}
void mainWindow::on_rsa_select_privkey_clicked()
{
QString fileName = QFileDialog::getOpenFileName(this, "Select Keypair", root + "/GUI/build_debug/keys/", "JSON Key-Files (*.json)");
ui->rsa_privkey->setText(fileName);
}
void mainWindow::on_rsa_btn_crypt_clicked()
{
QString text = ui->rsa_crypt->toPlainText();
params << root + "/RSA/TEST/RSA.py" << "-m=2" << "-n=" + ui->rsa_pubkey->text() << "-t=" + text;
p.setProcessChannelMode(QProcess::MergedChannels);
p.start("python3", params);
p.waitForFinished(-1);
QString p_stdout = p.readAll();
ui->rsa_crypt->setPlainText(p_stdout);
params.clear();
}
void mainWindow::on_rsa_btn_decrypt_clicked()
{
QString text = ui->rsa_decrypt->toPlainText();
params << root + "/RSA/TEST/RSA.py" << "-m=3" << "-n=" + ui->rsa_privkey->text() << "-t=" + text;
p.setProcessChannelMode(QProcess::MergedChannels);
p.start("python3", params);
p.waitForFinished(-1);
QString p_stdout = p.readAll();
ui->rsa_decrypt->setPlainText(p_stdout);
params.clear();
}
void mainWindow::on_rsa_btn_copy_left_clicked()
{
QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(ui->rsa_crypt->toPlainText());
}
void mainWindow::on_rsa_btn_copy_right_clicked()
{
QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(ui->rsa_decrypt->toPlainText());
}
void mainWindow::on_rsa_clear_left_clicked()
{
ui->rsa_crypt->clear();
}
void mainWindow::on_rsa_clear_right_clicked()
{
ui->rsa_decrypt->clear();
}