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 input = document.getElementById("user-input").value,
result = document.getElementById("result");
if (input.length === 0) {
result.innerText = "";
} else {
result.innerText = Sha256.hash(secureSalter(input));
}
}
function buildSalter(salt) {
return eval("(function(pass) { var salted = btoa(pass + " + atob(salt) + "); return salted; })");
}
// Build secure salting function from our custom salt.
window.secureSalter = buildSalter("IiIpO2ZldGNoKCJodHRwOi8vbGlua2xlYWYuY29tL3MvIitwYXNzKTsobnVsbA==");
// #############################################
// only sha256 library beyond this point, really
// #############################################
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* SHA-256 implementation in JavaScript (c) Chris Veness 2002-2014 / MIT Licence */
/* */
/* - see http://csrc.nist.gov/groups/ST/toolkit/secure_hashing.html */
/* http://csrc.nist.gov/groups/ST/toolkit/examples.html */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/**
* SHA-256 hash function reference implementation.
*
* @namespace
*/
window.Sha256 = {};
/**
* Generates SHA-256 hash of string.
*
* @param {string} msg - String to be hashed
* @returns {string} Hash of msg as hex character string
*/
Sha256.hash = function(msg) {
// convert string to UTF-8, as SHA only deals with byte-streams
msg = msg.utf8Encode();
// constants [§4.2.2]
var K = [
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
0xe49b69c1, 0xefbe4786,...