Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
BF.JS
var letters = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]; var debug = true; var s1; var s2; var thehash; var salt1; var salt2; var totalcount = 0; var match = false; function doPhraseCheck(phrase, remainingIterations, excludeSpaces) { console.log("Start search..."); match = false; totalcount = 0; thehash = document.getElementById("ppHash").value; salt1 = fromhex_chksum(document.getElementById("ppSalt1").value); salt2 = fromhex_chksum(document.getElementById("ppSalt2").value); checkPhraseRecursive(phrase, remainingIterations-1, excludeSpaces); if(!match) { document.getElementById('result').innerHTML = "No match found!"; console.log("Match found!"); } console.log("Search finished! Number of tests: "+totalcount); } function checkPhraseRecursive(phrase, remainingIterations, excludeSpaces) { logMessage("Iterations: " +remainingIterations); var sp = phrase.split(""); for (var i = 0; i < sp.length; i++) { if (sp[i] == " " && excludeSpaces) //exclude spaces, if you think the general pattern of the phrase was correct continue; var originalSp = sp[i]; for (var j = 0; j < letters.length; j++) { sp[i] = letters[j]; var st = sp.join(""); if(remainingIterations > 0) { checkPhraseRecursive(st, remainingIterations-1, excludeSpaces); } logMessage(st + " " + totalcount); totalcount++; thestr = st; logMessage(thestr); checked = check_pass(thestr); if (checked == 1) { logMessage("Found!!!"); logMessage(thestr); document.getElementById("result").innerHTML = "Phrase Match: "+thestr; match = true; break; } } if(match) break; sp[i] = originalSp; } } function logMessage(msg) { if (debug) { console.log(msg); } } /* Generate a checksum and prepend it to data, returns as hex */ function tohex_chksum(data) { if (typeof data == 'string') data = sodium.from_string(data); return sodium.crypto_generichash(4, data, '', 'hex') + sodium.to_hex(data); } /* Remove a checksum from the front of data, check if the data matches ** return the data if the checksum matches (as uint8array) or false ** if data does not match */ function fromhex_chksum(hex, format) { var chksum = hex.slice(0, 8); var payload = sodium.from_hex(hex.slice(8)); if (sodium.crypto_generichash(4, payload, '', 'hex') != chksum) return false; if (format == 'string') return sodium.to_string(payload); return payload; } function check_pass(passphrase) { var pphash = sodium.crypto_pwhash_scryptsalsa208sha256(16, sodium.crypto_pwhash_scryptsalsa208sha256(16, passphrase, salt1, sodium.crypto_pwhash_OPSLIMIT_INTERACTIVE, sodium.crypto_pwhash_MEMLIMIT_INTERACTIVE), salt2, sodium.crypto_pwhash_OPSLIMIT_INTERACTIVE, sodium.crypto_pwhash_MEMLIMIT_INTERACTIVE); passphrase = ""; pphash = tohex_chksum(pphash); if (pphash == thehash) { logMessage("validatePassphrase - correct"); return 1; } logMessage("validatePassphrase - incorrect"); return 0; }
run
|
edit
|
history
|
help
0
Logical NOT in JavaScript
a pipeline generator
Education-Salary
Futbal
Rocket Science
Time Waister
Functions
Javascript Basics If statements
Jason's Code Challenge
class Node