-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimagedecryption.cpp
More file actions
52 lines (49 loc) · 1.77 KB
/
imagedecryption.cpp
File metadata and controls
52 lines (49 loc) · 1.77 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
#include "imagedecryption.h"
#include "cryptionwindow.h"
#include <QImage>
#include <QColor>
#include <QFile>
#include "math.h"
#include <QDebug>
ImageDecryption::ImageDecryption(QObject *parent) :
QThread(parent)
{
}
void ImageDecryption::initSettings(QImage* fileRead, QFile* fileSave) {
this->fileRead = fileRead;
this->fileSave = fileSave;
}
void ImageDecryption::run() {
CryptionWindow::log.writeLine("Starting Decryption...");
if(!fileSave->open(QIODevice::WriteOnly))
return;
uchar buffer[4];
CryptionWindow::log.writeLine("Now parsing image...");
quint64 fileSize = fileRead->pixel(0, 0);
bool usesFourthBit = fileRead->pixel(1, 0) & 0xFF;
CryptionWindow::log.writeLine(QString("The image shows the encrypted file having %1 bytes and %2.").arg(fileSize).arg(usesFourthBit ? "has alpha" : "does not have alpha"));
quint64 i = 0;
int actuallyUsed = 0;
for(int y = 0; y < fileRead->height(); y++) {
for(int x = 0; x < fileRead->width(); x++) {
if(y == 0)
if(x < 2)
continue; //Skip the first 2 pixels of data, as it's used for the 'header'.
QRgb rgb = fileRead->pixel(x, y);
buffer[0] = qRed(rgb); if(i++ >= fileSize) goto fin; else actuallyUsed++;
buffer[1] = qGreen(rgb); if(i++ >= fileSize) goto fin; else actuallyUsed++;
buffer[2] = qBlue(rgb); if(i++ >= fileSize) goto fin; else actuallyUsed++;
if(usesFourthBit) {
buffer[3] = qAlpha(rgb); if(i++ >= fileSize) goto fin; else actuallyUsed++;
}
fin:
fileSave->write((char*)buffer, actuallyUsed);
actuallyUsed = 0;
}
}
CryptionWindow::log.writeLine("Finished Decrypting.");
fileRead = new QImage();
fileSave->flush();
fileSave->close();
fileSave->deleteLater();
}