-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
202 lines (192 loc) · 8.55 KB
/
index.html
File metadata and controls
202 lines (192 loc) · 8.55 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
<!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 Paste)</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;
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%; cursor: pointer; }
.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;
}
.drop-zone.dragover { background-color: #cce5ff; border-color: #007bff; }
</style>
</head>
<body>
<h1>Kingry Tools: Steganography (Rich Paste)</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/*" style="display:none">
<img id="sourcePreview" class="preview">
<div id="hideEditor" class="editor" contenteditable="true" data-placeholder="Paste rich content 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 Text</button>
<div id="resultContainer" style="text-align:center;">
<h3>Result Image</h3>
<img id="resultImage" class="preview">
</div>
</div>
<div class="section">
<h2>Extract HTML</h2>
<input type="file" id="stegoInput" accept="image/*">
<img id="stegoPreview" class="preview">
<input type="password" id="extractPassword" placeholder="Password (if used)">
<button id="extractButton" onclick="extractText()" disabled>Extract Text</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');
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);
reader.readAsDataURL(blob);
}
}
setTimeout(updateByteInfo, 50);
});
hideEditor.addEventListener('input', updateByteInfo);
const dropZone = document.getElementById('dropZone');
dropZone.addEventListener('click', () => 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');
coverInput.files = e.dataTransfer.files;
handleCoverImage();
});
const coverInput = document.getElementById('coverInput');
coverInput.addEventListener('change', handleCoverImage);
function handleCoverImage() {
const file = 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)*3/4;
updateByteInfo();
};
img.src = e.target.result;
sourcePreview.src = e.target.result;
sourcePreview.style.display = 'block';
};
reader.readAsDataURL(file);
}
const stegoInput = document.getElementById('stegoInput');
stegoInput.addEventListener('change', handleStegoImage);
function handleStegoImage() {
const file = stegoInput.files[0];
const preview = document.getElementById('stegoPreview');
if (!file) { preview.style.display='none'; extractButton.disabled=true; return; }
const reader = new FileReader();
reader.onload = e => {
preview.src = e.target.result;
preview.style.display = 'block';
extractButton.disabled = false;
};
reader.readAsDataURL(file);
}
function updateByteInfo() {
const raw = hideEditor.innerHTML;
const used = new TextEncoder().encode(LZString.compressToUTF16(raw)).length;
byteInfo.textContent=`Bytes: ${used} / ${maxBytes}`;
byteInfo.style.color = used>maxBytes?'red':'black';
hideButton.disabled = !(used>0 && used<=maxBytes && coverInput.files.length);
}
function xorEncryptDecrypt(data,key){const k=new TextEncoder().encode(key);return data.map((b,i)=>b^k[i%k.length]);}
function intToBinArray(n,bits){return Array.from({length:bits},(_,i)=>(n>>(bits-i-1))&1);}
function binArrayToInt(arr){return arr.reduce((acc,b)=>acc<<1|b,0);}
function hideText(){
const file=coverInput.files[0]; const raw=hideEditor.innerHTML; const pwd=hidePassword.value;
if(!file||!raw) return alert('Select cover image & add content.');
const 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.');
const imgData = ctx.getImageData(0, 0, img.width, img.height);
const p = imgData.data;
let idx = 0;
for (let i = 0; i < p.length && idx < bits.length; i += 4) {
p[i] = (p[i] & ~1) | bits[idx++];
if (idx < bits.length) p[i+1] = (p[i+1] & ~1) | bits[idx++];
if (idx < bits.length) p[i+2] = (p[i+2] & ~1) | bits[idx++];
}
ctx.putImageData(imgData, 0, 0);
const url = canvas.toDataURL('image/png');
resultImage.src = url;
resultImage.style.display = 'block';
resultImage.onclick = () => window.open(url,'_blank');
};
img.src = e.target.result;
};
reader.readAsDataURL(file);
}
function extractText(){
const file=stegoInput.files[0]; const pwd=extractPassword.value;
if(!file) return alert('Select a stego image.');
const reader=new FileReader(); reader.onload=e=>{
const img=new Image(); img.onload=()=>{
const c=document.getElementById('canvas'); c.width=img.width; c.height=img.height;
const ctx=c.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(c=>c.charCodeAt(0))); str=new TextDecoder().decode(xorEncryptDecrypt(rawBytes, pwd));}
else str=new TextDecoder().decode(extracted);
extractEditor.innerHTML = LZString.decompressFromUTF16(str);
}catch{alert('Decoding failed.');}
};
img.src = e.target.result;
};
reader.readAsDataURL(file);
}
</script>
</body>
</html>