My first quick implementation of the ”full page as key” idea
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;
}());