mirror of
https://github.com/zs-yg/kortapp-z.git
synced 2025-12-07 00:20:43 +08:00
废弃的零宽字符隐藏器
欸
This commit is contained in:
16
others/C++/stegano_project/src/CommonDefsImpl.cpp
Normal file
16
others/C++/stegano_project/src/CommonDefsImpl.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include "CommonDefs.hpp"
|
||||
#include <codecvt>
|
||||
#include <locale>
|
||||
#include <string>
|
||||
|
||||
namespace CommonDefs {
|
||||
std::wstring utf8_to_wstring(const std::string& str) {
|
||||
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
|
||||
return converter.from_bytes(str);
|
||||
}
|
||||
|
||||
std::string wstring_to_utf8(const std::wstring& wstr) {
|
||||
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
|
||||
return converter.to_bytes(wstr);
|
||||
}
|
||||
}
|
||||
92
others/C++/stegano_project/src/GUI.cpp
Normal file
92
others/C++/stegano_project/src/GUI.cpp
Normal file
@@ -0,0 +1,92 @@
|
||||
// src/GUI.cpp (改进布局)
|
||||
#include "GUI.hpp"
|
||||
#include "Steganography.hpp"
|
||||
#include "CommonDefs.hpp"
|
||||
#include <FL/fl_ask.H>
|
||||
#include <string>
|
||||
|
||||
const int PAD = 15;
|
||||
const int WIDTH = 600;
|
||||
const int HEIGHT = 600;
|
||||
const int BTN_WIDTH = 120;
|
||||
const int BTN_HEIGHT = 30;
|
||||
|
||||
MainWindow::MainWindow(int width, int height, const char* title)
|
||||
: Fl_Window(width, height, title) {
|
||||
|
||||
begin();
|
||||
|
||||
// 创建标签页
|
||||
tabs = new Fl_Tabs(0, 0, WIDTH, HEIGHT);
|
||||
tabs->selection_color(FL_BLUE);
|
||||
|
||||
// 嵌入标签页
|
||||
embedGroup = new Fl_Group(0, 30, WIDTH, HEIGHT - 30, "Embed");
|
||||
embedGroup->color(FL_WHITE);
|
||||
embedGroup->selection_color(FL_WHITE);
|
||||
|
||||
int y = PAD + 30;
|
||||
|
||||
coverInput = new Fl_Multiline_Input(PAD, y, WIDTH - 2 * PAD, 80, "Cover Text:");
|
||||
coverInput->align(FL_ALIGN_TOP_LEFT);
|
||||
y += 90;
|
||||
|
||||
messageInput = new Fl_Multiline_Input(PAD, y, WIDTH - 2 * PAD, 80, "Secret Message:");
|
||||
messageInput->align(FL_ALIGN_TOP_LEFT);
|
||||
y += 90;
|
||||
|
||||
encodeBtn = new Fl_Button(WIDTH - BTN_WIDTH - PAD, y, BTN_WIDTH, BTN_HEIGHT, "Embed");
|
||||
encodeBtn->callback(encode_cb, this);
|
||||
encodeBtn->color(FL_GREEN);
|
||||
y += 40;
|
||||
|
||||
resultOutput = new Fl_Multiline_Output(PAD, y, WIDTH - 2 * PAD, 80, "Result (with hidden text):");
|
||||
resultOutput->align(FL_ALIGN_TOP_LEFT);
|
||||
resultOutput->textsize(12);
|
||||
resultOutput->readonly(1);
|
||||
y += 90;
|
||||
|
||||
// 状态标签
|
||||
Fl_Box* statusBox = new Fl_Box(PAD, y, WIDTH - 2 * PAD, 30, "");
|
||||
statusBox->label("Status: Ready");
|
||||
|
||||
embedGroup->end();
|
||||
|
||||
// 提取标签页
|
||||
extractGroup = new Fl_Group(0, 30, WIDTH, HEIGHT - 30, "Extract");
|
||||
extractGroup->color(FL_WHITE);
|
||||
extractGroup->selection_color(FL_WHITE);
|
||||
|
||||
y = PAD + 30;
|
||||
|
||||
extractInput = new Fl_Multiline_Input(PAD, y, WIDTH - 2 * PAD, 80, "Text to decode:");
|
||||
extractInput->align(FL_ALIGN_TOP_LEFT);
|
||||
y += 90;
|
||||
|
||||
decodeBtn = new Fl_Button(WIDTH - BTN_WIDTH - PAD, y, BTN_WIDTH, BTN_HEIGHT, "Extract");
|
||||
decodeBtn->callback(decode_cb, this);
|
||||
decodeBtn->color(FL_BLUE);
|
||||
y += 40;
|
||||
|
||||
extractedOutput = new Fl_Multiline_Output(PAD, y, WIDTH - 2 * PAD, 80, "Extracted Message:");
|
||||
extractedOutput->align(FL_ALIGN_TOP_LEFT);
|
||||
extractedOutput->textsize(12);
|
||||
extractedOutput->readonly(1);
|
||||
y += 90;
|
||||
|
||||
// 状态标签
|
||||
Fl_Box* extractStatus = new Fl_Box(PAD, y, WIDTH - 2 * PAD, 30, "");
|
||||
extractStatus->label("Status: Ready");
|
||||
|
||||
extractGroup->end();
|
||||
tabs->end();
|
||||
|
||||
end();
|
||||
|
||||
// 设置默认选择的标签
|
||||
tabs->value(embedGroup);
|
||||
|
||||
// 窗口美化
|
||||
color(FL_WHITE);
|
||||
resizable(this);
|
||||
}
|
||||
25
others/C++/stegano_project/src/Steganography.cpp
Normal file
25
others/C++/stegano_project/src/Steganography.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include "Steganography.hpp"
|
||||
#include "CommonDefs.hpp"
|
||||
#include <stdexcept>
|
||||
|
||||
std::wstring Steganography::embed(const std::wstring& cover_text, const std::string& message) {
|
||||
std::wstring encoded = ZeroWidthEncoder::encode(message);
|
||||
return cover_text + CommonDefs::ZERO_WIDTH_JOINER + encoded;
|
||||
}
|
||||
|
||||
std::string Steganography::extract(const std::wstring& stego_text) {
|
||||
// 查找分隔符
|
||||
size_t pos = stego_text.find(CommonDefs::ZERO_WIDTH_JOINER);
|
||||
if (pos == std::wstring::npos) {
|
||||
throw std::runtime_error("No hidden message detected");
|
||||
}
|
||||
|
||||
std::wstring encoded = stego_text.substr(pos + 1);
|
||||
return ZeroWidthEncoder::decode(encoded);
|
||||
}
|
||||
|
||||
bool Steganography::is_zero_width(wchar_t c) {
|
||||
return c == CommonDefs::ZERO_WIDTH_SPACE ||
|
||||
c == CommonDefs::ZERO_WIDTH_NON_JOINER ||
|
||||
c == CommonDefs::ZERO_WIDTH_JOINER;
|
||||
}
|
||||
41
others/C++/stegano_project/src/ZeroWidthEncoder.cpp
Normal file
41
others/C++/stegano_project/src/ZeroWidthEncoder.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
#include "ZeroWidthEncoder.hpp"
|
||||
#include "CommonDefs.hpp"
|
||||
#include <bitset>
|
||||
|
||||
std::wstring ZeroWidthEncoder::encode(const std::string& message) {
|
||||
std::wstring result;
|
||||
for (char c : message) {
|
||||
result += char_to_zero_width(c);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string ZeroWidthEncoder::decode(const std::wstring& encoded) {
|
||||
std::string result;
|
||||
for (size_t i = 0; i < encoded.size(); i += 8) {
|
||||
if (i + 8 > encoded.size()) break;
|
||||
result += zero_width_to_char(encoded.substr(i, 8));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::wstring ZeroWidthEncoder::char_to_zero_width(char c) {
|
||||
std::bitset<8> bits(c);
|
||||
std::wstring seq;
|
||||
for (int i = 7; i >= 0; --i) {
|
||||
seq += bits.test(i) ?
|
||||
CommonDefs::ZERO_WIDTH_NON_JOINER :
|
||||
CommonDefs::ZERO_WIDTH_SPACE;
|
||||
}
|
||||
return seq;
|
||||
}
|
||||
|
||||
char ZeroWidthEncoder::zero_width_to_char(const std::wstring& sequence) {
|
||||
if (sequence.size() != 8) return 0;
|
||||
|
||||
std::bitset<8> bits;
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
bits.set(7 - i, sequence[i] == CommonDefs::ZERO_WIDTH_NON_JOINER);
|
||||
}
|
||||
return static_cast<char>(bits.to_ulong());
|
||||
}
|
||||
13
others/C++/stegano_project/src/main.cpp
Normal file
13
others/C++/stegano_project/src/main.cpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#include "GUI.hpp"
|
||||
#include <FL/Fl.H>
|
||||
#include <Windows.h>
|
||||
|
||||
int main() {
|
||||
// 确保控制台使用UTF-8编码
|
||||
SetConsoleOutputCP(CP_UTF8);
|
||||
|
||||
MainWindow win(800, 600, "Zero-Width Steganography");
|
||||
win.show();
|
||||
|
||||
return Fl::run();
|
||||
}
|
||||
Reference in New Issue
Block a user