Skip to content

Commit 50e8b5d

Browse files
committed
update
1 parent 0214f80 commit 50e8b5d

File tree

5 files changed

+72
-39
lines changed

5 files changed

+72
-39
lines changed

Steganalysis.pro

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ CONFIG += c++11
88
# In order to do so, uncomment the following line.
99
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
1010

11+
win32-msvc* {
12+
QMAKE_CXXFLAGS += /source-charset:utf-8 /execution-charset:utf-8
13+
}
14+
1115
SOURCES += \
1216
lsb.cpp \
1317
main.cpp \
@@ -36,4 +40,5 @@ RESOURCES += \
3640
DISTFILES += \
3741
logo.rc
3842

39-
RC_FILE += logo.rc
43+
RC_FILE += \
44+
logo.rc

lsb.cpp

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "lsb.h"
1+
#include "lsb.h"
22

33
LSB::LSB()
44
{
@@ -15,30 +15,41 @@ void LSB::LoadImg(const QString & path)
1515
img.load(path);
1616
width = img.width();
1717
height = img.height();
18-
max = (width * height * 3 - 12) / 8;
18+
max = (width * height * 3 - 12) / 4;
1919
}
2020

2121
void LSB::WriteImg(const QString & path)
2222
{
2323
img.save(path);
2424
}
2525

26-
void LSB::CoverPixel()
26+
void LSB::CoverPixel(int TYPE)
2727
{
2828
int len = coded.length();
2929
int index = 0;
30+
int red, green, blue, alpha;
31+
QRgb pixelValue, newPixelValue;
32+
QVector <QString> list;
33+
QString value;
3034
for (int i=0;i<width;i++) {
3135
for (int j=0;j<height;j++) {
32-
QRgb pixelValue = img.pixel(i, j);
33-
int red = qRed(pixelValue);
34-
int green = qGreen(pixelValue);
35-
int blue = qBlue(pixelValue);
36-
QVector <QString> list;
36+
if (index <= len)
37+
{
38+
pixelValue = img.pixel(i, j);
39+
red = qRed(pixelValue);
40+
green = qGreen(pixelValue);
41+
blue = qBlue(pixelValue);
42+
if (TYPE == PNG)
43+
{
44+
alpha = qAlpha(pixelValue);
45+
}
46+
list.clear();
47+
list.shrink_to_fit();
3748
list.append(QString::number(red, 2));
3849
list.append(QString::number(green, 2));
3950
list.append(QString::number(blue, 2));
4051
for (int t=0;t<3;t++) {
41-
QString value = list[t];
52+
value = list[t];
4253
if (index >= len)
4354
{
4455
value[value.length()-1] = '0';
@@ -52,8 +63,14 @@ void LSB::CoverPixel()
5263
red = list[0].toInt(&n, 2);
5364
green = list[1].toInt(&n, 2);
5465
blue = list[2].toInt(&n, 2);
55-
QRgb newPixelValue = qRgb(red, green, blue);
66+
if (TYPE == PNG)
67+
{
68+
newPixelValue = qRgba(red, green, blue, alpha);
69+
} else {
70+
newPixelValue = qRgb(red, green, blue);
71+
}
5672
img.setPixel(i, j, newPixelValue);
73+
}
5774
}
5875
}
5976
}
@@ -63,20 +80,23 @@ QString LSB::SplitPixel()
6380
QString head = "";
6481
int len = 0;
6582
bool flag = false;
66-
QString decoded = "";
83+
QString decoded = "", value;
84+
QRgb pixelValue;
6785
int index = 0;
86+
QVector <QString> list;
6887
for (int i=0;i<width;i++) {
6988
for (int j=0;j<height;j++) {
70-
QRgb pixelValue = img.pixel(i, j);
89+
pixelValue = img.pixel(i, j);
7190
int red = qRed(pixelValue);
7291
int green = qGreen(pixelValue);
7392
int blue = qBlue(pixelValue);
74-
QVector <QString> list;
93+
list.clear();
94+
list.shrink_to_fit();
7595
list.append(QString::number(red, 2));
7696
list.append(QString::number(green, 2));
7797
list.append(QString::number(blue, 2));
7898
for (int t=0;t<3;t++) {
79-
QString value = list[t];
99+
value = list[t];
80100
if (index < 12)
81101
{
82102
head += value[value.length() - 1];
@@ -100,6 +120,7 @@ QString LSB::SplitPixel()
100120
return "";
101121
}
102122

123+
103124
void LSB::SetText(const QString & string)
104125
{
105126
raw = string;

lsb.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#ifndef LSB_H
1+
#ifndef LSB_H
22
#define LSB_H
33

44
#include <iostream>
@@ -8,6 +8,8 @@
88
#include <QVector>
99
#include <QDebug>
1010

11+
enum TYPE {PNG, DEFAULT};
12+
1113
class LSB
1214
{
1315
private:
@@ -31,7 +33,7 @@ class LSB
3133
int GetWidth();
3234
QImage GetImg();
3335
QString GetDecoded();
34-
void CoverPixel();
36+
void CoverPixel(int TYPE=DEFAULT);
3537
QString SplitPixel();
3638
void Encode();
3739
void Decode();

mainwindow.cpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,27 +62,27 @@ void MainWindow::Warning(const QString & string)
6262
messageBox.setWindowTitle("Warning");
6363
messageBox.setText(string);
6464
messageBox.setIcon(QMessageBox::Information);
65-
messageBox.addButton("confirm", QMessageBox::AcceptRole);
65+
messageBox.addButton("确认", QMessageBox::AcceptRole);
6666
messageBox.exec();
6767
}
6868

6969

7070
void MainWindow::on_choose_clicked()
7171
{
72-
Path = QFileDialog::getOpenFileName(this, "Choose a image file", "/", "(*.png *.jpg *.jpeg *.bmp)");
72+
Path = QFileDialog::getOpenFileName(this, QString("选择一张图片"), "/", "(*.png *.bmp)");
7373
if (Path.isEmpty())
7474
{
7575
qDebug() << "Error";
7676
}
7777
else
7878
{
79+
Reset();
7980
QFileInfo fileInfo(Path);
8081
path = fileInfo.path();
8182
fileName = fileInfo.fileName();
8283
suffix = fileInfo.completeSuffix();
8384
ui->rawfile->setText(fileName);
8485
ui->button->setEnabled(true);
85-
8686
lsb.LoadImg(Path);
8787
max = QString::number(lsb.GetMax());
8888
if (mode == ENC)
@@ -98,7 +98,8 @@ void MainWindow::on_choose_clicked()
9898

9999
void MainWindow::on_save_clicked()
100100
{
101-
lsb.WriteImg(path + "/" + ui->name->text());
101+
QString new_path = path + "/" + ui->name->text();
102+
lsb.WriteImg(new_path);
102103
}
103104

104105

@@ -110,15 +111,20 @@ void MainWindow::on_button_clicked()
110111
QString text = ui->text->toPlainText();
111112
if (text == "")
112113
{
113-
Warning("At least one word");
114+
Warning("至少一个字符");
114115
} else {
115116
if (text.length() >= max.toInt())
116117
{
117-
Warning("Words over the threshold");
118+
Warning("字符过多");
118119
}
119120
lsb.SetText(text);
120121
lsb.Encode();
121-
lsb.CoverPixel();
122+
if (suffix == "png")
123+
{
124+
lsb.CoverPixel(PNG);
125+
} else {
126+
lsb.CoverPixel(DEFAULT);
127+
}
122128
ImgShow(ui->encrypt, lsb.GetImg());
123129
ui->name->setText(fileName.remove(fileName.length() - suffix.length() - 1, suffix.length() + 1) + "_encrypt." + suffix);
124130
ui->name->setReadOnly(true);
@@ -135,7 +141,6 @@ void MainWindow::on_button_clicked()
135141
break;
136142
}
137143
}
138-
139144
}
140145

141146

@@ -145,8 +150,8 @@ void MainWindow::on_choose1_stateChanged(int arg1)
145150
{
146151
mode = ENC;
147152
on_clear_clicked();
148-
ui->num->setText("text to be encrypted");
149-
ui->button->setText("encrypt");
153+
ui->num->setText("待加密密文");
154+
ui->button->setText("加密");
150155
ui->choose2->setChecked(false);
151156
Reset();
152157
}
@@ -159,8 +164,8 @@ void MainWindow::on_choose2_stateChanged(int arg1)
159164
{
160165
mode = DEC;
161166
on_clear_clicked();
162-
ui->num->setText("text decrypted");
163-
ui->button->setText("decrypt");
167+
ui->num->setText("解密明文");
168+
ui->button->setText("解密");
164169
ui->choose1->setChecked(false);
165170
Reset();
166171
}

mainwindow.ui

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@
5757
<rect>
5858
<x>180</x>
5959
<y>20</y>
60-
<width>72</width>
61-
<height>15</height>
60+
<width>51</width>
61+
<height>16</height>
6262
</rect>
6363
</property>
6464
<property name="text">
65-
<string>raw</string>
65+
<string>原图片</string>
6666
</property>
6767
</widget>
6868
<widget class="QTextEdit" name="text">
@@ -120,7 +120,7 @@
120120
</rect>
121121
</property>
122122
<property name="text">
123-
<string>save</string>
123+
<string>保存</string>
124124
</property>
125125
</widget>
126126
<widget class="QPushButton" name="button">
@@ -133,7 +133,7 @@
133133
</rect>
134134
</property>
135135
<property name="text">
136-
<string>encrypt</string>
136+
<string>加密</string>
137137
</property>
138138
</widget>
139139
<widget class="QLineEdit" name="name">
@@ -159,7 +159,7 @@
159159
</rect>
160160
</property>
161161
<property name="text">
162-
<string>encrypt</string>
162+
<string>加密</string>
163163
</property>
164164
</widget>
165165
<widget class="QCheckBox" name="choose2">
@@ -172,7 +172,7 @@
172172
</rect>
173173
</property>
174174
<property name="text">
175-
<string>decrypt</string>
175+
<string>解密</string>
176176
</property>
177177
</widget>
178178
<widget class="QPushButton" name="clear">
@@ -185,7 +185,7 @@
185185
</rect>
186186
</property>
187187
<property name="text">
188-
<string>clr</string>
188+
<string>清除</string>
189189
</property>
190190
</widget>
191191
<widget class="QPushButton" name="copy">
@@ -198,7 +198,7 @@
198198
</rect>
199199
</property>
200200
<property name="text">
201-
<string>copy</string>
201+
<string>复制</string>
202202
</property>
203203
</widget>
204204
<widget class="QLabel" name="num">
@@ -211,7 +211,7 @@
211211
</rect>
212212
</property>
213213
<property name="text">
214-
<string>text to be encrypted</string>
214+
<string>待加密密文</string>
215215
</property>
216216
</widget>
217217
</widget>

0 commit comments

Comments
 (0)