{"id":4951,"date":"2015-10-04T09:03:15","date_gmt":"2015-10-04T06:03:15","guid":{"rendered":"http:\/\/mummila.net\/kommentit\/?p=4951"},"modified":"2015-10-04T09:04:26","modified_gmt":"2015-10-04T06:04:26","slug":"already-noticed-the-first-mistake","status":"publish","type":"post","link":"https:\/\/mummila.net\/kommentit\/2015\/10\/04\/already-noticed-the-first-mistake\/","title":{"rendered":"Already noticed the first mistake"},"content":{"rendered":"<p>You&#8217;re right Jonathan, using one whole page to decipher another would also be interesting. It&#8217;d take a bit more code (temporary storage is needed for keeping the previous page) but it still shouldn&#8217;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.<\/p>\n<p>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&#8217;t part of the alphabet. Here&#8217;s a fixed version that takes out the page number and whitespace preceding it:<\/p>\n<pre><code>(function () {\r\n    var alphabet, c, i, m, text, title;\r\n\r\n    alphabet = 'abcdefghijklmnopqrstuvwxyz,. ';\r\n    title = document.title.replace(new RegExp('[^abcdefghijklmnopqrstuvwxyz,\\. ]', 'g'), '');\r\n    title = title.substr(0, title.length - 1);\r\n    text = {\r\n        original: document.getElementById('textblock').textContent,\r\n        decoded: ''\r\n    };\r\n\r\n    for (i = 0; i &lt; text.original.length; i += 1) {\r\n        c = text.original.substr(i, 1);\r\n        if (c === &#039;\\n&#039;) {\r\n            text.decoded += c;\r\n        } else {\r\n            m = alphabet.indexOf(title.substr(i % title.length, 1)); \/* add &quot;+ 1&quot; if you want A = 1, B = 2,... instead of A = 0, B = 1,... *\/\r\n            text.decoded += alphabet.substr(((alphabet.indexOf(c) - m) % alphabet.length), 1);\r\n        }\r\n    }\r\n    document.getElementById(&#039;textblock&#039;).textContent = text.decoded;\r\n}());\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Forgot to strip the page number from the title it should, as numbers aren&#8217;t part of the alphabet. Here&#8217;s a version that takes out the number.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1097],"tags":[],"class_list":["post-4951","post","type-post","status-publish","format-standard","hentry","category-keskustelupalstat","sijainti-library-of-babel"],"_links":{"self":[{"href":"https:\/\/mummila.net\/kommentit\/wp-json\/wp\/v2\/posts\/4951","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mummila.net\/kommentit\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mummila.net\/kommentit\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mummila.net\/kommentit\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mummila.net\/kommentit\/wp-json\/wp\/v2\/comments?post=4951"}],"version-history":[{"count":5,"href":"https:\/\/mummila.net\/kommentit\/wp-json\/wp\/v2\/posts\/4951\/revisions"}],"predecessor-version":[{"id":4956,"href":"https:\/\/mummila.net\/kommentit\/wp-json\/wp\/v2\/posts\/4951\/revisions\/4956"}],"wp:attachment":[{"href":"https:\/\/mummila.net\/kommentit\/wp-json\/wp\/v2\/media?parent=4951"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mummila.net\/kommentit\/wp-json\/wp\/v2\/categories?post=4951"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mummila.net\/kommentit\/wp-json\/wp\/v2\/tags?post=4951"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}