Advertisement
Guest User

Multiplicative Hash Generator

a guest
Oct 26th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 3.92 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <script src="http://peterolson.github.com/BigInteger.js/BigInteger.min.js"></script>
  5.        
  6.         <!-- Simple Password Hash Library -->
  7.        
  8.         <script>
  9.     /* 
  10.         Calculates the value of (mantissa * (base^exponent)) and stores it into a bigInt
  11.     */ 
  12.         function bigInt_from_shorthand(mantissa, base, exponent)
  13.         {
  14.             return bigInt(mantissa).multiply(bigInt(base).pow(bigInt(exponent)));
  15.         }  
  16.     /* 
  17.         See more large sophie-germain primes at http://yves.gallot.pagesperso-orange.fr/primes/chrrcds.html#Sophie 
  18.     */     
  19.         function safe_prime_from_sophie_germain_shorthand(mantissa, base, exponent, adjustment)
  20.         {
  21.             return bigInt(1).add(bigInt(2).multiply(bigInt(adjustment).add(bigInt_from_shorthand(mantissa, base, exponent))));
  22.         }
  23.     /* 
  24.         Passing -1 as the truncate_length parameter truncates to the original text length, while zero means no truncation...
  25.     */         
  26.         function make_safe_hash(text, truncate_length = 0)
  27.         {
  28.             text.trim();
  29.             var length = text.length;
  30.         //  Make sure our data is padded with non-zero values
  31.             var value = "9";
  32.             var first = safe_prime_from_sophie_germain_shorthand(72021, 2, 23630, -1);
  33.             var second = safe_prime_from_sophie_germain_shorthand(14516877, 2, 24176, -1); 
  34.             var modulus = safe_prime_from_sophie_germain_shorthand(18458709, 2, 32611, -1);
  35.             for(var index = 0; index < length; ++index)
  36.                 value += text[index].charCodeAt();
  37.             value += "9";
  38.             var temp = first.multiply(value).multiply(second);
  39.             var result = temp.multiply(temp).mod(modulus);
  40.             if(truncate_length)
  41.                 result = result.toString().substr(0, truncate_length < 0 ? length : truncate_length);
  42.             return result;
  43.         }
  44.     /
  45.         Passing -1 as the truncate_length parameter truncates to the original text length, while zero means no truncation...
  46.     */     
  47.         function make_user_hash(username, password, truncate_length = 0)
  48.         {
  49.             return make_safe_hash(username.trim() + ";" + password.trim(), truncate_length);
  50.         }
  51.         </script>
  52.        
  53.         <!-- Test Program -->
  54.        
  55.         <script>
  56.         function display()
  57.         {
  58.             var length_input = document.getElementById('length');
  59.             var length = Number(length_input.value);
  60.             if(isNaN(length) || !length)
  61.             {
  62.                 length = 0;
  63.                 length_input.value = "(default)";
  64.             }  
  65.             var username = document.getElementById('username').value;
  66.             var password = document.getElementById('password').value;
  67.             document.getElementById('output').innerHTML = make_user_hash(username, password, length).toString();
  68.         }
  69.         function toggle()
  70.         {
  71.             var input = document.getElementById('password');
  72.             var button = document.getElementById('visibility');
  73.             if(button.value ==  "show")
  74.             {
  75.                 input.type = "text";
  76.                 button.value = "hide";
  77.             }
  78.             else
  79.             {
  80.                 input.type = "password";
  81.                 button.value = "show";     
  82.             }
  83.         }
  84.         </script>
  85.     </head>
  86.     <body style = "background-color:#cddeee;color:#369;font-family:Arial,Helvetica,sans-serif;">
  87.         <br/>
  88.         <h1 align = "center">Multiplicative Hash Generator</h1>
  89.         <br/>
  90.         <br/>
  91.         <br/>
  92.         <form onsubmit="display()" action="javascript:void(0)">
  93.             <table align = "center" style = "border-spacing:15px;border-collapse:separate;">
  94.                 <tr>
  95.                     <td>
  96.                         Username &nbsp; (optional)
  97.                     </td>
  98.                     <td>
  99.                         Password
  100.                         &nbsp;
  101.                         <input type = "button" id = "visibility" value = "show" onclick = "toggle()"/>
  102.                     </td>
  103.                     <td>
  104.                         Length
  105.                     </td>
  106.                 </tr>
  107.                 <tr>
  108.                     <td>
  109.                         <input type = "text" id = "username" onfocus = "this.select()"/>
  110.                     </td>
  111.                     <td>
  112.                         <input type = "password" id = "password" onfocus = "this.select()"/>
  113.                     </td>
  114.                     <td>
  115.                         <input type = "text" id = "length" onfocus = "this.select()" value = "(default)"/>
  116.                     </td>
  117.                 <tr>           
  118.                     <td></td>
  119.                     <td align="center">
  120.                         <input type = "submit" id = "generate" value = "Generate!"/>
  121.                     </td>
  122.                     <td></td>              
  123.                 </tr>          
  124.             </table>
  125.         </form>
  126.         <p id="output" style = "word-wrap:break-word;"></p>
  127.     </body>
  128. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement