Skip to content

Commit

Permalink
Added sources.
Browse files Browse the repository at this point in the history
  • Loading branch information
eterey committed Jan 28, 2016
1 parent 9ff96d3 commit 7372e26
Show file tree
Hide file tree
Showing 7 changed files with 403 additions and 0 deletions.
11 changes: 11 additions & 0 deletions app/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "mainwindow.h"
#include <QApplication>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();

return a.exec();
}
38 changes: 38 additions & 0 deletions app/mainwindow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "teaencryptor.h"
#include <stdint.h>

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}

MainWindow::~MainWindow()
{
delete ui;
}

void MainWindow::on_pushButtonEncrypt_clicked()
{
// Read input values from form
uint32_t v1 = this->ui->lineEditV1->text().toInt();
uint32_t v2 = this->ui->lineEditV2->text().toInt();
uint32_t v[2] = { v1, v2 };
uint32_t k1 = this->ui->lineEditK1->text().toInt();
uint32_t k2 = this->ui->lineEditK2->text().toInt();
uint32_t k3 = this->ui->lineEditK3->text().toInt();
uint32_t k4 = this->ui->lineEditK4->text().toInt();
uint32_t k[4] = { k1, k2, k3, k4 };
// Create TEA encryptor
TeaEncryptor* encryptor = new TeaEncryptor();
// Encrypt values
encryptor->encrypt(&v[0], &k[0]);
// Output results
QString v1_encrypted = QString::number(v[0]);
this->ui->lineEditEncryptedV1->setText(v1_encrypted);
QString v2_encrypted = QString::number(v[1]);
this->ui->lineEditEncryptedV2->setText(v2_encrypted);
}
26 changes: 26 additions & 0 deletions app/mainwindow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();

private slots:

void on_pushButtonEncrypt_clicked();

private:
Ui::MainWindow *ui;
};

#endif // MAINWINDOW_H
264 changes: 264 additions & 0 deletions app/mainwindow.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,264 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>421</width>
<height>322</height>
</rect>
</property>
<property name="windowTitle">
<string>TEA Encoder</string>
</property>
<widget class="QWidget" name="centralWidget">
<widget class="QPushButton" name="pushButtonEncrypt">
<property name="geometry">
<rect>
<x>320</x>
<y>150</y>
<width>81</width>
<height>22</height>
</rect>
</property>
<property name="text">
<string>Encrypt</string>
</property>
</widget>
<widget class="QGroupBox" name="groupBoxResult">
<property name="geometry">
<rect>
<x>20</x>
<y>170</y>
<width>381</width>
<height>91</height>
</rect>
</property>
<property name="title">
<string>Encrypted values</string>
</property>
<widget class="QLineEdit" name="lineEditEncryptedV1">
<property name="geometry">
<rect>
<x>60</x>
<y>50</y>
<width>113</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QLineEdit" name="lineEditEncryptedV2">
<property name="geometry">
<rect>
<x>190</x>
<y>50</y>
<width>113</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="labelEncryptedV1">
<property name="geometry">
<rect>
<x>60</x>
<y>30</y>
<width>59</width>
<height>14</height>
</rect>
</property>
<property name="text">
<string>V1:</string>
</property>
</widget>
<widget class="QLabel" name="labelEncryptedV2">
<property name="geometry">
<rect>
<x>190</x>
<y>30</y>
<width>59</width>
<height>14</height>
</rect>
</property>
<property name="text">
<string>V2:</string>
</property>
</widget>
</widget>
<widget class="QGroupBox" name="groupBoxRawValues">
<property name="geometry">
<rect>
<x>20</x>
<y>0</y>
<width>381</width>
<height>141</height>
</rect>
</property>
<property name="title">
<string>Raw values</string>
</property>
<widget class="QLabel" name="labelV1">
<property name="geometry">
<rect>
<x>60</x>
<y>30</y>
<width>59</width>
<height>14</height>
</rect>
</property>
<property name="text">
<string>V1:</string>
</property>
</widget>
<widget class="QLabel" name="labelV2">
<property name="geometry">
<rect>
<x>190</x>
<y>30</y>
<width>59</width>
<height>14</height>
</rect>
</property>
<property name="text">
<string>V2:</string>
</property>
</widget>
<widget class="QLineEdit" name="lineEditV2">
<property name="geometry">
<rect>
<x>190</x>
<y>50</y>
<width>113</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QLineEdit" name="lineEditV1">
<property name="geometry">
<rect>
<x>60</x>
<y>50</y>
<width>113</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="labelK1">
<property name="geometry">
<rect>
<x>10</x>
<y>80</y>
<width>59</width>
<height>14</height>
</rect>
</property>
<property name="text">
<string>K1:</string>
</property>
</widget>
<widget class="QLineEdit" name="lineEditK1">
<property name="geometry">
<rect>
<x>10</x>
<y>100</y>
<width>71</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="labelK2">
<property name="geometry">
<rect>
<x>100</x>
<y>80</y>
<width>59</width>
<height>14</height>
</rect>
</property>
<property name="text">
<string>K2:</string>
</property>
</widget>
<widget class="QLineEdit" name="lineEditK2">
<property name="geometry">
<rect>
<x>100</x>
<y>100</y>
<width>71</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QLineEdit" name="lineEditK3">
<property name="geometry">
<rect>
<x>190</x>
<y>100</y>
<width>81</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="labelK3">
<property name="geometry">
<rect>
<x>190</x>
<y>80</y>
<width>59</width>
<height>14</height>
</rect>
</property>
<property name="text">
<string>K3:</string>
</property>
</widget>
<widget class="QLineEdit" name="lineEditK4">
<property name="geometry">
<rect>
<x>290</x>
<y>100</y>
<width>81</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="labelK4">
<property name="geometry">
<rect>
<x>290</x>
<y>80</y>
<width>59</width>
<height>14</height>
</rect>
</property>
<property name="text">
<string>K4:</string>
</property>
</widget>
</widget>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>421</width>
<height>19</height>
</rect>
</property>
</widget>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
</widget>
<widget class="QStatusBar" name="statusBar"/>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>
16 changes: 16 additions & 0 deletions app/tea_encrypto.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = tea_encrypto
TEMPLATE = app


SOURCES += main.cpp\
mainwindow.cpp \
teaencryptor.cpp

HEADERS += mainwindow.h \
teaencryptor.h

FORMS += mainwindow.ui
34 changes: 34 additions & 0 deletions app/teaencryptor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "teaencryptor.h"
#include <stdint.h>

TeaEncryptor::TeaEncryptor()
{

}

void TeaEncryptor::encrypt(uint32_t* v, uint32_t* k)
{
uint32_t v0 = v[0], v1 = v[1], sum = 0, i; /* set up */
uint32_t delta = 0x9e3779b9; /* a key schedule constant */
uint32_t k0 = k[0], k1 = k[1], k2 = k[2], k3 = k[3]; /* cache key */
for (i = 0; i < 32; i++) { /* basic cycle start */
sum += delta;
v0 += ((v1 << 4) + k0) ^ (v1 + sum) ^ ((v1 >> 5) + k1);
v1 += ((v0 << 4) + k2) ^ (v0 + sum) ^ ((v0 >> 5) + k3);
} /* end cycle */
v[0] = v0; v[1] = v1;
}


void TeaEncryptor::decrypt(uint32_t* v, uint32_t* k)
{
uint32_t v0 = v[0], v1 = v[1], sum = 0xC6EF3720, i; /* set up */
uint32_t delta = 0x9e3779b9; /* a key schedule constant */
uint32_t k0 = k[0], k1 = k[1], k2 = k[2], k3 = k[3]; /* cache key */
for (i = 0; i<32; i++) { /* basic cycle start */
v1 -= ((v0 << 4) + k2) ^ (v0 + sum) ^ ((v0 >> 5) + k3);
v0 -= ((v1 << 4) + k0) ^ (v1 + sum) ^ ((v1 >> 5) + k1);
sum -= delta;
} /* end cycle */
v[0] = v0; v[1] = v1;
}
Loading

0 comments on commit 7372e26

Please sign in to comment.