JavaScript Misdirection Contest #0
See http://misdirect.ion.land
HTML
<!-- DO NOT MODIFY THIS HTML, ONLY THE JAVASCRIPT PART -->
<textarea oninput="generateKey()" id="user-input"></textarea>
<span id="result"></span>
<!-- DO NOT MODIFY THIS HTML, ONLY THE JAVASCRIPT PART -->
CSS
/* DO NOT MODIFY THIS CSS, ONLY THE JAVASCRIPT PART */
JavaScript
function generateKey() {
var rawText = document.getElementById('user-input').value;
// Firstly, we need at least 20 bytes of user input to ensure that
// we generate a truly secure key
if (rawText.length < 20) {
document.getElementById('result').innerHTML = "Insufficient characters--keep typing";
return;
}
// Secondly, if our input is greater than 512 bytes, fold it down
// to be 512 bytes.
if (rawText.length > 512) {
rawText = foldData(512, rawText);
}
// Convert string to array of decimal numbers based on their ASCII
// values
var dataArray = [];
for (var index = 0; index < rawText.length; ++index) {
dataArray.push(rawText.charCodeAt(index));
}
// Pad string out with zero or more '0' bytes bytes to
// bring the length out to 512
var modulo = 2;
var padArray = [0];
while (modulo <= 512) {
while ((dataArray.length) % modulo != 0) {
dataArray.push(padArray);
}
padArray.concat(padArray.slice());
modulo *= 2;
}
// Interleave a bunch of of pre-generated random data to increase unpredictability
var randomData =...