Here’s my first quick implementation of the ”full page as key” idea:
Save page as key:
(function () {
localStorage.setItem('libraryOfBabelKey', document.getElementById('textblock').textContent);
}());
Decrypt using previously saved key:
(function () {
var alphabet, c, i, m, text, key;
alphabet = 'abcdefghijklmnopqrstuvwxyz,. ';
key = localStorage.getItem('libraryOfBabelKey');
if (!key) {
alert('No key has been saved.');
return;
}
text = {
original: document.getElementById('textblock').textContent,
decoded: ''
};
for (i = 0; i < text.original.length; i += 1) {
c = text.original.substr(i, 1);
if (c === '\n') {
text.decoded += c;
} else {
m = alphabet.indexOf(key.substr(i, 1));
text.decoded += alphabet.substr(((alphabet.indexOf(c) - m) % alphabet.length), 1);
}
}
document.getElementById('textblock').textContent = text.decoded;
}());
You’re right Jonathan, using one whole page to decipher another would also be interesting. It’d take a bit more code (temporary storage is needed for keeping the previous page) but it still shouldn’t be too difficult. The pages could then be considered as having been encrypted with a one-time pad, which is unbreakable and thus a cool idea in itself.
I already noticed the first mistake in my code above: I forgot to strip the page number from the title prior to use, but it should be, as numbers aren’t part of the alphabet. Here’s a fixed version that takes out the page number and whitespace preceding it:
(function () {
var alphabet, c, i, m, text, title;
alphabet = 'abcdefghijklmnopqrstuvwxyz,. ';
title = document.title.replace(new RegExp('[^abcdefghijklmnopqrstuvwxyz,\. ]', 'g'), '');
title = title.substr(0, title.length - 1);
text = {
original: document.getElementById('textblock').textContent,
decoded: ''
};
for (i = 0; i < text.original.length; i += 1) {
c = text.original.substr(i, 1);
if (c === '\n') {
text.decoded += c;
} else {
m = alphabet.indexOf(title.substr(i % title.length, 1)); /* add "+ 1" if you want A = 1, B = 2,... instead of A = 0, B = 1,... */
text.decoded += alphabet.substr(((alphabet.indexOf(c) - m) % alphabet.length), 1);
}
}
document.getElementById('textblock').textContent = text.decoded;
}());
Here’s a piece of JavaScript I made that uses the book title as a Vigenère cipher keyword to decrypt the page content. You can paste it directly into the browser’s URL bar on a library page to decrypt. (I made it in a hurry so it comes with no warranty!)
javascript:(function () {
var alphabet, c, i, m, text, title;
alphabet = 'abcdefghijklmnopqrstuvwxyz,. ';
title = document.title;
text = {
original: document.getElementById('textblock').textContent,
decoded: ''
};
for (i = 0; i < text.original.length; i += 1) {
c = text.original.substr(i, 1);
if (c === '\n') {
text.decoded += c;
} else {
m = alphabet.indexOf(title.substr(i % title.length, 1)); /* add "+ 1" if you want A = 1, B = 2,... instead of A = 0, B = 1,... */
text.decoded += alphabet.substr(((alphabet.indexOf(c) - m) % alphabet.length), 1);
}
}
document.getElementById('textblock').textContent = text.decoded;
}());
All right, thanks for looking into this — whatever the outcome.
Ah, James Jeans. I’ve worn the trousers invented by him!
”In god we droste” Nice…
I wish they had knocked down a redshirt on the shelf there.
Loistavaa, paljon kiitoksia! Veikkaan että minun kannattaa aloittaa scifistä, sillä on yleensä ainakin lähtökohtaisesti paras vetovoima. Enkäpä muuten siltikään muista vuosikausiin scifiä lukeneeni jostain syystä. Tuo Kulttuuri kuulostaa hyvältä, muistuttaa perusidealtaan jossain määrin Asimovin Säätiö-sarjaa, josta aikoinaan pidin kovasti (nimenomaan sen perusidean, tulevaisuuden yhteiskunnan kuvauksen takia).
Ja sitten jos se scifi ei nappaakaan, voin kokeilla eiscifiä. Ja sittenkin, jos nappaakin.
Muistankin nyt tuon Banks-postauksesi. Muistelen myös jo silloin miettineeni tätä neuvoa kysyväni, mutta jostain syystä se jäi näköjään tekemättä.
You could argue the code already is open. After all, you can just go to the library and get it, provided you know where to look. ;-)
Ai niin Lynchpä tietenki! Joo, kyllä minäkin näin ollen voin sanoa yleisesti tykkääväni siitä kun se tehdään oikein, ei vain siinä paha-ei-saa-palkkaansa -erityistapauksessa. Lynchin elokuvia tosin en enimmäkseen ole jaksanut katsella loppuun saakka, mutta sekään ei johdu tuosta piirteestä, vaan enemmänkin niiden vaativuudesta (niihin pitäisi aktiivisesti uppoutua, ja kykyni mihinkään aktiiviseen on ylipäänsä heikko).
Iain Banksista olenkin muuten aikonut tiedustella sinulta neuvoa: mistä kannattaisi aloittaa? (Näpytän tässä samalla myös tuon Fowlesin lukulistalleni.)