24 void ViewPC::on_encryptMode_clicked()
30 void ViewPC::on_decryptMode_clicked()
42 inputFileName = QFileDialog::getOpenFileName(
this, tr(
"Select file"),
"/untitled.txt", tr(
"Text files (*.txt);;All Files (*)"));
44 inputFileName = QFileDialog::getOpenFileName(
this, tr(
"Select file"),
"/untitled.png", tr(
"PNG files (*.png);;All Files (*)"));
46 ui->fileLabel->setText(inputFileName.isEmpty() ? tr(
"File not chosen") : inputFileName);
65 QString text = ui->text->toPlainText();
68 if(inputFileName.isEmpty()) {
69 alert(
"no_input_file",
true);
73 QFile file(inputFileName);
74 if (!file.open(QIODevice::ReadOnly))
76 alert(
"open_file_fail",
true);
80 auto size = file.size();
81 if(size > qPow(2, 24)) {
82 alert(
"muchdata",
true);
86 data = file.readAll();
101 QByteArray hash = QCryptographicHash::hash(data, QCryptographicHash::Sha256);
102 encr_data = hash + encr_data;
109 if(inputFileName.isEmpty()) {
110 alert(
"no_input_file",
true);
116 QImage * res_image =
new QImage(inputFileName);
117 emit
decrypt(res_image, key, 0);
133 box.setIcon(QMessageBox::Warning);
135 box.setIcon(QMessageBox::Information);
136 box.setText(message);
137 box.setWindowIcon(QIcon(
":/icons/mail.png"));
138 box.setWindowTitle(tr(
"Message"));
149 QString outputFileName = QFileDialog::getSaveFileName(
this, tr(
"Save File"),
151 tr(
"Text(*.txt);;All files (*)"));
152 QFile writeFile(outputFileName);
153 if (!writeFile.open(QIODevice::WriteOnly))
155 alert(
"save_file_fail",
true);
158 writeFile.write(Edata);
160 alert(
"decryption_completed");
170 QString outputFileName = QFileDialog::getSaveFileName(
this, tr(
"Save Image"),
172 tr(
"Images(*.png)"));
173 if(!image->save(outputFileName)) {
174 alert(
"save_file_fail",
true);
177 alert(
"encryption_completed");
189 dialog =
new QProgressDialog(tr(
"Cryption in progress."), tr(
"Cancel"), 0, 100);
192 dialog->setWindowTitle(tr(
"Processing"));
193 dialog->setWindowIcon(QIcon(
":/icons/loading.png"));
226 ui->text->setText(
"");
227 ui->text->setEnabled(encr);
229 ui->startButton->setText(encr ? tr(
"Continue configuration") : tr(
"Start decryption"));
230 ui->enLabel1->setText(encr ? tr(
"Type in the text for encryption:") : tr(
"Text input isn't supported in decryption mode"));
231 ui->enLabel1->setEnabled(encr);
232 ui->enLabel2->setText(encr ? tr(
"Or use the file dialog to choose a file:") : tr(
"Choose a file for decryption:"));
233 ui->comboBox->setEnabled(encr);
242 versionString = version;
251 QString text = QInputDialog::getText(
this, tr(
"Dialog"),
252 tr(
"Enter the keyphrase:"), QLineEdit::Password,
254 if(text.isEmpty() && ok) {
255 alert(
"no_key",
true);
258 return ok ? text : QString();
261 QByteArray ViewPC::bytes(
long long n)
263 return QByteArray::fromHex(QByteArray::number(n, 16));
280 QUrl docLink(
"https://waleko.github.io/PictureCrypt/docs");
281 QDesktopServices::openUrl(docLink);
289 errorsDict[
"muchdata"] = tr(
"Data size is too big (must be less than 15MB)!");
290 errorsDict[
"nullimage"] = tr(
"Invalid / null image!");
291 errorsDict[
"bigimage"] = tr(
"Image is too big!");
292 errorsDict[
"bitsWrong"] = tr(
"bitsUsed parameter is wrong!");
294 errorsDict[
"big_key"] = tr(
"Given key is too big!");
295 errorsDict[
"undefined_mode"] = tr(
"Undefined mode is only available when decrypting!");
296 errorsDict[
"wrongmode"] = tr(
"Given mode isn't available!");
297 errorsDict[
"inject-v1.4"] = tr(
"ModelPC::inject() isn't available with v1.4 (advanced) mode");
298 errorsDict[
"all_modes_fail"] = tr(
"Given image isn't encrypted by this app (all modes have failed) or is damaged!");
299 errorsDict[
"nojphs"] = tr(
"JPHS is not installed!");
300 errorsDict[
"bitsBufferFail"] = tr(
"bitsBufferFail (holy crap, contact me or submit a bug)");
301 errorsDict[
"point_visited_twice"] = tr(
"One point visited twice (holy crap, contact me or submit a bug)");
302 errorsDict[
"bigdata"] = tr(
"Too much data for this image!");
303 errorsDict[
"veriffail"] = tr(
"Given image isn't encrypted with this mode or is damaged!");
304 errorsDict[
"noreaddata"] = tr(
"No data to read from image!");
305 errorsDict[
"new_version"] = tr(
"Version of the image is newer than yours (update!!!)");
306 errorsDict[
"old_version"] = tr(
"Version of the image is older than yours");
307 errorsDict[
"no_input_file"] = tr(
"No file given!");
308 errorsDict[
"open_file_fail"] = tr(
"Cannot open file!");
309 errorsDict[
"save_file_fail"] = tr(
"Cannot save file!");
310 errorsDict[
"decryption_completed"] = tr(
"Decryption completed!");
311 errorsDict[
"encryption_completed"] = tr(
"Encryption completed!");
314 void ViewPC::on_actionJPHS_path_triggered()
316 QString dir = QFileDialog::getExistingDirectory(
this, tr(
"Open JPHS folder"),
318 QFileDialog::ShowDirsOnly
319 | QFileDialog::DontResolveSymlinks);
323 void ViewPC::on_comboBox_currentIndexChanged(
int index)
325 selectedMode = index + 1;
328 void ViewPC::on_text_textChanged()
330 ui->fileButton->setEnabled(ui->text->toPlainText().isEmpty());
bool success
success Flag, if image was successfully selected and data was encrypted.
bool progressDialogClosed
progressDialogClosed Flag, if dialog is closed.
QImage image
image Inputted image
void setJPHSDir(QString dir)
setJPHSPath Sets the default JPHS directory
void abortCircuit()
ViewPC::abortCircuit Slot to close ProgressDialog (ViewPC::dialog)
The ViewPC class View layer of the app. Controls EncryptDialog and ProgressDialog.
ViewPC(QWidget *parent=nullptr)
QProgressDialog * dialog
dialog ProgressDialog used.
~ViewPC()
ViewPC::~ViewPC Simple destructor for this layer.
The EncryptDialog class Class to get the image and key to store secret info.
void decrypt(QImage *_image, QString key, int mode)
decrypt Signal calling ModelPC::decrypt
void on_startButton_clicked()
ViewPC::on_startButton_clicked Slot to be called, when Start Button is pressed.
void setEncryptMode(bool encr)
ViewPC::setEncryptMode Set the encrpt mode (ViewPC::isEncrypt)
void on_actionAbout_triggered()
ViewPC::on_actionAbout_triggered Opens about page.
void alert(QString message, bool isWarning=false)
ViewPC::alert Slot to create QMessageBox with message.
void abortModel()
abortModel Signal calling to stop ModelPC::circuit
int bitsUsed
bitsUsed Bits used per byte of pixel.
QMap< QString, QString > errorsDict
errorsDict QMap - Errors dictionary
void setProgress(int val)
ViewPC::setProgress Slot to set the value of the ProgressDialog (ViewPC::dialog). ...
void on_fileButton_clicked()
ViewPC::on_fileButton_clicked Slot to be called, when according button is pressed.
void saveData(QByteArray Edata)
ViewPC::saveData Slot to be called to save data using QFileDialog.
QString key
key Key to be used for encryption in EncrytDialog::zip
void encrypt(QByteArray data, QImage *image, int mode, QString key, int bitsUsed)
encrypt Signal calling ModelPC::encrypt
void setVersion(QString version)
AboutPC::setVersion Function to set the version display.
QString requestKey()
ViewPC::requestKey Request keyphrase from user using InputDialog.
void saveImage(QImage *image)
ViewPC::saveImage Slot to be called to save image using QFileDialog.
QByteArray compr_data
compr_data Compressed data, aka Output data.
void setVersion(QString version)
ViewPC::setVersion Set the version of the app from ControllerPC.
The AboutPC class The About Page dialog.
void setupErrorsDict()
ViewPC::setupErrorsDict Setups errorsDict from strings.xml.
void on_actionHelp_triggered()
ViewPC::on_actionHelp_triggered Opens online documentation.