PageSourceSearch

https://www.linguagemclipper.com.br/sites/all/modules/hashcash/js/hashcash.js?tk2v53

js linguagemclipper.com.br collected 2026-10-02 18:48:21 UTC 5,329 bytes, 211 lines download raw bytes

1function hashcash_create(formfield) {
2  var ajax_options = {
3    async:false,
4    cache:false,
5    url:Drupal.settings.hashcash.url+'/'+document.getElementById(formfield).value,
6    dataType:'text',
7    success:function(formfield_value){
8      set_form_field(formfield, formfield_value);
9    }
10  };
11  jQuery.ajax(ajax_options);
12}
13
14function set_form_field(formfield, formfield_value){
15  var shafound = false;
16  var hashcash = '';
17  var new_field_value = ''; 
18  while(!shafound){
19    new_field_value = formfield_value+randomString(20);
20    hashcash = SHA1(new_field_value);
21    if(hashcash.substring(0,2) == "00"){
22      shafound=true;
23    }
24  }
25  document.getElementById(formfield).value = new_field_value;
26}
27
28function randomString(string_length) {
29	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
30	var randomstring = '';
31	for (var i=0; i<string_length; i++) {
32		var rnum = Math.floor(Math.random() * chars.length);
33		randomstring += chars.substring(rnum,rnum+1);
34	}
35	return randomstring;
36}
37
38/**
39 *  The following function is provided by:
40 *
41 *  Secure Hash Algorithm (SHA1)
42 *  http://www.webtoolkit.info/
43 *
44 */
45function SHA1 (msg) {
46
47    function rotate_left(n,s) {
48        var t4 = ( n<<s ) | (n>>>(32-s));
49        return t4;
50    };
51
52    function lsb_hex(val) {
53        var str="";
54        var i;
55        var vh;
56        var vl;
57
58        for( i=0; i<=6; i+=2 ) {
59            vh = (val>>>(i*4+4))&0x0f;
60            vl = (val>>>(i*4))&0x0f;
61            str += vh.toString(16) + vl.toString(16);
62        }
63        return str;
64    };
65
66    function cvt_hex(val) {
67        var str="";
68        var i;
69        var v;
70
71        for( i=7; i>=0; i-- ) {
72            v = (val>>>(i*4))&0x0f;
73            str += v.toString(16);
74        }
75        return str;
76    };
77
78
79    function Utf8Encode(string) {
80        string = string.replace(/\r\n/g,"\n");
81        var utftext = "";
82
83        for (var n = 0; n < string.length; n++) {
84
85            var c = string.charCodeAt(n);
86
87            if (c < 128) {
88                utftext += String.fromCharCode(c);
89            }
90            else if((c > 127) && (c < 2048)) {
91                utftext += String.fromCharCode((c >> 6) | 192);
92                utftext += String.fromCharCode((c & 63) | 128);
93            }
94            else {
95                utftext += String.fromCharCode((c >> 12) | 224);
96                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
97                utftext += String.fromCharCode((c & 63) | 128);
98            }
99
100        }
101
102        return utftext;
103    };
104
105    var blockstart;
106    var i, j;
107    var W = new Array(80);
108    var H0 = 0x67452301;
109    var H1 = 0xEFCDAB89;
110    var H2 = 0x98BADCFE;
111    var H3 = 0x10325476;
112    var H4 = 0xC3D2E1F0;
113    var A, B, C, D, E;
114    var temp;
115
116    msg = Utf8Encode(msg);
117
118    var msg_len = msg.length;
119
120    var word_array = new Array();
121    for( i=0; i<msg_len-3; i+=4 ) {
122        j = msg.charCodeAt(i)<<24 | msg.charCodeAt(i+1)<<16 |
123        msg.charCodeAt(i+2)<<8 | msg.charCodeAt(i+3);
124        word_array.push( j );
125    }
126
127    switch( msg_len % 4 ) {
128        case 0:
129            i = 0x080000000;
130        break;
131        case 1:
132            i = msg.charCodeAt(msg_len-1)<<24 | 0x0800000;
133        break;
134
135        case 2:
136            i = msg.charCodeAt(msg_len-2)<<24 | msg.charCodeAt(msg_len-1)<<16 | 0x08000;
137        break;
138
139        case 3:
140            i = msg.charCodeAt(msg_len-3)<<24 | msg.charCodeAt(msg_len-2)<<16 | msg.charCodeAt(msg_len-1)<<8    | 0x80;
141        break;
142    }
143
144    word_array.push( i );
145
146    while( (word_array.length % 16) != 14 ) word_array.push( 0 );
147
148    word_array.push( msg_len>>>29 );
149    word_array.push( (msg_len<<3)&0x0ffffffff );
150
151
152    for ( blockstart=0; blockstart<word_array.length; blockstart+=16 ) {
153
154        for( i=0; i<16; i++ ) W[i] = word_array[blockstart+i];
155        for( i=16; i<=79; i++ ) W[i] = rotate_left(W[i-3] ^ W[i-8] ^ W[i-14] ^ W[i-16], 1);
156
157        A = H0;
158        B = H1;
159        C = H2;
160        D = H3;
161        E = H4;
162
163        for( i= 0; i<=19; i++ ) {
164            temp = (rotate_left(A,5) + ((B&C) | (~B&D)) + E + W[i] + 0x5A827999) & 0x0ffffffff;
165            E = D;
166            D = C;
167            C = rotate_left(B,30);
168            B = A;
169            A = temp;
170        }
171
172        for( i=20; i<=39; i++ ) {
173            temp = (rotate_left(A,5) + (B ^ C ^ D) + E + W[i] + 0x6ED9EBA1) & 0x0ffffffff;
174            E = D;
175            D = C;
176            C = rotate_left(B,30);
177            B = A;
178            A = temp;
179        }
180
181        for( i=40; i<=59; i++ ) {
182            temp = (rotate_left(A,5) + ((B&C) | (B&D) | (C&D)) + E + W[i] + 0x8F1BBCDC) & 0x0ffffffff;
183            E = D;
184            D = C;
185            C = rotate_left(B,30);
186            B = A;
187            A = temp;
188        }
189
190        for( i=60; i<=79; i++ ) {
191            temp = (rotate_left(A,5) + (B ^ C ^ D) + E + W[i] + 0xCA62C1D6) & 0x0ffffffff;
192            E = D;
193            D = C;
194            C = rotate_left(B,30);
195            B = A;
196            A = temp;
197        }
198
199        H0 = (H0 + A) & 0x0ffffffff;
200        H1 = (H1 + B) & 0x0ffffffff;
201        H2 = (H2 + C) & 0x0ffffffff;
202        H3 = (H3 + D) & 0x0ffffffff;
203        H4 = (H4 + E) & 0x0ffffffff;
204
205    }
206
207    var temp = cvt_hex(H0) + cvt_hex(H1) + cvt_hex(H2) + cvt_hex(H3) + cvt_hex(H4);
208
209    return temp.toLowerCase();
210
211}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.