Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var s = "e"
- var max_it = 1000
- var special_chars = 10
- var digit_chars = 6
- var cap_chars = 4
- function hex2a(hexx) {
- var hex = hexx.toString();//force conversion
- var str = '';
- for (var i = 0; i < hex.length; i += 2){
- str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
- }
- return str;
- }
- function sha256(str, it) {
- if (it > max_it){
- throw new Error("can't find a match to satisfy regex");
- }
- console.log("iteration: ",it)
- // We transform the string into an arraybuffer.
- var buffer = new TextEncoder("utf-8").encode(str);
- return crypto.subtle.digest("SHA-256", buffer).then(function (hash) {
- var t = hex(hash)
- if (!reg.test(t) && it < max_it){
- console.log("failed requirements",t)
- var new_it = it + 1
- return sha256(t,new_it)
- } else if(it >= max_it){
- console.log("HORROR")
- return false
- }
- else{
- return [t,it]
- }
- });
- }
- var reg_string = '(?=(.*(\`|\~|\!|\@|\#|\$|\%|\^|\*|\(|\|\-)){'+special_chars+'})(?=(.*\d){'+digit_chars+'})(?=.*[a-z])(?=(.*[A-Z]){'+cap_chars+'}).{14,14}'
- var reg = new RegExp(reg_string)
- console.log("regexp",reg)
- function hex(buffer) {
- var hexCodes = [];
- var view = new DataView(buffer);
- for (var i = 0; i < view.byteLength; i += 4) {
- // Using getUint32 reduces the number of iterations needed (we process 4 bytes each time)
- var value = view.getUint32(i)
- // toString(16) will give the hex representation of the number without padding
- var stringValue = value.toString(8)
- // We use concatenation and slice for padding
- //var padding = '00000000'
- var padding = ''
- var paddedValue = (padding + hex2a(stringValue)).slice(-padding.length)
- hexCodes.push(paddedValue);
- }
- // Join all the hex strings into one
- return hexCodes.join("");
- }
- console.log("Input 'e' should take 454 iterations to satisfy 10 special, 6 digits, and 4 caps");
- sha256(s,1).then(function(digest) {
- console.log(digest);
- console.log("test",reg.test(digest))
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement