Advertisement
Guest User

SHA512 in GameMaker

a guest
Mar 8th, 2014
541
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ///sha512_calc(message)
  2. //Geschreven door Size43
  3.  
  4. var bitlength, binb, add1, add2, add3, add4, binb, j, i, binb_length, _sha512, hex, output;
  5. for(i = 750; i > 351; i -= 1)
  6. {
  7.     _sha512[i] = $0000;
  8. }
  9.  
  10. _sha512[0] = $428a;_sha512[1] = $2f98;_sha512[2] = $d728;_sha512[3] = $ae22;_sha512[4] = $7137;_sha512[5] = $4491;_sha512[6] = $23ef;_sha512[7] = $65cd;_sha512[8] = $b5c0;_sha512[9] = $fbcf;_sha512[10] = $ec4d;_sha512[11] = $3b2f;_sha512[12] = $e9b5;_sha512[13] = $dba5;_sha512[14] = $8189;_sha512[15] = $dbbc;_sha512[16] = $3956;_sha512[17] = $c25b;_sha512[18] = $f348;_sha512[19] = $b538;_sha512[20] = $59f1;_sha512[21] = $11f1;_sha512[22] = $b605;_sha512[23] = $d019;_sha512[24] = $923f;_sha512[25] = $82a4;_sha512[26] = $af19;_sha512[27] = $4f9b;_sha512[28] = $ab1c;_sha512[29] = $5ed5;_sha512[30] = $da6d;_sha512[31] = $8118;_sha512[32] = $d807;_sha512[33] = $aa98;_sha512[34] = $a303;_sha512[35] = $0242;_sha512[36] = $1283;_sha512[37] = $5b01;_sha512[38] = $4570;_sha512[39] = $6fbe;_sha512[40] = $2431;_sha512[41] = $85be;_sha512[42] = $4ee4;_sha512[43] = $b28c;_sha512[44] = $550c;_sha512[45] = $7dc3;_sha512[46] = $d5ff;_sha512[47] = $b4e2;_sha512[48] = $72be;_sha512[49] = $5d74;_sha512[50] = $f27b;_sha512[51] = $896f;_sha512[52] = $80de;_sha512[53] = $b1fe;_sha512[54] = $3b16;_sha512[55] = $96b1;_sha512[56] = $9bdc;_sha512[57] = $06a7;_sha512[58] = $25c7;_sha512[59] = $1235;_sha512[60] = $c19b;_sha512[61] = $f174;_sha512[62] = $cf69;_sha512[63] = $2694;_sha512[64] = $e49b;_sha512[65] = $69c1;_sha512[66] = $9ef1;_sha512[67] = $4ad2;_sha512[68] = $efbe;_sha512[69] = $4786;_sha512[70] = $384f;_sha512[71] = $25e3;_sha512[72] = $0fc1;_sha512[73] = $9dc6;_sha512[74] = $8b8c;_sha512[75] = $d5b5;_sha512[76] = $240c;_sha512[77] = $a1cc;_sha512[78] = $77ac;_sha512[79] = $9c65;_sha512[80] = $2de9;_sha512[81] = $2c6f;_sha512[82] = $592b;_sha512[83] = $0275;_sha512[84] = $4a74;_sha512[85] = $84aa;_sha512[86] = $6ea6;_sha512[87] = $e483;_sha512[88] = $5cb0;_sha512[89] = $a9dc;_sha512[90] = $bd41;_sha512[91] = $fbd4;_sha512[92] = $76f9;_sha512[93] = $88da;_sha512[94] = $8311;_sha512[95] = $53b5;_sha512[96] = $983e;_sha512[97] = $5152;_sha512[98] = $ee66;_sha512[99] = $dfab;_sha512[100] = $a831;_sha512[101] = $c66d;_sha512[102] = $2db4;_sha512[103] = $3210;_sha512[104] = $b003;_sha512[105] = $27c8;_sha512[106] = $98fb;_sha512[107] = $213f;_sha512[108] = $bf59;_sha512[109] = $7fc7;_sha512[110] = $beef;_sha512[111] = $0ee4;_sha512[112] = $c6e0;_sha512[113] = $0bf3;_sha512[114] = $3da8;_sha512[115] = $8fc2;_sha512[116] = $d5a7;_sha512[117] = $9147;_sha512[118] = $930a;_sha512[119] = $a725;_sha512[120] = $06ca;_sha512[121] = $6351;_sha512[122] = $e003;_sha512[123] = $826f;_sha512[124] = $1429;_sha512[125] = $2967;_sha512[126] = $0a0e;_sha512[127] = $6e70;_sha512[128] = $27b7;_sha512[129] = $0a85;_sha512[130] = $46d2;_sha512[131] = $2ffc;_sha512[132] = $2e1b;_sha512[133] = $2138;_sha512[134] = $5c26;_sha512[135] = $c926;_sha512[136] = $4d2c;_sha512[137] = $6dfc;_sha512[138] = $5ac4;_sha512[139] = $2aed;_sha512[140] = $5338;_sha512[141] = $0d13;_sha512[142] = $9d95;_sha512[143] = $b3df;_sha512[144] = $650a;_sha512[145] = $7354;_sha512[146] = $8baf;_sha512[147] = $63de;_sha512[148] = $766a;_sha512[149] = $0abb;_sha512[150] = $3c77;_sha512[151] = $b2a8;_sha512[152] = $81c2;_sha512[153] = $c92e;_sha512[154] = $47ed;_sha512[155] = $aee6;_sha512[156] = $9272;_sha512[157] = $2c85;_sha512[158] = $1482;_sha512[159] = $353b;_sha512[160] = $a2bf;_sha512[161] = $e8a1;_sha512[162] = $4cf1;_sha512[163] = $0364;_sha512[164] = $a81a;_sha512[165] = $664b;_sha512[166] = $bc42;_sha512[167] = $3001;_sha512[168] = $c24b;_sha512[169] = $8b70;_sha512[170] = $d0f8;_sha512[171] = $9791;_sha512[172] = $c76c;_sha512[173] = $51a3;_sha512[174] = $0654;_sha512[175] = $be30;_sha512[176] = $d192;_sha512[177] = $e819;_sha512[178] = $d6ef;_sha512[179] = $5218;_sha512[180] = $d699;_sha512[181] = $0624;_sha512[182] = $5565;_sha512[183] = $a910;_sha512[184] = $f40e;_sha512[185] = $3585;_sha512[186] = $5771;_sha512[187] = $202a;_sha512[188] = $106a;_sha512[189] = $a070;_sha512[190] = $32bb;_sha512[191] = $d1b8;_sha512[192] = $19a4;_sha512[193] = $c116;_sha512[194] = $b8d2;_sha512[195] = $d0c8;_sha512[196] = $1e37;_sha512[197] = $6c08;_sha512[198] = $5141;_sha512[199] = $ab53;_sha512[200] = $2748;_sha512[201] = $774c;_sha512[202] = $df8e;_sha512[203] = $eb99;_sha512[204] = $34b0;_sha512[205] = $bcb5;_sha512[206] = $e19b;_sha512[207] = $48a8;_sha512[208] = $391c;_sha512[209] = $0cb3;_sha512[210] = $c5c9;_sha512[211] = $5a63;_sha512[212] = $4ed8;_sha512[213] = $aa4a;_sha512[214] = $e341;_sha512[215] = $8acb;_sha512[216] = $5b9c;_sha512[217] = $ca4f;_sha512[218] = $7763;_sha512[219] = $e373;_sha512[220] = $682e;_sha512[221] = $6ff3;_sha512[222] = $d6b2;_sha512[223] = $b8a3;_sha512[224] = $748f;_sha512[225] = $82ee;_sha512[226] = $5def;_sha512[227] = $b2fc;_sha512[228] = $78a5;_sha512[229] = $636f;_sha512[230] = $4317;_sha512[231] = $2f60;_sha512[232] = $84c8;_sha512[233] = $7814;_sha512[234] = $a1f0;_sha512[235] = $ab72;_sha512[236] = $8cc7;_sha512[237] = $0208;_sha512[238] = $1a64;_sha512[239] = $39ec;_sha512[240] = $90be;_sha512[241] = $fffa;_sha512[242] = $2363;_sha512[243] = $1e28;_sha512[244] = $a450;_sha512[245] = $6ceb;_sha512[246] = $de82;_sha512[247] = $bde9;_sha512[248] = $bef9;_sha512[249] = $a3f7;_sha512[250] = $b2c6;_sha512[251] = $7915;_sha512[252] = $c671;_sha512[253] = $78f2;_sha512[254] = $e372;_sha512[255] = $532b;_sha512[256] = $ca27;_sha512[257] = $3ece;_sha512[258] = $ea26;_sha512[259] = $619c;_sha512[260] = $d186;_sha512[261] = $b8c7;_sha512[262] = $21c0;_sha512[263] = $c207;_sha512[264] = $eada;_sha512[265] = $7dd6;_sha512[266] = $cde0;_sha512[267] = $eb1e;_sha512[268] = $f57d;_sha512[269] = $4f7f;_sha512[270] = $ee6e;_sha512[271] = $d178;_sha512[272] = $06f0;_sha512[273] = $67aa;_sha512[274] = $7217;_sha512[275] = $6fba;_sha512[276] = $0a63;_sha512[277] = $7dc5;_sha512[278] = $a2c8;_sha512[279] = $98a6;_sha512[280] = $113f;_sha512[281] = $9804;_sha512[282] = $bef9;_sha512[283] = $0dae;_sha512[284] = $1b71;_sha512[285] = $0b35;_sha512[286] = $131c;_sha512[287] = $471b;_sha512[288] = $28db;_sha512[289] = $77f5;_sha512[290] = $2304;_sha512[291] = $7d84;_sha512[292] = $32ca;_sha512[293] = $ab7b;_sha512[294] = $40c7;_sha512[295] = $2493;_sha512[296] = $3c9e;_sha512[297] = $be0a;_sha512[298] = $15c9;_sha512[299] = $bebc;_sha512[300] = $431d;_sha512[301] = $67c4;_sha512[302] = $9c10;_sha512[303] = $0d4c;_sha512[304] = $4cc5;_sha512[305] = $d4be;_sha512[306] = $cb3e;_sha512[307] = $42b6;_sha512[308] = $597f;_sha512[309] = $299c;_sha512[310] = $fc65;_sha512[311] = $7e2a;_sha512[312] = $5fcb;_sha512[313] = $6fab;_sha512[314] = $3ad6;_sha512[315] = $faec;_sha512[316] = $6c44;_sha512[317] = $198c;_sha512[318] = $4a47;_sha512[319] = $5817;_sha512[320] = $6a09;_sha512[321] = $e667;_sha512[322] = $f3bc;_sha512[323] = $c908;_sha512[324] = $bb67;_sha512[325] = $ae85;_sha512[326] = $84ca;_sha512[327] = $a73b;_sha512[328] = $3c6e;_sha512[329] = $f372;_sha512[330] = $fe94;_sha512[331] = $f82b;_sha512[332] = $a54f;_sha512[333] = $f53a;_sha512[334] = $5f1d;_sha512[335] = $36f1;_sha512[336] = $510e;_sha512[337] = $527f;_sha512[338] = $ade6;_sha512[339] = $82d1;_sha512[340] = $9b05;_sha512[341] = $688c;_sha512[342] = $2b3e;_sha512[343] = $6c1f;_sha512[344] = $1f83;_sha512[345] = $d9ab;_sha512[346] = $fb41;_sha512[347] = $bd6b;_sha512[348] = $5be0;_sha512[349] = $cd19;_sha512[350] = $137e;_sha512[351] = $2179;
  11.  
  12. bitlength = string_length(argument0) * 8
  13.  
  14. //Convert to big-endian
  15. for (i = 0; i < string_length(argument0); i += 1)
  16. {
  17.     if(i mod 2 == 0)
  18.     {
  19.         //High byte
  20.         binb[floor(i / 2)] = (ord(string_char_at(argument0, i + 1)) & $ff) << 8;
  21.     }else{
  22.         //Low byte
  23.         binb[floor(i / 2)] |= ord(string_char_at(argument0, i + 1)) & $ff;
  24.     }
  25. }
  26.  
  27. if(i mod 2 == 0)
  28. {
  29.     //High byte
  30.     binb[floor(i / 2)] = $80 << 8;
  31. }else{
  32.     //Low byte
  33.     binb[floor(i / 2)] |= $80;
  34. }
  35.  
  36. //append padding to the source string. The format is described in the FIPS.
  37. binb_length = ((((bitlength + 128) >> 10) + 1) << 6);
  38.  
  39. binb[binb_length - 1] = bitlength & $ffff;
  40. binb[binb_length - 2] = (bitlength >> 16) & $ffff;
  41.  
  42. for (i = 0; i < (binb_length / 2); i += 32) //32 dwords is the block size
  43. {
  44.     _sha512[ 360] = _sha512[320]; _sha512[ 360 + 1] = _sha512[320 + 1]; _sha512[ 360 + 2] = _sha512[320 + 2]; _sha512[ 360 + 3] = _sha512[320 + 3];;
  45.     _sha512[364] = _sha512[324]; _sha512[ 364  + 1] = _sha512[324 + 1]; _sha512[ 364  + 2] = _sha512[324 + 2]; _sha512[ 364  + 3] = _sha512[324 + 3];;
  46.     _sha512[368] = _sha512[328]; _sha512[ 368  + 1] = _sha512[328 + 1]; _sha512[ 368  + 2] = _sha512[328 + 2]; _sha512[ 368  + 3] = _sha512[328 + 3];;
  47.     _sha512[372] = _sha512[332]; _sha512[ 372  + 1] = _sha512[332 + 1]; _sha512[ 372  + 2] = _sha512[332 + 2]; _sha512[ 372  + 3] = _sha512[332 + 3];;
  48.     _sha512[376] = _sha512[336]; _sha512[ 376  + 1] = _sha512[336 + 1]; _sha512[ 376  + 2] = _sha512[336 + 2]; _sha512[ 376  + 3] = _sha512[336 + 3];;
  49.     _sha512[380] = _sha512[340]; _sha512[ 380  + 1] = _sha512[340 + 1]; _sha512[ 380  + 2] = _sha512[340 + 2]; _sha512[ 380  + 3] = _sha512[340 + 3];;
  50.     _sha512[384] = _sha512[344]; _sha512[ 384  + 1] = _sha512[344 + 1]; _sha512[ 384  + 2] = _sha512[344 + 2]; _sha512[ 384  + 3] = _sha512[344 + 3];;
  51.     _sha512[388] = _sha512[348]; _sha512[ 388  + 1] = _sha512[348 + 1]; _sha512[ 388  + 2] = _sha512[348 + 2]; _sha512[ 388  + 3] = _sha512[348 + 3];;
  52.  
  53.     for (j = 0; j < 16; j += 1)
  54.     {
  55.         _sha512[(420 + (j) * 4)] = binb[(i + 2 * j) * 2]; _sha512[(420 + (j) * 4) + 1] = binb[(i + 2 * j) * 2 + 1]; _sha512[(420 + (j) * 4) + 2] = binb[(i + 2 * j + 1) * 2]; _sha512[(420 + (j) * 4) + 3] = binb[(i + 2 * j + 1) * 2 + 1];;
  56.     }
  57.    
  58.     for (j = 16; j < 80; j += 1)
  59.     {
  60.         //sigma1
  61.         //rrot(408, (420 + (j - 2) * 4), 19);
  62.             //Shift 16
  63.             add2 = (420 + (j - 2) * 4)
  64.             add1 = _sha512[add2 + 3];
  65.             _sha512[408 + 3] = _sha512[add2 + 2]
  66.             _sha512[408 + 2] = _sha512[add2 + 1]
  67.             _sha512[408 + 1] = _sha512[add2 + 0]
  68.             _sha512[408 + 0] = add1
  69.            
  70.             //Shift 3
  71.             add1 = _sha512[408 + 3];
  72.             _sha512[408 + 3] = (_sha512[408 + 3] >> 3) | ((_sha512[408 + 2] << 13) & $ffff)
  73.             _sha512[408 + 2] = (_sha512[408 + 2] >> 3) | ((_sha512[408 + 1] << 13) & $ffff)
  74.             _sha512[408 + 1] = (_sha512[408 + 1] >> 3) | ((_sha512[408 + 0] << 13) & $ffff)
  75.             _sha512[408 + 0] = (_sha512[408 + 0] >> 3) | ((add1 << 13) & $ffff)
  76.            
  77.            
  78.         //rrot(412, (420 + (j - 2) * 4), 32 + 29);
  79.             add2 = (420 + (j - 2) * 4);
  80.             //Shift 48
  81.             add1 = _sha512[add2 + 0];
  82.             _sha512[412 + 0] = _sha512[add2 + 1]
  83.             _sha512[412 + 1] = _sha512[add2 + 2]
  84.             _sha512[412 + 2] = _sha512[add2 + 3]
  85.             _sha512[412 + 3] = add1
  86.            
  87.             //Shift 13
  88.             add1 = _sha512[412 + 3];
  89.             _sha512[412 + 3] = (_sha512[412 + 3] >> 13) | ((_sha512[412 + 2] << 3) & $ffff)
  90.             _sha512[412 + 2] = (_sha512[412 + 2] >> 13) | ((_sha512[412 + 1] << 3) & $ffff)
  91.             _sha512[412 + 1] = (_sha512[412 + 1] >> 13) | ((_sha512[412 + 0] << 3) & $ffff)
  92.             _sha512[412 + 0] = (_sha512[412 + 0] >> 13) | ((add1 << 3) & $ffff)
  93.        
  94.         //shr(416, (420 + (j - 2) * 4), 6);
  95.             //Shift 6
  96.             //add2 = (420 + (j - 2) * 4);
  97.             _sha512[416 + 3] = (_sha512[add2 + 3] >> 6) | ((_sha512[add2 + 2] << 10) & $ffff)
  98.             _sha512[416 + 2] = (_sha512[add2 + 2] >> 6) | ((_sha512[add2 + 1] << 10) & $ffff)
  99.             _sha512[416 + 1] = (_sha512[add2 + 1] >> 6) | ((_sha512[add2 + 0] << 10) & $ffff)
  100.             _sha512[416 + 0] = (_sha512[add2 + 0] >> 6)
  101.         _sha512[396] = _sha512[408] ^ _sha512[412] ^ _sha512[416]; _sha512[396 + 1] = _sha512[408 + 1] ^ _sha512[412 + 1] ^ _sha512[416 + 1]; _sha512[396 + 2] = _sha512[408 + 2] ^ _sha512[412 + 2] ^ _sha512[416 + 2]; _sha512[396 + 3] = _sha512[408 + 3] ^ _sha512[412 + 3] ^ _sha512[416 + 3];;
  102.        
  103.         //sigma0
  104.         //rrot(408, (420 + (j - 15) * 4), 1);
  105.             //Shift 1
  106.             add2 = (420 + (j - 15) * 4);
  107.             add1 = _sha512[add2 + 3];
  108.             _sha512[408 + 3] = (_sha512[add2 + 3] >> 1) | ((_sha512[add2 + 2] << 15) & $ffff)
  109.             _sha512[408 + 2] = (_sha512[add2 + 2] >> 1) | ((_sha512[add2 + 1] << 15) & $ffff)
  110.             _sha512[408 + 1] = (_sha512[add2 + 1] >> 1) | ((_sha512[add2 + 0] << 15) & $ffff)
  111.             _sha512[408 + 0] = (_sha512[add2 + 0] >> 1) | ((add1 << 15) & $ffff)
  112.            
  113.         //rrot(412, (420 + (j - 15) * 4), 8);
  114.             //Shift 8
  115.             //add2 = (420 + (j - 15) * 4)
  116.             add1 = _sha512[add2 + 3];
  117.             _sha512[412 + 3] = (_sha512[add2 + 3] >> 8) | ((_sha512[add2 + 2] << 8) & $ffff)
  118.             _sha512[412 + 2] = (_sha512[add2 + 2] >> 8) | ((_sha512[add2 + 1] << 8) & $ffff)
  119.             _sha512[412 + 1] = (_sha512[add2 + 1] >> 8) | ((_sha512[add2 + 0] << 8) & $ffff)
  120.             _sha512[412 + 0] = (_sha512[add2 + 0] >> 8) | ((add1 << 8) & $ffff)
  121.        
  122.        
  123.         //shr(416, (420 + (j - 15) * 4), 7);
  124.             //Shift 6
  125.             //add2 = (420 + (j - 15) * 4);
  126.             _sha512[416 + 3] = (_sha512[add2 + 3] >> 7) | ((_sha512[add2 + 2] << 9) & $ffff)
  127.             _sha512[416 + 2] = (_sha512[add2 + 2] >> 7) | ((_sha512[add2 + 1] << 9) & $ffff)
  128.             _sha512[416 + 1] = (_sha512[add2 + 1] >> 7) | ((_sha512[add2 + 0] << 9) & $ffff)
  129.             _sha512[416 + 0] = (_sha512[add2 + 0] >> 7)
  130.        
  131.         _sha512[392] = _sha512[408] ^ _sha512[412] ^ _sha512[416]; _sha512[392 + 1] = _sha512[408 + 1] ^ _sha512[412 + 1] ^ _sha512[416 + 1]; _sha512[392 + 2] = _sha512[408 + 2] ^ _sha512[412 + 2] ^ _sha512[416 + 2]; _sha512[392 + 3] = _sha512[408 + 3] ^ _sha512[412 + 3] ^ _sha512[416 + 3];;
  132.        
  133.         add1 = _sha512[396 + 3] + _sha512[(420 + (j - 7) * 4) + 3] + _sha512[392 + 3] + _sha512[(420 + (j - 16) * 4) + 3]; add2 = _sha512[396 + 2] + _sha512[(420 + (j - 7) * 4) + 2] + _sha512[392 + 2] + _sha512[(420 + (j - 16) * 4) + 2] + (add1 >> 16); add3 = _sha512[396 + 1] + _sha512[(420 + (j - 7) * 4) + 1] + _sha512[392 + 1] + _sha512[(420 + (j - 16) * 4) + 1] + (add2 >> 16); add4 = _sha512[396] + _sha512[(420 + (j - 7) * 4)] + _sha512[392] + _sha512[(420 + (j - 16) * 4)] + (add3 >> 16); _sha512[(420 + (j) * 4) + 3] = add1 & $00ffff; _sha512[(420 + (j) * 4) + 2] = add2 & $00ffff; _sha512[(420 + (j) * 4) + 1] = add3 & $00ffff; _sha512[(420 + (j) * 4)] = add4 & $00ffff;
  134.     }
  135.    
  136.     for (j = 0; j < 80; j += 1)
  137.     {
  138.         //400
  139.         _sha512[400 + 3] = (_sha512[ 376  + 3] & _sha512[ 380  + 3]) ^ (~_sha512[ 376  + 3] & _sha512[ 384  + 3]);
  140.         _sha512[400 + 2] = (_sha512[ 376  + 2] & _sha512[ 380  + 2]) ^ (~_sha512[ 376  + 2] & _sha512[ 384  + 2]);
  141.         _sha512[400 + 1] = (_sha512[ 376  + 1] & _sha512[ 380  + 1]) ^ (~_sha512[ 376  + 1] & _sha512[ 384  + 1]);
  142.         _sha512[400] = (_sha512[376] & _sha512[380]) ^ (~_sha512[376] & _sha512[384]);
  143.        
  144.         //Sigma1
  145.         //rrot(408, 376, 14);
  146.             //Shift 14
  147.             add1 = _sha512[376 + 3];
  148.             _sha512[408 + 3] = (_sha512[376 + 3] >> 14) | ((_sha512[376 + 2] << 2) & $ffff)
  149.             _sha512[408 + 2] = (_sha512[376 + 2] >> 14) | ((_sha512[376 + 1] << 2) & $ffff)
  150.             _sha512[408 + 1] = (_sha512[376 + 1] >> 14) | ((_sha512[376 + 0] << 2) & $ffff)
  151.             _sha512[408 + 0] = (_sha512[376 + 0] >> 14) | ((add1 << 2) & $ffff)
  152.        
  153.        
  154.         //rrot(412, 376, 18);
  155.             //Shift 16
  156.             add1 = _sha512[376 + 3];
  157.             _sha512[412 + 3] = _sha512[376 + 2]
  158.             _sha512[412 + 2] = _sha512[376 + 1]
  159.             _sha512[412 + 1] = _sha512[376 + 0]
  160.             _sha512[412 + 0] = add1
  161.            
  162.             //Shift 2
  163.             add1 = _sha512[412 + 3];
  164.             _sha512[412 + 3] = (_sha512[412 + 3] >> 2) | ((_sha512[412 + 2] << 14) & $ffff)
  165.             _sha512[412 + 2] = (_sha512[412 + 2] >> 2) | ((_sha512[412 + 1] << 14) & $ffff)
  166.             _sha512[412 + 1] = (_sha512[412 + 1] >> 2) | ((_sha512[412 + 0] << 14) & $ffff)
  167.             _sha512[412 + 0] = (_sha512[412 + 0] >> 2) | ((add1 << 14) & $ffff)
  168.        
  169.         //rrot(416, 376, 32 + 9);
  170.             //Shift 32
  171.             add1 = _sha512[376 + 1];
  172.             add2 = _sha512[376 + 2];
  173.             _sha512[416 + 1] = _sha512[376 + 3]
  174.             _sha512[416 + 2] = _sha512[376 + 0]
  175.             _sha512[416 + 3] = add1;
  176.             _sha512[416 + 0] = add2;
  177.            
  178.             //Shift 9
  179.             add1 = _sha512[416 + 3];
  180.             _sha512[416 + 3] = (_sha512[416 + 3] >> 9) | ((_sha512[416 + 2] << 7) & $ffff)
  181.             _sha512[416 + 2] = (_sha512[416 + 2] >> 9) | ((_sha512[416 + 1] << 7) & $ffff)
  182.             _sha512[416 + 1] = (_sha512[416 + 1] >> 9) | ((_sha512[416 + 0] << 7) & $ffff)
  183.             _sha512[416 + 0] = (_sha512[416 + 0] >> 9) | ((add1 << 7) & $ffff)
  184.        
  185.         //xor3
  186.         _sha512[396] = _sha512[408] ^ _sha512[412] ^ _sha512[416]; _sha512[396 + 1] = _sha512[408 + 1] ^ _sha512[412 + 1] ^ _sha512[416 + 1]; _sha512[396 + 2] = _sha512[408 + 2] ^ _sha512[412 + 2] ^ _sha512[416 + 2]; _sha512[396 + 3] = _sha512[408 + 3] ^ _sha512[412 + 3] ^ _sha512[416 + 3];;
  187.        
  188.         //Sigma0
  189.         //rrot(408,  360, 28);
  190.             //Shift 12
  191.             add1 = _sha512[360 + 3];
  192.             _sha512[408 + 3] = (_sha512[360 + 3] >> 12) | ((_sha512[360 + 2] << 4) & $ffff)
  193.             _sha512[408 + 2] = (_sha512[360 + 2] >> 12) | ((_sha512[360 + 1] << 4) & $ffff)
  194.             _sha512[408 + 1] = (_sha512[360 + 1] >> 12) | ((_sha512[360 + 0] << 4) & $ffff)
  195.             _sha512[408 + 0] = (_sha512[360 + 0] >> 12) | ((add1 << 4) & $ffff)
  196.            
  197.             //Shift 16
  198.             add1 = _sha512[408 + 3];
  199.             _sha512[408 + 3] = _sha512[408 + 2]
  200.             _sha512[408 + 2] = _sha512[408 + 1]
  201.             _sha512[408 + 1] = _sha512[408 + 0]
  202.             _sha512[408 + 0] = add1
  203.        
  204.        
  205.         //rrot(412,  360, 32 + 2);
  206.             //Shift 32
  207.             add1 = _sha512[360 + 1];
  208.             add2 = _sha512[360 + 2];
  209.             _sha512[412 + 1] = _sha512[360 + 3]
  210.             _sha512[412 + 2] = _sha512[360 + 0]
  211.             _sha512[412 + 3] = add1
  212.             _sha512[412 + 0] = add2
  213.            
  214.             //Shift 2
  215.             add1 = _sha512[412 + 3];
  216.             _sha512[412 + 3] = (_sha512[412 + 3] >> 2) | ((_sha512[412 + 2] << 14) & $ffff)
  217.             _sha512[412 + 2] = (_sha512[412 + 2] >> 2) | ((_sha512[412 + 1] << 14) & $ffff)
  218.             _sha512[412 + 1] = (_sha512[412 + 1] >> 2) | ((_sha512[412 + 0] << 14) & $ffff)
  219.             _sha512[412 + 0] = (_sha512[412 + 0] >> 2) | ((add1 << 14) & $ffff)
  220.        
  221.        
  222.         //rrot(416,  360, 32 + 7);
  223.             //Shift 32
  224.             add1 = _sha512[360 + 1];
  225.             add2 = _sha512[360 + 2];
  226.             _sha512[416 + 1] = _sha512[360 + 3]
  227.             _sha512[416 + 2] = _sha512[360 + 0]
  228.             _sha512[416 + 3] = add1
  229.             _sha512[416 + 0] = add2
  230.            
  231.             //Shift 7
  232.             add1 = _sha512[416 + 3];
  233.             _sha512[416 + 3] = (_sha512[416 + 3] >> 7) | ((_sha512[416 + 2] << 9) & $ffff)
  234.             _sha512[416 + 2] = (_sha512[416 + 2] >> 7) | ((_sha512[416 + 1] << 9) & $ffff)
  235.             _sha512[416 + 1] = (_sha512[416 + 1] >> 7) | ((_sha512[416 + 0] << 9) & $ffff)
  236.             _sha512[416 + 0] = (_sha512[416 + 0] >> 7) | ((add1 << 9) & $ffff)
  237.            
  238.        
  239.         _sha512[392] = _sha512[408] ^ _sha512[412] ^ _sha512[416]; _sha512[392 + 1] = _sha512[408 + 1] ^ _sha512[412 + 1] ^ _sha512[416 + 1]; _sha512[392 + 2] = _sha512[408 + 2] ^ _sha512[412 + 2] ^ _sha512[416 + 2]; _sha512[392 + 3] = _sha512[408 + 3] ^ _sha512[412 + 3] ^ _sha512[416 + 3];;
  240.        
  241.         //404
  242.         _sha512[404 + 3] = (_sha512[ 360 + 3] & _sha512[ 364  + 3]) ^ (_sha512[ 360 + 3] & _sha512[ 368  + 3]) ^ (_sha512[ 364  + 3] & _sha512[ 368  + 3]);
  243.         _sha512[404 + 2] = (_sha512[ 360 + 2] & _sha512[ 364  + 2]) ^ (_sha512[ 360 + 2] & _sha512[ 368  + 2]) ^ (_sha512[ 364  + 2] & _sha512[ 368  + 2]);
  244.         _sha512[404 + 1] = (_sha512[ 360 + 1] & _sha512[ 364  + 1]) ^ (_sha512[ 360 + 1] & _sha512[ 368  + 1]) ^ (_sha512[ 364  + 1] & _sha512[ 368  + 1]);
  245.         _sha512[404] = (_sha512[ 360] & _sha512[364]) ^ (_sha512[ 360] & _sha512[368]) ^ (_sha512[364] & _sha512[368]);
  246.        
  247.         //j * 4 = k[j]
  248.         add1 = _sha512[388 + 3] + _sha512[396 + 3] + _sha512[400 + 3] + _sha512[j * 4 + 3] + _sha512[(420 + (j) * 4) + 3]; add2 = _sha512[388 + 2] + _sha512[396 + 2] + _sha512[400 + 2] + _sha512[j * 4 + 2] + _sha512[(420 + (j) * 4) + 2] + (add1 >> 16); add3 = _sha512[388 + 1] + _sha512[396 + 1] + _sha512[400 + 1] + _sha512[j * 4 + 1] + _sha512[(420 + (j) * 4) + 1] + (add2 >> 16); add4 = _sha512[388] + _sha512[396] + _sha512[400] + _sha512[j * 4] + _sha512[(420 + (j) * 4)] + (add3 >> 16); _sha512[352 + 3] = add1 & $00ffff; _sha512[352 + 2] = add2 & $00ffff; _sha512[352 + 1] = add3 & $00ffff; _sha512[352] = add4 & $00ffff;
  249.        
  250.         add1 = _sha512[392 + 3] + _sha512[404 + 3]; add2 = _sha512[392 + 2] + _sha512[404 + 2] + (add1 >> 16); add3 = _sha512[392 + 1] + _sha512[404 + 1] + (add2 >> 16); add4 = _sha512[392] + _sha512[404] + (add3 >> 16); _sha512[356 + 3] = add1 & $00ffff; _sha512[356 + 2] = add2 & $00ffff; _sha512[356 + 1] = add3 & $00ffff; _sha512[356] = add4 & $00ffff;
  251.        
  252.         _sha512[388] = _sha512[384]; _sha512[ 388  + 1] = _sha512[ 384  + 1]; _sha512[ 388  + 2] = _sha512[ 384  + 2]; _sha512[ 388  + 3] = _sha512[ 384  + 3];;
  253.         _sha512[384] = _sha512[380]; _sha512[ 384  + 1] = _sha512[ 380  + 1]; _sha512[ 384  + 2] = _sha512[ 380  + 2]; _sha512[ 384  + 3] = _sha512[ 380  + 3];;
  254.         _sha512[380] = _sha512[376]; _sha512[ 380  + 1] = _sha512[ 376  + 1]; _sha512[ 380  + 2] = _sha512[ 376  + 2]; _sha512[ 380  + 3] = _sha512[ 376  + 3];;
  255.         add1 = _sha512[372 + 3] + _sha512[352 + 3]; add2 = _sha512[372 + 2] + _sha512[352 + 2] + (add1 >> 16); add3 = _sha512[372 + 1] + _sha512[352 + 1] + (add2 >> 16); add4 = _sha512[372] + _sha512[352] + (add3 >> 16); _sha512[376 + 3] = add1 & $00ffff; _sha512[376 + 2] = add2 & $00ffff; _sha512[376 + 1] = add3 & $00ffff; _sha512[376] = add4 & $00ffff;
  256.  
  257.         _sha512[372] = _sha512[368]; _sha512[ 372  + 1] = _sha512[ 368  + 1]; _sha512[ 372  + 2] = _sha512[ 368  + 2]; _sha512[ 372  + 3] = _sha512[ 368  + 3];;
  258.         _sha512[368] = _sha512[364]; _sha512[ 368  + 1] = _sha512[ 364  + 1]; _sha512[ 368  + 2] = _sha512[ 364  + 2]; _sha512[ 368  + 3] = _sha512[ 364  + 3];;
  259.         _sha512[364] = _sha512[ 360]; _sha512[ 364  + 1] = _sha512[ 360 + 1]; _sha512[ 364  + 2] = _sha512[ 360 + 2]; _sha512[ 364  + 3] = _sha512[ 360 + 3];;
  260.         add1 = _sha512[352 + 3] + _sha512[356 + 3]; add2 = _sha512[352 + 2] + _sha512[356 + 2] + (add1 >> 16); add3 = _sha512[352 + 1] + _sha512[356 + 1] + (add2 >> 16); add4 = _sha512[352] + _sha512[356] + (add3 >> 16); _sha512[360 + 3] = add1 & $00ffff; _sha512[360 + 2] = add2 & $00ffff; _sha512[360 + 1] = add3 & $00ffff; _sha512[360] = add4 & $00ffff;
  261.     }
  262.    
  263.    
  264.     add1 = _sha512[320 + 3] + _sha512[ 360 + 3]; add2 = _sha512[320 + 2] + _sha512[ 360 + 2] + (add1 >> 16); add3 = _sha512[320 + 1] + _sha512[ 360 + 1] + (add2 >> 16); add4 = _sha512[320] + _sha512[ 360] + (add3 >> 16); _sha512[320 + 3] = add1 & $00ffff; _sha512[320 + 2] = add2 & $00ffff; _sha512[320 + 1] = add3 & $00ffff; _sha512[320] = add4 & $00ffff;
  265.     add1 = _sha512[324 + 3] + _sha512[ 364  + 3]; add2 = _sha512[324 + 2] + _sha512[ 364  + 2] + (add1 >> 16); add3 = _sha512[324 + 1] + _sha512[ 364  + 1] + (add2 >> 16); add4 = _sha512[324] + _sha512[ 364 ] + (add3 >> 16); _sha512[324 + 3] = add1 & $00ffff; _sha512[324 + 2] = add2 & $00ffff; _sha512[324 + 1] = add3 & $00ffff; _sha512[324] = add4 & $00ffff;
  266.     add1 = _sha512[328 + 3] + _sha512[ 368  + 3]; add2 = _sha512[328 + 2] + _sha512[ 368  + 2] + (add1 >> 16); add3 = _sha512[328 + 1] + _sha512[ 368  + 1] + (add2 >> 16); add4 = _sha512[328] + _sha512[ 368 ] + (add3 >> 16); _sha512[328 + 3] = add1 & $00ffff; _sha512[328 + 2] = add2 & $00ffff; _sha512[328 + 1] = add3 & $00ffff; _sha512[328] = add4 & $00ffff;
  267.     add1 = _sha512[332 + 3] + _sha512[ 372  + 3]; add2 = _sha512[332 + 2] + _sha512[ 372  + 2] + (add1 >> 16); add3 = _sha512[332 + 1] + _sha512[ 372  + 1] + (add2 >> 16); add4 = _sha512[332] + _sha512[ 372 ] + (add3 >> 16); _sha512[332 + 3] = add1 & $00ffff; _sha512[332 + 2] = add2 & $00ffff; _sha512[332 + 1] = add3 & $00ffff; _sha512[332] = add4 & $00ffff;
  268.     add1 = _sha512[336 + 3] + _sha512[ 376  + 3]; add2 = _sha512[336 + 2] + _sha512[ 376  + 2] + (add1 >> 16); add3 = _sha512[336 + 1] + _sha512[ 376  + 1] + (add2 >> 16); add4 = _sha512[336] + _sha512[ 376 ] + (add3 >> 16); _sha512[336 + 3] = add1 & $00ffff; _sha512[336 + 2] = add2 & $00ffff; _sha512[336 + 1] = add3 & $00ffff; _sha512[336] = add4 & $00ffff;
  269.     add1 = _sha512[340 + 3] + _sha512[ 380  + 3]; add2 = _sha512[340 + 2] + _sha512[ 380  + 2] + (add1 >> 16); add3 = _sha512[340 + 1] + _sha512[ 380  + 1] + (add2 >> 16); add4 = _sha512[340] + _sha512[ 380 ] + (add3 >> 16); _sha512[340 + 3] = add1 & $00ffff; _sha512[340 + 2] = add2 & $00ffff; _sha512[340 + 1] = add3 & $00ffff; _sha512[340] = add4 & $00ffff;
  270.     add1 = _sha512[344 + 3] + _sha512[ 384  + 3]; add2 = _sha512[344 + 2] + _sha512[ 384  + 2] + (add1 >> 16); add3 = _sha512[344 + 1] + _sha512[ 384  + 1] + (add2 >> 16); add4 = _sha512[344] + _sha512[ 384 ] + (add3 >> 16); _sha512[344 + 3] = add1 & $00ffff; _sha512[344 + 2] = add2 & $00ffff; _sha512[344 + 1] = add3 & $00ffff; _sha512[344] = add4 & $00ffff;
  271.     add1 = _sha512[348 + 3] + _sha512[ 388  + 3]; add2 = _sha512[348 + 2] + _sha512[ 388  + 2] + (add1 >> 16); add3 = _sha512[348 + 1] + _sha512[ 388  + 1] + (add2 >> 16); add4 = _sha512[348] + _sha512[ 388 ] + (add3 >> 16); _sha512[348 + 3] = add1 & $00ffff; _sha512[348 + 2] = add2 & $00ffff; _sha512[348 + 1] = add3 & $00ffff; _sha512[348] = add4 & $00ffff;
  272. }
  273.  
  274. //convert hash to hex string
  275. hex = "0123456789abcdef";
  276. output = "";
  277. for (i = 0; i < 8; i += 1)
  278. {
  279.     for(j = 0; j < 4 ; j += 1)
  280.     {
  281.         var b; b = _sha512[(320 + i * 4) + j];
  282.         output += string_char_at(hex, ((b >> 12) & $f) + 1) +
  283.                     string_char_at(hex, ((b >> 8) & $f) + 1) +
  284.                     string_char_at(hex, ((b >> 4) & $f) + 1) +
  285.                     string_char_at(hex, (b & $f) + 1);
  286.     }
  287. }
  288.  
  289. return output;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement