-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstego.html
538 lines (462 loc) · 17.3 KB
/
stego.html
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Stego! Text Steganography</title>
<link rel="stylesheet" type="text/css" href="javascrypt.css" />
<meta name="keywords" content="javascrypt, browser, encryption, stego, steganography, hidden, writing, javascript" />
<meta name="description" content="Stego! Text Steganography" />
<meta name="author" content="John Walker" />
<meta name="robots" content="index" />
<!-- Import the external JavaScript modules -->
<script type="text/javascript" src="externalLinks.js"></script>
<script type="text/javascript" src="lecuyer.js"></script>
<script type="text/javascript" src="armour.js"></script>
<script type="text/javascript" src="stegodict.js"></script>
<script type="text/javascript">
<!--
'use strict';
/* Examine the message and determine which kind of ASCII
armour it uses from the sentinel preceding the message.
We test for each of the sentinels and, if any are
found, decide based on the one found first in the
message (since, for example, the sentinel for
codegroup armour might appear in a Base64 message,
but only after the Base64 sentinel). If none of
the sentinels are found, we decode using the armour
type specified by the checkboxes for encryption.
The return value is an integer which identifies the
armour type as follows:
0 Codegroup
1 Hexadecimal
2 Base 64
*/
function determineArmourType(s) {
var plainF = document.getElementById("plain");
var kt, pcg, phex, pb64, pmin;
pcg = s.indexOf(codegroupSentinel);
phex = s.indexOf(hexSentinel);
pb64 = s.indexOf(base64sent);
if (pcg == -1) {
pcg = s.length;
}
if (phex == -1) {
phex = s.length;
}
if (pb64 == -1) {
pb64 = s.length;
}
pmin = Math.min(pcg, Math.min(phex, pb64));
if (pmin < s.length) {
if (pmin == pcg) {
kt = 0;
} else if (pmin == phex) {
kt = 1;
} else {
kt = 2;
}
} else {
if (plainF.encoding[0].checked) {
kt = 0;
} else if (plainF.encoding[1].checked) {
kt = 1;
} else if (plainF.encoding[2].checked) {
kt = 2;
}
}
return kt;
}
// Retrieve word given index in list of words of that length
function retrieveWord(length, index) {
if ((length >= minw) && (length <= maxw) &&
(index >= 0) && (index < nwords[length])) {
return cwords[length].substring(length * index, length * (index + 1));
}
return "";
}
// Obtain word by index in complete dictionary
function indexWord(index) {
if ((index >= 0) && (index < twords)) {
var j;
for (j = minw; j <= maxw; j++) {
if (index < nwords[j]) {
break;
}
index -= nwords[j];
}
return retrieveWord(j, index);
}
return "";
}
/* Edit an array of bytes (integers between 0 and 255) to
a hexadecimal string. */
function byteArrayToHex(byteArray) {
var result = "", i;
for (i = 0; i < byteArray.length; i++) {
result += ((byteArray[i] < 16) ? "0" : "") +
byteArray[i].toString(16);
}
return result;
}
/* Parse a sequence of hexadecimal digits into an array
of bytes (integers between 0 and 255). */
function hexToByteArray(hexString) {
var byteArray = new Array(), i;
if (hexString.length % 2) {
byteArray += "0";
}
if ((hexString.indexOf("0x") == 0) ||
(hexString.indexOf("0X") == 0)) {
hexString = hexString.substring(2);
}
for (i = 0; i < hexString.length; i += 2) {
byteArray[Math.floor(i / 2)] =
parseInt(hexString.slice(i, i + 2), 16);
}
return byteArray;
}
// Hide text as words
function Hide_text() {
var plainF = document.getElementById("plain");
var cipherF = document.getElementById("cipher");
if (cipherF.text.value.length == 0) {
alert("No cipher text to hide! Please enter or paste cipher text in the field above.");
return;
}
plainF.text.value = "";
var ct = new Array(), kt, padded = false;
var purng = new LEcuyer((new Date()).getTime());
kt = determineArmourType(cipherF.text.value);
if (kt == 0) {
ct = disarm_codegroup(cipherF.text.value);
} else if (kt == 1) {
ct = disarm_hex(cipherF.text.value);
} else if (kt == 2) {
ct = disarm_base64(cipherF.text.value);
}
/* Cipher text should always be an even number of bytes.
If it isn't, pad it with a zero and set a flag to indicate
we've added a pad. */
if (ct.length & 1) {
ct[ct.length] = 0;
padded = true;
}
/* Walk through cipher text two bytes at a time,
assembling each pair into an index into our table
of words. Append each word to the hidden text. */
var i, w, l = "", t = "";
var maxLine = cipherF.linelen.value,
sl = 0, sc = 0, fpar = false,
parl = purng.nextInt(9) + 3,
puncture = cipherF.punctuation.checked;
if (isNaN(maxLine) || (maxLine < 12)) {
cipherF.linelen.value = maxLine = 72;
}
for (i = 0; i < ct.length; i += 2) {
w = indexWord((ct[i] << 8) | ct[i + 1]).toLowerCase();
if (puncture && (sl == 0)) {
w = w.substr(0, 1).toUpperCase() + w.substr(1, w.length);
}
/* If this is the last word, put a period after it
unless we added a padding byte, in which case we
end with a bang to so indicate. */
if (i == (ct.length - 2)) {
w += padded ? "!" : ".";
} else {
if (puncture) {
// Regular word. Generate random but plausible punctuation
sl++;
if (sl >= (purng.nextInt(9) + 3)) {
var p = purng.nextInt(15), pu;
pu = (p <= 13) ? "." : ((p == 14) ? "?" : "!");
w += pu + " ";
sl = 0;
sc++;
if (sc >= parl) {
fpar = true;
sc = 0;
}
} else {
if (purng.nextInt(6) == 6) {
w += ",";
}
}
}
}
if ((l.length + w.length + 1) > maxLine) {
l = l.replace(/\s+$/, "");
t += l + "\n";
l = "";
}
if (l.length > 0) {
l += " ";
}
l += w;
if (fpar) {
l = l.replace(/\s+$/, "");
t += l + "\n\n";
l = "";
fpar = false;
parl = purng.nextInt(8) + 2;
}
}
t += l + "\n";
plainF.text.value = t;
purng = null;
}
// Decode text from words
function Seek_text() {
var plainF = document.getElementById("plain");
var cipherF = document.getElementById("cipher");
if (plainF.text.value.length == 0) {
alert("No hidden text to decode! Please enter or paste hidden text in the field above.");
return;
}
cipherF.text.value = "";
var ct = new Array(), padded = false;
/* Precompute table of cumulative words before those
of a given length. */
var awords = new Array(), i, j;
j = 0;
for (i = minw; i <= maxw; i++) {
awords[i] = j;
j += nwords[i];
}
var t = plainF.text.value, n = 0, v;
var wpat = /\W*(\w+)\w*/i;
while (wpat.test(t)) {
// Extract next word from text and determine its length
t = t.replace(wpat, "");
var w = RegExp.$1;
var l = w.length;
// Look it up in the list of words of this length
w = w.substring(0, 1).toUpperCase() +
w.substring(1, w.length);
v = cwords[l].indexOf(w);
if (v >= 0) {
v = (v / l) + awords[l];
}
if (v == -1) {
alert("Cipher text contains word \"" + w + "\"\n" +
"which is not in the dictionary.");
} else {
ct[n++] = (v >> 8) & 0xFF;
ct[n++] = v & 0xFF;
}
}
if (t.indexOf("!") != -1) {
padded = true;
ct.pop();
n -= 1;
}
if (plainF.encoding[0].checked) {
v = armour_codegroup(ct);
} else if (plainF.encoding[1].checked) {
v = armour_hex(ct);
} else if (plainF.encoding[2].checked) {
base64addsent = plainF.b64sent.checked;
v = armour_base64(ct);
}
cipherF.text.value = v ;
}
// Sanity check dictionary length
if (twords != (1 << 16)) {
alert("Error! Dictionary (stegodict.js) contains " +
twords + " words; " + (1 << 16) + " words required.");
}
// -->
</script>
</head>
<body onload="externalLinks();">
<h1>Stego! Text Steganography</h1>
<hr class="h" />
<p>
<em>Steganography</em> is the art and science of hidden writing.
While an encryption program such as our
companion <a href="javascrypt.html">JavaScrypt</a> page
protects your message from being read by those not in possession
of the key, sometimes you wish to obscure the very fact
you're sending an encrypted message at all. An encoded
message just screams you're using encryption, which may
attract unwanted attention to your activities even if
snoopers cannot read the text of your messages. Steganography
attempts to conceal the presence of an encrypted message; over
history a wide variety of techniques have been used: secret
compartments in objects, invisible ink, microdots, grilles used
to hide letters of a message among innocent text, and, in
the digital age, embedding messages as imperceptible noise
in images and audio files.
</p>
<p class="subsuper">
This page implements a very rudimentary form of steganography; an
encrypted message is converted to what, at first glance, looks
like English text. It <em>is</em>, in fact, English text, but
complete
<a href="https://www.fourmilab.ch/etexts/www/carroll/jabberwocky.html"
rel="Target:JavascryptAux">nonsense</a>,
consisting of words chosen from a
dictionary of 65536 (2<sup>16</sup>) words, each encoding
two bytes of the message in the position of the word in the dictionary.
Punctuation and paragraph breaks are sprinkled through the
text to make it look (marginally) more plausible. Let's
be frank: anybody who gives this text more than a cursory
glance is going to immediately twig to the fact that
something very odd is going on here (unless, perhaps, you
give it a suitably postmodern title and cast it as a paper
published in
<cite><a href="https://socialtextjournal.org/"
rel="Target:JavascryptAux">Social Text</a></cite>).
To make things less obvious, you may wish to embed the text
generated by this page into a long document, having beforehand
established a convention with your correspondent to permit
them to locate it.
</p>
<form id="cipher" action="#" onsubmit="return false;">
<h3>Cipher Text</h3>
<p>
To convert an encrypted message to English text, paste the cipher text
generated by
<a href="javascrypt.html">JavaScrypt</a> into the box below, then
press the <b>Hide</b> button. You can control the
approximate length of lines of text by setting the <b>Line length</b>,
and suppress the interspersing of punctuation and paragraph
breaks by unchecking <b>Punctuation</b>. The cipher text may be in any
of the encodings supported by JavaScrypt. If the cipher text lacks the
sentinels normally included by JavaScrypt (for example, if you're
using this page to convert a
<a href="https://www.fourmilab.ch/webtools/base64/"
rel="Target:JavascryptAux">Base64</a> file generated
by another program to text), you <em>must</em> specify the
encoding by checking the corresponding button in the
<b>Encoding</b> section below the <b>Hidden Text</b> box.
</p>
<p class="c">
<textarea name="text" rows="16" cols="80"
style="background-color: rgb(255, 200, 200); color: #000000;">
</textarea>
<br />
<input type="button" name="hide" value=" Hide " onclick="Hide_text();" />
<input type="button" value=" Clear " onclick="document.getElementById('cipher').text.value = '';" />
<input type="button" value=" Select " onclick="document.getElementById('cipher').text.select();" />
Line length: <input type="text" name="linelen" size="4" maxlength="6" value="72" />
<label><input type="checkbox" checked="checked"
name="punctuation" /> Punctuation</label>
</p>
</form>
<form id="plain" action="#" onsubmit="return false;">
<h3>Hidden Text</h3>
<p>
To decode a message hidden as text, paste the hidden message into
the box below. While blank lines and punctuation of all kinds are
ignored, as is the case of letters, there must be no extraneous words
in the text. Press the <b>Seek</b> button to decode the
message into JavaScrypt-compatible cipher text in the box
above. The cipher text will use the encoding specified by
the <b>Encoding</b> buttons. If
<a href="https://www.fourmilab.ch/webtools/base64/"
rel="Target:JavascryptAux">Base64</a>
encoding is requested and the <b>Sentinel</b> box is
unchecked, the usual JavaScrypt cipher text start and end
sentinels will be omitted; this option permits creating
Base64-encoded documents suitable for use with other programs.
</p>
<p class="c">
<textarea name="text" rows="16" cols="80"
style="background-color: rgb(255, 165, 0); color: #000000;">
</textarea>
<br />
<input type="button" name="seek" value=" Seek " onclick="Seek_text();" />
<input type="button" value=" Clear " onclick="document.getElementById('plain').text.value = '';" />
<input type="button" value=" Select " onclick="document.getElementById('plain').text.select();" />
<br />
<b>Encoding:</b>
<label><input type="radio" checked="checked" name="encoding" /> Codegroup</label>
<label><input type="radio" name="encoding" /> Hexadecimal</label>
<label><input type="radio" name="encoding" /> Base 64</label>
<label><input type="checkbox" checked="checked" name="b64sent" /> Sentinel?</label>
</p>
</form>
<!-- +FULL -->
<!--
<h3>Debugging Console</h3>
<form id="debug" action="#" onsubmit="return false;">
<center>
<textarea name="log" rows="6" cols="80">
</textarea>
<br />
<input type="button" value=" Clear " onclick="document.getElementById('debug').log.value = '';" />
<input type="button" value=" Test " onclick="TestSomething();" />
</center>
</form>
<h4><a href="javascript:">JavaScript Console</a></h4>
-->
<script type="text/javascript">
<!--
/* Dump one or more (variable_name, value) pairs given as arguments
to the function. */
function dump()
{
var t = "", i;
for (i = 0; i < arguments.length; i += 2) {
if (t.length > 0) {
t += ", ";
}
t += arguments[i] + " = " + arguments[i + 1];
}
document.getElementById('debug').log.value += t + "\n";
}
-->
</script>
<!-- -FULL -->
<h3><a href="index.html">JavaScrypt</a></h3>
<ul>
<li><a href="index.html">JavaScrypt Home Page</a></li>
<li><a href="example.html">JavaScrypt Tutorial</a></li>
<li><a href="javascrypt.html">Encryption/Decryption Utility</a>
(<a href="jscrypt.html">lean version</a>)</li>
<li><a href="pass_phrase.html">Pass Phrase Generator</a></li>
<li><a href="javascrypt.zip">Download JavaScrypt Source Code</a>
(<a href="http://www.info-zip.org/"
rel="Target:JavascryptAux">Zipped</a> archive)</li>
</ul>
<h3><a href="https://www.fourmilab.ch/">Fourmilab Home Page</a></h3>
<p />
<hr />
<p />
<table class="footer">
<tr>
<td class="left">
by <a href="https://www.fourmilab.ch/">John Walker</a><br />
December, 2005<br />
Updated: March, 2018
</td>
<td class="right">
<table class="buttons">
<tr><td>
<a href="http://validator.w3.org/check?uri=https://www.fourmilab.ch/javascrypt/stego.html"
rel="Target:JavascryptAux" class="i"><img class="button"
src="https://www.fourmilab.ch/images/icons/valid-xhtml10.png"
alt="Valid XHTML 1.0" height="31" width="88" /></a>
</td></tr>
</table>
</td>
</tr>
</table>
<p class="c">
<em>This document is in the public domain.<br />
Use of this program to generate postmodern poetry or sociology
theses is strictly forbidden.</em>
</p>
</body>
</html>