Skip to content

Commit 7372e26

Browse files
committed
Added sources.
1 parent 9ff96d3 commit 7372e26

7 files changed

+403
-0
lines changed

app/main.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include "mainwindow.h"
2+
#include <QApplication>
3+
4+
int main(int argc, char *argv[])
5+
{
6+
QApplication a(argc, argv);
7+
MainWindow w;
8+
w.show();
9+
10+
return a.exec();
11+
}

app/mainwindow.cpp

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include "mainwindow.h"
2+
#include "ui_mainwindow.h"
3+
#include "teaencryptor.h"
4+
#include <stdint.h>
5+
6+
MainWindow::MainWindow(QWidget *parent) :
7+
QMainWindow(parent),
8+
ui(new Ui::MainWindow)
9+
{
10+
ui->setupUi(this);
11+
}
12+
13+
MainWindow::~MainWindow()
14+
{
15+
delete ui;
16+
}
17+
18+
void MainWindow::on_pushButtonEncrypt_clicked()
19+
{
20+
// Read input values from form
21+
uint32_t v1 = this->ui->lineEditV1->text().toInt();
22+
uint32_t v2 = this->ui->lineEditV2->text().toInt();
23+
uint32_t v[2] = { v1, v2 };
24+
uint32_t k1 = this->ui->lineEditK1->text().toInt();
25+
uint32_t k2 = this->ui->lineEditK2->text().toInt();
26+
uint32_t k3 = this->ui->lineEditK3->text().toInt();
27+
uint32_t k4 = this->ui->lineEditK4->text().toInt();
28+
uint32_t k[4] = { k1, k2, k3, k4 };
29+
// Create TEA encryptor
30+
TeaEncryptor* encryptor = new TeaEncryptor();
31+
// Encrypt values
32+
encryptor->encrypt(&v[0], &k[0]);
33+
// Output results
34+
QString v1_encrypted = QString::number(v[0]);
35+
this->ui->lineEditEncryptedV1->setText(v1_encrypted);
36+
QString v2_encrypted = QString::number(v[1]);
37+
this->ui->lineEditEncryptedV2->setText(v2_encrypted);
38+
}

app/mainwindow.h

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#ifndef MAINWINDOW_H
2+
#define MAINWINDOW_H
3+
4+
#include <QMainWindow>
5+
6+
namespace Ui {
7+
class MainWindow;
8+
}
9+
10+
class MainWindow : public QMainWindow
11+
{
12+
Q_OBJECT
13+
14+
public:
15+
explicit MainWindow(QWidget *parent = 0);
16+
~MainWindow();
17+
18+
private slots:
19+
20+
void on_pushButtonEncrypt_clicked();
21+
22+
private:
23+
Ui::MainWindow *ui;
24+
};
25+
26+
#endif // MAINWINDOW_H

app/mainwindow.ui

+264
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>MainWindow</class>
4+
<widget class="QMainWindow" name="MainWindow">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>421</width>
10+
<height>322</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>TEA Encoder</string>
15+
</property>
16+
<widget class="QWidget" name="centralWidget">
17+
<widget class="QPushButton" name="pushButtonEncrypt">
18+
<property name="geometry">
19+
<rect>
20+
<x>320</x>
21+
<y>150</y>
22+
<width>81</width>
23+
<height>22</height>
24+
</rect>
25+
</property>
26+
<property name="text">
27+
<string>Encrypt</string>
28+
</property>
29+
</widget>
30+
<widget class="QGroupBox" name="groupBoxResult">
31+
<property name="geometry">
32+
<rect>
33+
<x>20</x>
34+
<y>170</y>
35+
<width>381</width>
36+
<height>91</height>
37+
</rect>
38+
</property>
39+
<property name="title">
40+
<string>Encrypted values</string>
41+
</property>
42+
<widget class="QLineEdit" name="lineEditEncryptedV1">
43+
<property name="geometry">
44+
<rect>
45+
<x>60</x>
46+
<y>50</y>
47+
<width>113</width>
48+
<height>22</height>
49+
</rect>
50+
</property>
51+
</widget>
52+
<widget class="QLineEdit" name="lineEditEncryptedV2">
53+
<property name="geometry">
54+
<rect>
55+
<x>190</x>
56+
<y>50</y>
57+
<width>113</width>
58+
<height>22</height>
59+
</rect>
60+
</property>
61+
</widget>
62+
<widget class="QLabel" name="labelEncryptedV1">
63+
<property name="geometry">
64+
<rect>
65+
<x>60</x>
66+
<y>30</y>
67+
<width>59</width>
68+
<height>14</height>
69+
</rect>
70+
</property>
71+
<property name="text">
72+
<string>V1:</string>
73+
</property>
74+
</widget>
75+
<widget class="QLabel" name="labelEncryptedV2">
76+
<property name="geometry">
77+
<rect>
78+
<x>190</x>
79+
<y>30</y>
80+
<width>59</width>
81+
<height>14</height>
82+
</rect>
83+
</property>
84+
<property name="text">
85+
<string>V2:</string>
86+
</property>
87+
</widget>
88+
</widget>
89+
<widget class="QGroupBox" name="groupBoxRawValues">
90+
<property name="geometry">
91+
<rect>
92+
<x>20</x>
93+
<y>0</y>
94+
<width>381</width>
95+
<height>141</height>
96+
</rect>
97+
</property>
98+
<property name="title">
99+
<string>Raw values</string>
100+
</property>
101+
<widget class="QLabel" name="labelV1">
102+
<property name="geometry">
103+
<rect>
104+
<x>60</x>
105+
<y>30</y>
106+
<width>59</width>
107+
<height>14</height>
108+
</rect>
109+
</property>
110+
<property name="text">
111+
<string>V1:</string>
112+
</property>
113+
</widget>
114+
<widget class="QLabel" name="labelV2">
115+
<property name="geometry">
116+
<rect>
117+
<x>190</x>
118+
<y>30</y>
119+
<width>59</width>
120+
<height>14</height>
121+
</rect>
122+
</property>
123+
<property name="text">
124+
<string>V2:</string>
125+
</property>
126+
</widget>
127+
<widget class="QLineEdit" name="lineEditV2">
128+
<property name="geometry">
129+
<rect>
130+
<x>190</x>
131+
<y>50</y>
132+
<width>113</width>
133+
<height>22</height>
134+
</rect>
135+
</property>
136+
</widget>
137+
<widget class="QLineEdit" name="lineEditV1">
138+
<property name="geometry">
139+
<rect>
140+
<x>60</x>
141+
<y>50</y>
142+
<width>113</width>
143+
<height>22</height>
144+
</rect>
145+
</property>
146+
</widget>
147+
<widget class="QLabel" name="labelK1">
148+
<property name="geometry">
149+
<rect>
150+
<x>10</x>
151+
<y>80</y>
152+
<width>59</width>
153+
<height>14</height>
154+
</rect>
155+
</property>
156+
<property name="text">
157+
<string>K1:</string>
158+
</property>
159+
</widget>
160+
<widget class="QLineEdit" name="lineEditK1">
161+
<property name="geometry">
162+
<rect>
163+
<x>10</x>
164+
<y>100</y>
165+
<width>71</width>
166+
<height>22</height>
167+
</rect>
168+
</property>
169+
</widget>
170+
<widget class="QLabel" name="labelK2">
171+
<property name="geometry">
172+
<rect>
173+
<x>100</x>
174+
<y>80</y>
175+
<width>59</width>
176+
<height>14</height>
177+
</rect>
178+
</property>
179+
<property name="text">
180+
<string>K2:</string>
181+
</property>
182+
</widget>
183+
<widget class="QLineEdit" name="lineEditK2">
184+
<property name="geometry">
185+
<rect>
186+
<x>100</x>
187+
<y>100</y>
188+
<width>71</width>
189+
<height>22</height>
190+
</rect>
191+
</property>
192+
</widget>
193+
<widget class="QLineEdit" name="lineEditK3">
194+
<property name="geometry">
195+
<rect>
196+
<x>190</x>
197+
<y>100</y>
198+
<width>81</width>
199+
<height>22</height>
200+
</rect>
201+
</property>
202+
</widget>
203+
<widget class="QLabel" name="labelK3">
204+
<property name="geometry">
205+
<rect>
206+
<x>190</x>
207+
<y>80</y>
208+
<width>59</width>
209+
<height>14</height>
210+
</rect>
211+
</property>
212+
<property name="text">
213+
<string>K3:</string>
214+
</property>
215+
</widget>
216+
<widget class="QLineEdit" name="lineEditK4">
217+
<property name="geometry">
218+
<rect>
219+
<x>290</x>
220+
<y>100</y>
221+
<width>81</width>
222+
<height>22</height>
223+
</rect>
224+
</property>
225+
</widget>
226+
<widget class="QLabel" name="labelK4">
227+
<property name="geometry">
228+
<rect>
229+
<x>290</x>
230+
<y>80</y>
231+
<width>59</width>
232+
<height>14</height>
233+
</rect>
234+
</property>
235+
<property name="text">
236+
<string>K4:</string>
237+
</property>
238+
</widget>
239+
</widget>
240+
</widget>
241+
<widget class="QMenuBar" name="menuBar">
242+
<property name="geometry">
243+
<rect>
244+
<x>0</x>
245+
<y>0</y>
246+
<width>421</width>
247+
<height>19</height>
248+
</rect>
249+
</property>
250+
</widget>
251+
<widget class="QToolBar" name="mainToolBar">
252+
<attribute name="toolBarArea">
253+
<enum>TopToolBarArea</enum>
254+
</attribute>
255+
<attribute name="toolBarBreak">
256+
<bool>false</bool>
257+
</attribute>
258+
</widget>
259+
<widget class="QStatusBar" name="statusBar"/>
260+
</widget>
261+
<layoutdefault spacing="6" margin="11"/>
262+
<resources/>
263+
<connections/>
264+
</ui>

app/tea_encrypto.pro

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
QT += core gui
2+
3+
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
4+
5+
TARGET = tea_encrypto
6+
TEMPLATE = app
7+
8+
9+
SOURCES += main.cpp\
10+
mainwindow.cpp \
11+
teaencryptor.cpp
12+
13+
HEADERS += mainwindow.h \
14+
teaencryptor.h
15+
16+
FORMS += mainwindow.ui

app/teaencryptor.cpp

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include "teaencryptor.h"
2+
#include <stdint.h>
3+
4+
TeaEncryptor::TeaEncryptor()
5+
{
6+
7+
}
8+
9+
void TeaEncryptor::encrypt(uint32_t* v, uint32_t* k)
10+
{
11+
uint32_t v0 = v[0], v1 = v[1], sum = 0, i; /* set up */
12+
uint32_t delta = 0x9e3779b9; /* a key schedule constant */
13+
uint32_t k0 = k[0], k1 = k[1], k2 = k[2], k3 = k[3]; /* cache key */
14+
for (i = 0; i < 32; i++) { /* basic cycle start */
15+
sum += delta;
16+
v0 += ((v1 << 4) + k0) ^ (v1 + sum) ^ ((v1 >> 5) + k1);
17+
v1 += ((v0 << 4) + k2) ^ (v0 + sum) ^ ((v0 >> 5) + k3);
18+
} /* end cycle */
19+
v[0] = v0; v[1] = v1;
20+
}
21+
22+
23+
void TeaEncryptor::decrypt(uint32_t* v, uint32_t* k)
24+
{
25+
uint32_t v0 = v[0], v1 = v[1], sum = 0xC6EF3720, i; /* set up */
26+
uint32_t delta = 0x9e3779b9; /* a key schedule constant */
27+
uint32_t k0 = k[0], k1 = k[1], k2 = k[2], k3 = k[3]; /* cache key */
28+
for (i = 0; i<32; i++) { /* basic cycle start */
29+
v1 -= ((v0 << 4) + k2) ^ (v0 + sum) ^ ((v0 >> 5) + k3);
30+
v0 -= ((v1 << 4) + k0) ^ (v1 + sum) ^ ((v1 >> 5) + k1);
31+
sum -= delta;
32+
} /* end cycle */
33+
v[0] = v0; v[1] = v1;
34+
}

0 commit comments

Comments
 (0)