Advertisement
Guest User

Untitled

a guest
Aug 28th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. var s = "e"
  2. var max_it = 1000
  3. var special_chars = 10
  4. var digit_chars = 6
  5. var cap_chars = 4
  6.  
  7. function hex2a(hexx) {
  8. var hex = hexx.toString();//force conversion
  9. var str = '';
  10. for (var i = 0; i < hex.length; i += 2){
  11. str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
  12. }
  13. return str;
  14. }
  15.  
  16. function sha256(str, it) {
  17. if (it > max_it){
  18. throw new Error("can't find a match to satisfy regex");
  19. }
  20. console.log("iteration: ",it)
  21. // We transform the string into an arraybuffer.
  22. var buffer = new TextEncoder("utf-8").encode(str);
  23. return crypto.subtle.digest("SHA-256", buffer).then(function (hash) {
  24. var t = hex(hash)
  25. if (!reg.test(t) && it < max_it){
  26. console.log("failed requirements",t)
  27. var new_it = it + 1
  28. return sha256(t,new_it)
  29. } else if(it >= max_it){
  30. console.log("HORROR")
  31. return false
  32. }
  33. else{
  34. return [t,it]
  35. }
  36.  
  37. });
  38. }
  39.  
  40. var reg_string = '(?=(.*(\`|\~|\!|\@|\#|\$|\%|\^|\*|\(|\|\-)){'+special_chars+'})(?=(.*\d){'+digit_chars+'})(?=.*[a-z])(?=(.*[A-Z]){'+cap_chars+'}).{14,14}'
  41.  
  42. var reg = new RegExp(reg_string)
  43. console.log("regexp",reg)
  44.  
  45. function hex(buffer) {
  46. var hexCodes = [];
  47. var view = new DataView(buffer);
  48. for (var i = 0; i < view.byteLength; i += 4) {
  49. // Using getUint32 reduces the number of iterations needed (we process 4 bytes each time)
  50. var value = view.getUint32(i)
  51. // toString(16) will give the hex representation of the number without padding
  52. var stringValue = value.toString(8)
  53.  
  54. // We use concatenation and slice for padding
  55. //var padding = '00000000'
  56. var padding = ''
  57. var paddedValue = (padding + hex2a(stringValue)).slice(-padding.length)
  58. hexCodes.push(paddedValue);
  59. }
  60.  
  61. // Join all the hex strings into one
  62. return hexCodes.join("");
  63. }
  64. console.log("Input 'e' should take 454 iterations to satisfy 10 special, 6 digits, and 4 caps");
  65. sha256(s,1).then(function(digest) {
  66. console.log(digest);
  67. console.log("test",reg.test(digest))
  68. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement