• API
• FAQ
• Tools
• Archive
daily pastebin goal
36%
SHARE
TWEET

# Composite Hash Generator

a guest Oct 27th, 2016 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. <!DOCTYPE html>
2. <html>
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.         {
22.         }
23.     /*
24.         The final hash will essentially be the sum of two distinct values obtained from this function
25.     */
26.         function make_preliminary_hash_integer(value, first, second, modulus)
27.         {
28.             var temp = first.multiply(value).multiply(second);
29.             return temp.multiply(temp).mod(modulus);
30.         }
31.     /*
32.         Passing -1 as the truncate_length parameter truncates to the original text length, while zero means no truncation...
33.     */
34.         function make_safe_hash(text, truncate_length = 0)
35.         {
36.             text.trim();
37.             var length = text.length;
38.         /*
39.             The mapping may seem somewhat obscure, but just keep in mind that the point
40.             here is merely to create a number suitable for use with this particular hash function
41.         */
44.             for(var index = 0; index < length; ++index)
45.             {
46.                 var data = text[index].charCodeAt();
47.             //  The resulting number is more likely to be unique if each character generates a three-digit sequence
48.                 if(data < 100)
50.                 digits += data;
51.             }
53.             var value = bigInt(digits);
54.             if(typeof make_safe_hash.initialized === "undefined")
55.             {
56.                 make_safe_hash.initialized = true;
57.                 make_safe_hash.lhs =
58.                 {
59.                     first : safe_prime_from_sophie_germain_shorthand(72021, 2, 23630, -1),
60.                     second : safe_prime_from_sophie_germain_shorthand(14516877, 2, 24176, -1),
61.                     modulus : safe_prime_from_sophie_germain_shorthand(18458709, 2, 32611, -1)
62.                 };
63.                 make_safe_hash.rhs =
64.                 {
65.                     first : safe_prime_from_sophie_germain_shorthand(470943129, 2, 16352, -1),
66.                     second : safe_prime_from_sophie_germain_shorthand(8069496435, 10, 5072, -1),
67.                     modulus : safe_prime_from_sophie_germain_shorthand(2375063906985, 2, 19380, -1)
68.                 };
69.             }
70.             var lhs = make_preliminary_hash_integer
71.             (
72.                 value,
73.                 make_safe_hash.lhs.first,
74.                 make_safe_hash.lhs.second,
75.                 make_safe_hash.lhs.modulus
76.             );
77.             var rhs = make_preliminary_hash_integer
78.             (
79.                 value,
80.                 make_safe_hash.rhs.first,
81.                 make_safe_hash.rhs.second,
82.                 make_safe_hash.rhs.modulus
83.             );
85.             if(truncate_length)
86.                 result = result.substr(0, truncate_length < 0 ? length : truncate_length);
87.             return result;
88.         }
89.     /*
90.         Passing -1 as the truncate_length parameter truncates to the original text length, while zero means no truncation...
91.     */
93.         {
94.         //  Note: 0x1e was chosen for the simple fact that it represents the "record separator" code in ascii
96.         }
97.         </script>
98.
99.         <!-- Test Program -->
100.
101.         <script>
102.         function display()
103.         {
104.             var length_input = document.getElementById('length');
105.             var length = Number(length_input.value);
106.             if(isNaN(length) || !length)
107.             {
108.                 length = 0;
109.                 length_input.value = "(default)";
110.             }
114.         }
115.         function toggle()
116.         {
118.             var button = document.getElementById('visibility');
119.             if(button.value ==  "show")
120.             {
121.                 input.type = "text";
122.                 button.value = "hide";
123.             }
124.             else
125.             {
127.                 button.value = "show";
128.             }
129.         }
130.         </script>
132.     <body style = "background-color:#cddeee;color:#369;font-family:Arial,Helvetica,sans-serif;">
133.         <br/>
134.         <h1 align = "center">Composite Hash Generator</h1>
135.         <br/>
136.         <br/>
137.         <br/>
138.         <form onsubmit="display()" action="javascript:void(0)">
139.             <table align = "center" style = "border-spacing:15px;border-collapse:separate;">
140.                 <tr>
141.                     <td>
143.                     </td>
144.                     <td>
146.                         &nbsp;
147.                         <input type = "button" id = "visibility" value = "show" onclick = "toggle()"/>
148.                     </td>
149.                     <td>
150.                         Length
151.                     </td>
152.                 </tr>
153.                 <tr>
154.                     <td>
155.                         <input type = "text" id = "username" onfocus = "this.select()"/>
156.                     </td>
157.                     <td>
159.                     </td>
160.                     <td>
161.                         <input type = "text" id = "length" onfocus = "this.select()" value = "(default)"/>
162.                     </td>
163.                 <tr>
164.                     <td></td>
165.                     <td align="center">
166.                         <input type = "submit" id = "generate" value = "Generate!"/>
167.                     </td>
168.                     <td></td>
169.                 </tr>
170.             </table>
171.         </form>
172.         <p id="output" style = "word-wrap:break-word;"></p>
173.     </body>
174. </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top