-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKTStegRich.html
More file actions
246 lines (233 loc) · 9.58 KB
/
KTStegRich.html
File metadata and controls
246 lines (233 loc) · 9.58 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Kingry Tools: Steganography (Rich Text and Images Version)</title>
<style>
body { font-family: Arial, sans-serif; margin: 20px; background: #f0f0f0; }
h1 { text-align: center; }
.container { display: flex; flex-wrap: wrap; justify-content: center; gap: 40px; }
.section { background: #fff; padding: 20px; border-radius: 8px; box-shadow: 0 0 10px rgba(0,0,0,0.1); width: 360px; }
.editor {
width: 100%;
min-height: 200px;
max-height: 60vh; /* Prevent box from growing beyond viewport, enable scrolling */
border: 1px solid #ccc;
border-radius: 4px;
padding: 8px;
margin-top: 10px;
overflow-y: auto;
background: #fff;
}
.editor:empty:before {
content: attr(data-placeholder);
color: #888;
}
input, button { width: 100%; padding: 8px; margin-top: 8px; }
canvas { display: none; }
#byteInfo { margin-top: 5px; font-size: 14px; }
img.preview { display: none; margin: 10px auto; max-width: 100%; border-radius: 4px; }
.drop-zone {
border: 2px dashed #888;
border-radius: 6px;
padding: 12px;
text-align: center;
color: #555;
margin-top: 10px;
cursor: pointer;
transition: background-color 0.2s, border-color 0.2s;
}
.drop-zone.dragover {
background-color: #cce5ff;
border-color: #007bff;
}
</style>
</head>
<body>
<h1>Kingry Tools: Steganography (Rich Text and Images Version)</h1>
<div class="container">
<div class="section">
<h2>Hide HTML</h2>
<div class="drop-zone" id="dropZone">Drop cover image here or click to select</div>
<input type="file" id="coverInput" accept="image/*" onchange="handleCoverImage()" style="display:none">
<img id="sourcePreview" class="preview">
<div id="hideEditor" class="editor" contenteditable="true" data-placeholder="Paste text or images here..."></div>
<div id="byteInfo">Bytes: 0</div>
<input type="password" id="hidePassword" placeholder="Password (optional)">
<button id="hideButton" onclick="hideText()" disabled>Hide & Download</button>
</div>
<div class="section">
<h2>Extract HTML</h2>
<input type="file" id="stegoInput" accept="image/*" onchange="handleStegoImage()">
<img id="stegoPreview" class="preview">
<input type="password" id="extractPassword" placeholder="Password (if used)">
<button id="extractButton" onclick="extractText()" disabled>Extract & View</button>
<div id="extractEditor" class="editor" contenteditable="false"></div>
</div>
</div>
<canvas id="canvas"></canvas>
<script src="https://cdn.jsdelivr.net/npm/lz-string@1.4.4/libs/lz-string.min.js"></script>
<script>
let maxBytes = 0;
const hideEditor = document.getElementById('hideEditor');
const extractEditor = document.getElementById('extractEditor');
// Handle paste of images and text
hideEditor.addEventListener('paste', e => {
const items = (e.clipboardData || e.originalEvent.clipboardData).items;
for (let item of items) {
if (item.kind === 'file' && item.type.startsWith('image/')) {
e.preventDefault();
const blob = item.getAsFile();
const reader = new FileReader();
reader.onload = ev => {
document.execCommand('insertImage', false, ev.target.result);
updateByteInfo();
};
reader.readAsDataURL(blob);
}
}
});
// Track input for byte count
hideEditor.addEventListener('input', updateByteInfo);
// Cover image selection
const dropZone = document.getElementById('dropZone');
dropZone.addEventListener('click', () => document.getElementById('coverInput').click());
dropZone.addEventListener('dragover', e => { e.preventDefault(); dropZone.classList.add('dragover'); });
dropZone.addEventListener('dragleave', e => { e.preventDefault(); dropZone.classList.remove('dragover'); });
dropZone.addEventListener('drop', e => { e.preventDefault(); dropZone.classList.remove('dragover'); const file = e.dataTransfer.files[0]; if (file && file.type.startsWith('image/')) { document.getElementById('coverInput').files = e.dataTransfer.files; handleCoverImage(); }});
function handleCoverImage() {
const file = document.getElementById('coverInput').files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = e => {
const img = new Image();
img.onload = () => {
maxBytes = Math.floor((img.width * img.height * 3) / 8) - 4;
maxBytes = Math.floor(maxBytes * 3 / 4);
updateByteInfo();
};
img.src = e.target.result;
const preview = document.getElementById('sourcePreview');
preview.src = e.target.result;
preview.style.display = 'block';
};
reader.readAsDataURL(file);
}
function handleStegoImage() {
const file = document.getElementById('stegoInput').files[0];
const preview = document.getElementById('stegoPreview');
if (!file) {
preview.style.display = 'none';
document.getElementById('extractButton').disabled = true;
return;
}
const reader = new FileReader();
reader.onload = e => {
preview.src = e.target.result;
preview.style.display = 'block';
document.getElementById('extractButton').disabled = false;
};
reader.readAsDataURL(file);
}
function updateByteInfo() {
const raw = hideEditor.innerHTML;
const comp = LZString.compressToUTF16(raw);
const used = new TextEncoder().encode(comp).length;
const info = document.getElementById('byteInfo');
info.textContent = `Bytes: ${used} / ${maxBytes}`;
info.style.color = used > maxBytes ? 'red' : 'black';
document.getElementById('hideButton').disabled = !(used > 0 && used <= maxBytes && document.getElementById('coverInput').files.length > 0);
}
// Encryption helper
function xorEncryptDecrypt(data, key) {
const keyBytes = new TextEncoder().encode(key);
return data.map((b, i) => b ^ keyBytes[i % keyBytes.length]);
}
function intToBinArray(n, bits) { return Array.from({length: bits}, (_, i) => (n >> (bits - i - 1)) & 1); }
function binArrayToInt(arr) { return arr.reduce((acc, bit) => (acc << 1) | bit, 0); }
// Hide and embed
function hideText() {
const file = document.getElementById('coverInput').files[0];
const raw = hideEditor.innerHTML;
const pwd = document.getElementById('hidePassword').value;
if (!file || !raw) return alert('Select cover image & add content.');
let msg = LZString.compressToUTF16(raw);
const reader = new FileReader(); reader.onload = e => {
const img = new Image(); img.onload = () => {
const canvas = document.getElementById('canvas');
canvas.width = img.width; canvas.height = img.height;
const ctx = canvas.getContext('2d'); ctx.drawImage(img, 0, 0);
let bytes = new TextEncoder().encode(msg);
if (pwd) {
const enc = xorEncryptDecrypt(bytes, pwd);
let binStr = '';
enc.forEach(b => binStr += String.fromCharCode(b));
bytes = new TextEncoder().encode(btoa(binStr));
}
const pixels = ctx.getImageData(0,0, img.width, img.height).data;
const bits = [...intToBinArray(bytes.length, 32)];
bytes.forEach(b => bits.push(...intToBinArray(b, 8)));
if (bits.length > pixels.length / 4 * 3) return alert('Payload too large.');
let idx = 0;
for (let i = 0; i < pixels.length; i += 4) {
if (idx < bits.length) pixels[i] = (pixels[i] & ~1) | bits[idx++];
if (idx < bits.length) pixels[i+1] = (pixels[i+1] & ~1) | bits[idx++];
if (idx < bits.length) pixels[i+2] = (pixels[i+2] & ~1) | bits[idx++];
}
ctx.putImageData(new ImageData(pixels, img.width, img.height), 0, 0);
setTimeout(() => {
const a = document.createElement('a');
a.download = 'stego_image.png';
a.href = canvas.toDataURL();
a.click();
}, 50);
};
img.src = e.target.result;
};
reader.readAsDataURL(file);
}
// Extract and display
function extractText() {
const file = document.getElementById('stegoInput').files[0];
const pwd = document.getElementById('extractPassword').value;
if (!file) return alert('Select a stego image.');
const reader = new FileReader(); reader.onload = e => {
const img = new Image(); img.onload = () => {
const canvas = document.getElementById('canvas');
canvas.width = img.width; canvas.height = img.height;
const ctx = canvas.getContext('2d'); ctx.drawImage(img, 0, 0);
const data = ctx.getImageData(0,0, img.width, img.height).data;
const bits = [];
for (let i = 0; i < data.length; i += 4) {
bits.push(data[i] & 1, data[i+1] & 1, data[i+2] & 1);
}
const len = binArrayToInt(bits.slice(0, 32));
const chunk = bits.slice(32, 32 + len * 8);
const bytes = [];
for (let i = 0; i < chunk.length; i += 8) {
bytes.push(binArrayToInt(chunk.slice(i, i+8)));
}
let extracted = new Uint8Array(bytes);
try {
let str;
if (pwd) {
const binStr = atob(new TextDecoder().decode(extracted));
const rawBytes = new Uint8Array([...binStr].map(ch => ch.charCodeAt(0)));
str = new TextDecoder().decode(xorEncryptDecrypt(rawBytes, pwd));
} else {
str = new TextDecoder().decode(extracted);
}
const html = LZString.decompressFromUTF16(str);
extractEditor.innerHTML = html;
} catch (err) {
alert('Failed to decode. Wrong password or corrupted image.');
}
};
img.src = e.target.result;
};
reader.readAsDataURL(file);
}
</script>
</body>
</html>