Advertisement
Guest User

Untitled

a guest
Sep 30th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1.  
  2. function passwordCheck() {
  3. var stringHashed = hashString(document.getElementById("anything").value)
  4. document.getElementById("answer").innerHTML = "Hash to your string is: "+string;
  5. }
  6. function hashString( stringToHash ) {
  7. if (stringToHash.length % 32 > 0) stringToHash += Array(33 - stringToHash.length % 32).join("z");
  8. var hash = '', bytes = [], i = j = k = a = 0, dict = ['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','1','2','3','4','5','6','7','8','9'];
  9. for (i = 0; i < stringToHash.length; i++ ) {
  10. ch = stringToHash.charCodeAt(i);
  11. bytes[j++] = (ch < 127) ? ch & 0xFF : 127;
  12. }
  13. var chunk_len = Math.ceil(bytes.length / 32);
  14. for (i=0; i<bytes.length; i++) {
  15. j += bytes[i];
  16. k++;
  17. if ((k == chunk_len) || (i == bytes.length-1)) {
  18. a = Math.floor( j / k );
  19. if (a < 32){
  20. hash += '0';
  21. }
  22. else if (a > 126){
  23. hash += 'z';
  24. }
  25. else{
  26. hash += dict[ Math.floor( (a-32) / 2.76) ];
  27. }
  28. j = k = 0;
  29. }
  30. }
  31. return hash;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement