Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <script src="http://peterolson.github.com/BigInteger.js/BigInteger.min.js"></script>
- <!-- Simple Password Hash Library -->
- <script>
- /*
- Calculates the value of (mantissa * (base^exponent)) and stores it into a bigInt
- */
- function bigInt_from_shorthand(mantissa, base, exponent)
- {
- return bigInt(mantissa).multiply(bigInt(base).pow(bigInt(exponent)));
- }
- /*
- See more large sophie-germain primes at http://yves.gallot.pagesperso-orange.fr/primes/chrrcds.html#Sophie
- */
- function safe_prime_from_sophie_germain_shorthand(mantissa, base, exponent, adjustment)
- {
- return bigInt(1).add(bigInt(2).multiply(bigInt(adjustment).add(bigInt_from_shorthand(mantissa, base, exponent))));
- }
- /*
- Passing -1 as the truncate_length parameter truncates to the original text length, while zero means no truncation...
- */
- function make_safe_hash(text, truncate_length = 0)
- {
- text.trim();
- var length = text.length;
- // Make sure our data is padded with non-zero values
- var value = "9";
- var first = safe_prime_from_sophie_germain_shorthand(72021, 2, 23630, -1);
- var second = safe_prime_from_sophie_germain_shorthand(14516877, 2, 24176, -1);
- var modulus = safe_prime_from_sophie_germain_shorthand(18458709, 2, 32611, -1);
- for(var index = 0; index < length; ++index)
- value += text[index].charCodeAt();
- value += "9";
- var temp = first.multiply(value).multiply(second);
- var result = temp.multiply(temp).mod(modulus);
- if(truncate_length)
- result = result.toString().substr(0, truncate_length < 0 ? length : truncate_length);
- return result;
- }
- /*
- Passing -1 as the truncate_length parameter truncates to the original text length, while zero means no truncation...
- */
- function make_user_hash(username, password, truncate_length = 0)
- {
- return make_safe_hash(username.trim() + ";" + password.trim(), truncate_length);
- }
- </script>
- <!-- Test Program -->
- <script>
- function display()
- {
- var length_input = document.getElementById('length');
- var length = Number(length_input.value);
- if(isNaN(length) || !length)
- {
- length = 0;
- length_input.value = "(default)";
- }
- var username = document.getElementById('username').value;
- var password = document.getElementById('password').value;
- document.getElementById('output').innerHTML = make_user_hash(username, password, length).toString();
- }
- function toggle()
- {
- var input = document.getElementById('password');
- var button = document.getElementById('visibility');
- if(button.value == "show")
- {
- input.type = "text";
- button.value = "hide";
- }
- else
- {
- input.type = "password";
- button.value = "show";
- }
- }
- </script>
- </head>
- <body style = "background-color:#cddeee;color:#369;font-family:Arial,Helvetica,sans-serif;">
- <br/>
- <h1 align = "center">Multiplicative Hash Generator</h1>
- <br/>
- <br/>
- <br/>
- <form onsubmit="display()" action="javascript:void(0)">
- <table align = "center" style = "border-spacing:15px;border-collapse:separate;">
- <tr>
- <td>
- Username (optional)
- </td>
- <td>
- Password
-
- <input type = "button" id = "visibility" value = "show" onclick = "toggle()"/>
- </td>
- <td>
- Length
- </td>
- </tr>
- <tr>
- <td>
- <input type = "text" id = "username" onfocus = "this.select()"/>
- </td>
- <td>
- <input type = "password" id = "password" onfocus = "this.select()"/>
- </td>
- <td>
- <input type = "text" id = "length" onfocus = "this.select()" value = "(default)"/>
- </td>
- <tr>
- <td></td>
- <td align="center">
- <input type = "submit" id = "generate" value = "Generate!"/>
- </td>
- <td></td>
- </tr>
- </table>
- </form>
- <p id="output" style = "word-wrap:break-word;"></p>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement