Vigenère cipher

3. lokakuuta 2015 klo 15.09
Sijainti: Keskustelupalstat: Library of Babel

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;
}());

Vastaa viestiin sen kontekstissa (Library of Babel)