PictureCrypt  1.4.1
An image-steganography project
encryptdialog.cpp
Go to the documentation of this file.
1 #include "encryptdialog.h"
2 #include "ui_encryptdialog.h"
9 EncryptDialog::EncryptDialog(QByteArray _data, QWidget *parent) :
10  QDialog(parent),
11  ui(new Ui::EncryptDialog)
12 {
13  ui->setupUi(this);
14  data = _data;
15  success = false;
16  // UI setup
17  ui->totalBytes->setText(QString::number(data.size()));
18  key = "";
19  compr_data = zip();
20  long long int compr_data_size = compr_data.size();
21  ui->zippedBytes->setText(QString::number(compr_data_size));
22  goodPercentage = false;
23  bitsUsed = 8;
24 }
25 
27 {
28  delete ui;
29 }
30 
31 void EncryptDialog::alert(QString text)
32 {
33  QMessageBox t;
34  t.setWindowTitle(tr("Message"));
35  t.setIcon(QMessageBox::Warning);
36  t.setWindowIcon(QIcon(":/mail.png"));
37  t.setText(text);
38  t.exec();
39 }
46 QByteArray EncryptDialog::zip()
47 {
48  // Zip
49  QByteArray c_data = qCompress(data, 9);
50  // Encryption
51  QByteArray hashKey = QCryptographicHash::hash(key.toUtf8(), QCryptographicHash::Sha256);
53 }
58 {
59  // Selet file
60  inputFileName = QFileDialog::getOpenFileName(this, tr("Open File"), "/", tr("Images (*.png *.xpm *.jpg *.jpeg)"));
61  ui->fileLabel->setText(inputFileName);
62  // Open image
63  QImage img(inputFileName);
64  image = img;
65  // Get size
66  size = img.width() * img.height();
67  // UI setup
68  long long int compr_data_size = compr_data.size();
69  ui->zippedBytes->setText(QString::number(compr_data_size));
70  if(inputFileName.isEmpty()) {
71  ui->percentage->setText("");
72  return;
73  }
74  double perc = (compr_data_size + 14) * 100 / (size * 3) * bitsUsed / 8;
75  ui->percentage->setText(QString::number(perc) + "%");
76  goodPercentage = perc < 70;
77 }
83 {
84  if(!goodPercentage) {
85  alert(tr("Your encoding percentage is over 70% which is a bit ambiguous."));
86  success = false;
87  return;
88  }
89  // Final zip
90  key = ui->keyLine->text();
91  compr_data = zip();
92  success = true;
93  close();
94 }
99 {
100  success = false;
101  close();
102 }
108 {
109  bitsUsed = value;
110  ui->bitsUsedLbl->setText(QString::number(value));
111  if(ui->percentage->text().isEmpty())
112  return;
113  double perc = (compr_data.size() + 14) * 100 / (size * 3) * 8 / bitsUsed;
114  ui->percentage->setText(QString::number(perc) + "%");
115 }
bool success
success Flag, if image was successfully selected and data was encrypted.
Definition: encryptdialog.h:46
void on_fileButton_clicked()
EncryptDialog::on_fileButton_clicked Slot to select the image.
static QByteArray Crypt(QAESEncryption::Aes level, QAESEncryption::Mode mode, const QByteArray &rawText, const QByteArray &key, const QByteArray &iv=NULL, QAESEncryption::Padding padding=QAESEncryption::ISO)
Crypt Static encode function.
void on_buttonBox_rejected()
EncryptDialog::on_buttonBox_rejected Slot to reject the encryption.
Definition: aboutpc.h:6
QByteArray data
data Input data
Definition: encryptdialog.h:42
QImage image
image Inputted image
Definition: encryptdialog.h:79
bool goodPercentage
goodPercentage Flag if area of the used data via encryption is less than 70% of the area of the image...
Definition: encryptdialog.h:66
void on_bitsSlider_valueChanged(int value)
EncryptDialog::on_bitsSlider_valueChanged Slot if value of the bits slider is changed.
long long int size
size Size of the image in square pixels
Definition: encryptdialog.h:58
void on_buttonBox_accepted()
EncryptDialog::on_buttonBox_accepted Slot to start the encryption. Successful closing of the app...
The EncryptDialog class Class to get the image and key to store secret info.
Definition: encryptdialog.h:21
int bitsUsed
bitsUsed Bits used per byte of pixel.
Definition: encryptdialog.h:75
QString key
key Key to be used for encryption in EncrytDialog::zip
Definition: encryptdialog.h:62
QByteArray zip()
EncryptDialog::zip Zipping algorithm It copresses the data and then compresses it using qCompress() ...
EncryptDialog(QByteArray _data, QWidget *parent=0)
EncryptDialog::EncryptDialog Constructor of the class. Input data is saved here and some variables ar...
QByteArray compr_data
compr_data Compressed data, aka Output data.
Definition: encryptdialog.h:50
QString inputFileName
inputFileName Filename of the image.
Definition: encryptdialog.h:54