Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ExeBy/smexe_ro.../var/softacul.../lime5
File: sha256.php
<?php
[0] Fix | Delete
[1] Fix | Delete
[2] Fix | Delete
/*******************************************************************************
[3] Fix | Delete
*
[4] Fix | Delete
* SHA256 static class for PHP4
[5] Fix | Delete
* implemented by feyd _at_ devnetwork .dot. net
[6] Fix | Delete
* specification from http://csrc.nist.gov/cryptval/shs/sha256-384-512.pdf
[7] Fix | Delete
*
[8] Fix | Delete
* ? Copyright 2005 Developer's Network. All rights reserved.
[9] Fix | Delete
* This is licensed under the Lesser General Public License (LGPL)
[10] Fix | Delete
*
[11] Fix | Delete
* Thanks to CertainKey Inc. for providing some example outputs in Javascript
[12] Fix | Delete
*
[13] Fix | Delete
*----- Version 1.0.1 ----------------------------------------------------------
[14] Fix | Delete
*
[15] Fix | Delete
* Syntax:
[16] Fix | Delete
* string SHA256::hash( string message[, string format ])
[17] Fix | Delete
*
[18] Fix | Delete
* Description:
[19] Fix | Delete
* SHA256::hash() is a static function that must be called with `message`
[20] Fix | Delete
* and optionally `format`. Possible values for `format` are:
[21] Fix | Delete
* 'bin' binary string output
[22] Fix | Delete
* 'hex' default; hexidecimal string output (lower case)
[23] Fix | Delete
*
[24] Fix | Delete
* Failures return FALSE.
[25] Fix | Delete
*
[26] Fix | Delete
* Usage:
[27] Fix | Delete
* $hash = SHA256::hash('string to hash');
[28] Fix | Delete
*
[29] Fix | Delete
******************************************************************************/
[30] Fix | Delete
[31] Fix | Delete
[32] Fix | Delete
// hashing class state and storage object. Abstract base class only.
[33] Fix | Delete
class hashData
[34] Fix | Delete
{
[35] Fix | Delete
// final hash
[36] Fix | Delete
var $hash = null;
[37] Fix | Delete
}
[38] Fix | Delete
[39] Fix | Delete
[40] Fix | Delete
// hashing class. Abstract base class only.
[41] Fix | Delete
class hash
[42] Fix | Delete
{
[43] Fix | Delete
// The base modes are:
[44] Fix | Delete
// 'bin' - binary output (most compact)
[45] Fix | Delete
// 'bit' - bit output (largest)
[46] Fix | Delete
// 'oct' - octal output (medium-large)
[47] Fix | Delete
// 'hex' - hexidecimal (default, medium)
[48] Fix | Delete
[49] Fix | Delete
// perform a hash on a string
[50] Fix | Delete
function hash($str, $mode = 'hex')
[51] Fix | Delete
{
[52] Fix | Delete
trigger_error('hash::hash() NOT IMPLEMENTED', E_USER_WARNING);
[53] Fix | Delete
return false;
[54] Fix | Delete
}
[55] Fix | Delete
[56] Fix | Delete
// chop the resultant hash into $length byte chunks
[57] Fix | Delete
function hashChunk($str, $length, $mode = 'hex')
[58] Fix | Delete
{
[59] Fix | Delete
trigger_error('hash::hashChunk() NOT IMPLEMENTED', E_USER_WARNING);
[60] Fix | Delete
return false;
[61] Fix | Delete
}
[62] Fix | Delete
[63] Fix | Delete
// perform a hash on a file
[64] Fix | Delete
function hashFile($filename, $mode = 'hex')
[65] Fix | Delete
{
[66] Fix | Delete
trigger_error('hash::hashFile() NOT IMPLEMENTED', E_USER_WARNING);
[67] Fix | Delete
return false;
[68] Fix | Delete
}
[69] Fix | Delete
[70] Fix | Delete
// chop the resultant hash into $length byte chunks
[71] Fix | Delete
function hashChunkFile($filename, $length, $mode = 'hex')
[72] Fix | Delete
{
[73] Fix | Delete
trigger_error('hash::hashChunkFile() NOT IMPLEMENTED', E_USER_WARNING);
[74] Fix | Delete
return false;
[75] Fix | Delete
}
[76] Fix | Delete
}
[77] Fix | Delete
[78] Fix | Delete
[79] Fix | Delete
// ------------
[80] Fix | Delete
[81] Fix | Delete
[82] Fix | Delete
class SHA256Data extends hashData
[83] Fix | Delete
{
[84] Fix | Delete
// buffer
[85] Fix | Delete
var $buf = array();
[86] Fix | Delete
[87] Fix | Delete
// padded data
[88] Fix | Delete
var $chunks = null;
[89] Fix | Delete
[90] Fix | Delete
function SHA256Data($str)
[91] Fix | Delete
{
[92] Fix | Delete
$M = strlen($str); // number of bytes
[93] Fix | Delete
$L1 = ($M >> 28) & 0x0000000F; // top order bits
[94] Fix | Delete
$L2 = $M << 3; // number of bits
[95] Fix | Delete
$l = pack('N*', $L1, $L2);
[96] Fix | Delete
[97] Fix | Delete
// 64 = 64 bits needed for the size mark. 1 = the 1 bit added to the
[98] Fix | Delete
// end. 511 = 511 bits to get the number to be at least large enough
[99] Fix | Delete
// to require one block. 512 is the block size.
[100] Fix | Delete
$k = $L2 + 64 + 1 + 511;
[101] Fix | Delete
$k -= $k % 512 + $L2 + 64 + 1;
[102] Fix | Delete
$k >>= 3; // convert to byte count
[103] Fix | Delete
[104] Fix | Delete
$str .= chr(0x80) . str_repeat(chr(0), $k) . $l;
[105] Fix | Delete
[106] Fix | Delete
assert('strlen($str) % 64 == 0');
[107] Fix | Delete
[108] Fix | Delete
// break the binary string into 512-bit blocks
[109] Fix | Delete
preg_match_all( '#.{64}#', $str, $this->chunks );
[110] Fix | Delete
$this->chunks = $this->chunks[0];
[111] Fix | Delete
[112] Fix | Delete
// H(0)
[113] Fix | Delete
/*
[114] Fix | Delete
$this->hash = array
[115] Fix | Delete
(
[116] Fix | Delete
(int)0x6A09E667, (int)0xBB67AE85,
[117] Fix | Delete
(int)0x3C6EF372, (int)0xA54FF53A,
[118] Fix | Delete
(int)0x510E527F, (int)0x9B05688C,
[119] Fix | Delete
(int)0x1F83D9AB, (int)0x5BE0CD19,
[120] Fix | Delete
);
[121] Fix | Delete
*/
[122] Fix | Delete
[123] Fix | Delete
$this->hash = array
[124] Fix | Delete
(
[125] Fix | Delete
1779033703, -1150833019,
[126] Fix | Delete
1013904242, -1521486534,
[127] Fix | Delete
1359893119, -1694144372,
[128] Fix | Delete
528734635, 1541459225,
[129] Fix | Delete
);
[130] Fix | Delete
}
[131] Fix | Delete
}
[132] Fix | Delete
[133] Fix | Delete
[134] Fix | Delete
// static class. Access via SHA256::hash()
[135] Fix | Delete
class SHA256 extends hash
[136] Fix | Delete
{
[137] Fix | Delete
function hash($str, $mode = 'hex')
[138] Fix | Delete
{
[139] Fix | Delete
static $modes = array( 'hex', 'bin', 'bit' );
[140] Fix | Delete
$ret = false;
[141] Fix | Delete
[142] Fix | Delete
if(!in_array(strtolower($mode), $modes))
[143] Fix | Delete
{
[144] Fix | Delete
trigger_error('mode specified is unrecognized: ' . $mode, E_USER_WARNING);
[145] Fix | Delete
}
[146] Fix | Delete
else
[147] Fix | Delete
{
[148] Fix | Delete
$data = new SHA256Data($str);
[149] Fix | Delete
$data =& $data;
[150] Fix | Delete
[151] Fix | Delete
SHA256::compute($data);
[152] Fix | Delete
[153] Fix | Delete
$func = array('SHA256', 'hash' . $mode);
[154] Fix | Delete
if(is_callable($func))
[155] Fix | Delete
{
[156] Fix | Delete
$func = 'hash' . $mode;
[157] Fix | Delete
$ret = SHA256::$func($data);
[158] Fix | Delete
//$ret = call_user_func($func, $data);
[159] Fix | Delete
}
[160] Fix | Delete
else
[161] Fix | Delete
{
[162] Fix | Delete
trigger_error('SHA256::hash' . $mode . '() NOT IMPLEMENTED.', E_USER_WARNING);
[163] Fix | Delete
}
[164] Fix | Delete
}
[165] Fix | Delete
[166] Fix | Delete
return $ret;
[167] Fix | Delete
}
[168] Fix | Delete
[169] Fix | Delete
// ------------
[170] Fix | Delete
// begin internal functions
[171] Fix | Delete
[172] Fix | Delete
// 32-bit summation
[173] Fix | Delete
function sum()
[174] Fix | Delete
{
[175] Fix | Delete
$T = 0;
[176] Fix | Delete
for($x = 0, $y = func_num_args(); $x < $y; $x++)
[177] Fix | Delete
{
[178] Fix | Delete
// argument
[179] Fix | Delete
$a = func_get_arg($x);
[180] Fix | Delete
[181] Fix | Delete
// carry storage
[182] Fix | Delete
$c = 0;
[183] Fix | Delete
[184] Fix | Delete
for($i = 0; $i < 32; $i++)
[185] Fix | Delete
{
[186] Fix | Delete
// sum of the bits at $i
[187] Fix | Delete
$j = (($T >> $i) & 1) + (($a >> $i) & 1) + $c;
[188] Fix | Delete
// carry of the bits at $i
[189] Fix | Delete
$c = ($j >> 1) & 1;
[190] Fix | Delete
// strip the carry
[191] Fix | Delete
$j &= 1;
[192] Fix | Delete
// clear the bit
[193] Fix | Delete
$T &= ~(1 << $i);
[194] Fix | Delete
// set the bit
[195] Fix | Delete
$T |= $j << $i;
[196] Fix | Delete
}
[197] Fix | Delete
}
[198] Fix | Delete
[199] Fix | Delete
return $T;
[200] Fix | Delete
}
[201] Fix | Delete
[202] Fix | Delete
[203] Fix | Delete
// compute the hash
[204] Fix | Delete
function compute(&$hashData)
[205] Fix | Delete
{
[206] Fix | Delete
static $vars = 'abcdefgh';
[207] Fix | Delete
static $K = null;
[208] Fix | Delete
[209] Fix | Delete
if($K === null)
[210] Fix | Delete
{
[211] Fix | Delete
/*
[212] Fix | Delete
$K = array(
[213] Fix | Delete
(int)0x428A2F98, (int)0x71374491, (int)0xB5C0FBCF, (int)0xE9B5DBA5,
[214] Fix | Delete
(int)0x3956C25B, (int)0x59F111F1, (int)0x923F82A4, (int)0xAB1C5ED5,
[215] Fix | Delete
(int)0xD807AA98, (int)0x12835B01, (int)0x243185BE, (int)0x550C7DC3,
[216] Fix | Delete
(int)0x72BE5D74, (int)0x80DEB1FE, (int)0x9BDC06A7, (int)0xC19BF174,
[217] Fix | Delete
(int)0xE49B69C1, (int)0xEFBE4786, (int)0x0FC19DC6, (int)0x240CA1CC,
[218] Fix | Delete
(int)0x2DE92C6F, (int)0x4A7484AA, (int)0x5CB0A9DC, (int)0x76F988DA,
[219] Fix | Delete
(int)0x983E5152, (int)0xA831C66D, (int)0xB00327C8, (int)0xBF597FC7,
[220] Fix | Delete
(int)0xC6E00BF3, (int)0xD5A79147, (int)0x06CA6351, (int)0x14292967,
[221] Fix | Delete
(int)0x27B70A85, (int)0x2E1B2138, (int)0x4D2C6DFC, (int)0x53380D13,
[222] Fix | Delete
(int)0x650A7354, (int)0x766A0ABB, (int)0x81C2C92E, (int)0x92722C85,
[223] Fix | Delete
(int)0xA2BFE8A1, (int)0xA81A664B, (int)0xC24B8B70, (int)0xC76C51A3,
[224] Fix | Delete
(int)0xD192E819, (int)0xD6990624, (int)0xF40E3585, (int)0x106AA070,
[225] Fix | Delete
(int)0x19A4C116, (int)0x1E376C08, (int)0x2748774C, (int)0x34B0BCB5,
[226] Fix | Delete
(int)0x391C0CB3, (int)0x4ED8AA4A, (int)0x5B9CCA4F, (int)0x682E6FF3,
[227] Fix | Delete
(int)0x748F82EE, (int)0x78A5636F, (int)0x84C87814, (int)0x8CC70208,
[228] Fix | Delete
(int)0x90BEFFFA, (int)0xA4506CEB, (int)0xBEF9A3F7, (int)0xC67178F2
[229] Fix | Delete
);
[230] Fix | Delete
*/
[231] Fix | Delete
$K = array (
[232] Fix | Delete
1116352408, 1899447441, -1245643825, -373957723,
[233] Fix | Delete
961987163, 1508970993, -1841331548, -1424204075,
[234] Fix | Delete
-670586216, 310598401, 607225278, 1426881987,
[235] Fix | Delete
1925078388, -2132889090, -1680079193, -1046744716,
[236] Fix | Delete
-459576895, -272742522, 264347078, 604807628,
[237] Fix | Delete
770255983, 1249150122, 1555081692, 1996064986,
[238] Fix | Delete
-1740746414, -1473132947, -1341970488, -1084653625,
[239] Fix | Delete
-958395405, -710438585, 113926993, 338241895,
[240] Fix | Delete
666307205, 773529912, 1294757372, 1396182291,
[241] Fix | Delete
1695183700, 1986661051, -2117940946, -1838011259,
[242] Fix | Delete
-1564481375, -1474664885, -1035236496, -949202525,
[243] Fix | Delete
-778901479, -694614492, -200395387, 275423344,
[244] Fix | Delete
430227734, 506948616, 659060556, 883997877,
[245] Fix | Delete
958139571, 1322822218, 1537002063, 1747873779,
[246] Fix | Delete
1955562222, 2024104815, -2067236844, -1933114872,
[247] Fix | Delete
-1866530822, -1538233109, -1090935817, -965641998,
[248] Fix | Delete
);
[249] Fix | Delete
}
[250] Fix | Delete
[251] Fix | Delete
$W = array();
[252] Fix | Delete
for($i = 0, $numChunks = sizeof($hashData->chunks); $i < $numChunks; $i++)
[253] Fix | Delete
{
[254] Fix | Delete
// initialize the registers
[255] Fix | Delete
for($j = 0; $j < 8; $j++)
[256] Fix | Delete
${$vars{$j}} = $hashData->hash[$j];
[257] Fix | Delete
[258] Fix | Delete
// the SHA-256 compression function
[259] Fix | Delete
for($j = 0; $j < 64; $j++)
[260] Fix | Delete
{
[261] Fix | Delete
if($j < 16)
[262] Fix | Delete
{
[263] Fix | Delete
$T1 = ord($hashData->chunks[$i]{$j*4 }) & 0xFF; $T1 <<= 8;
[264] Fix | Delete
$T1 |= ord($hashData->chunks[$i]{$j*4+1}) & 0xFF; $T1 <<= 8;
[265] Fix | Delete
$T1 |= ord($hashData->chunks[$i]{$j*4+2}) & 0xFF; $T1 <<= 8;
[266] Fix | Delete
$T1 |= ord($hashData->chunks[$i]{$j*4+3}) & 0xFF;
[267] Fix | Delete
$W[$j] = $T1;
[268] Fix | Delete
}
[269] Fix | Delete
else
[270] Fix | Delete
{
[271] Fix | Delete
$W[$j] = SHA256::sum(((($W[$j-2] >> 17) & 0x00007FFF) | ($W[$j-2] << 15)) ^ ((($W[$j-2] >> 19) & 0x00001FFF) | ($W[$j-2] << 13)) ^ (($W[$j-2] >> 10) & 0x003FFFFF), $W[$j-7], ((($W[$j-15] >> 7) & 0x01FFFFFF) | ($W[$j-15] << 25)) ^ ((($W[$j-15] >> 18) & 0x00003FFF) | ($W[$j-15] << 14)) ^ (($W[$j-15] >> 3) & 0x1FFFFFFF), $W[$j-16]);
[272] Fix | Delete
}
[273] Fix | Delete
[274] Fix | Delete
$T1 = SHA256::sum($h, ((($e >> 6) & 0x03FFFFFF) | ($e << 26)) ^ ((($e >> 11) & 0x001FFFFF) | ($e << 21)) ^ ((($e >> 25) & 0x0000007F) | ($e << 7)), ($e & $f) ^ (~$e & $g), $K[$j], $W[$j]);
[275] Fix | Delete
$T2 = SHA256::sum(((($a >> 2) & 0x3FFFFFFF) | ($a << 30)) ^ ((($a >> 13) & 0x0007FFFF) | ($a << 19)) ^ ((($a >> 22) & 0x000003FF) | ($a << 10)), ($a & $b) ^ ($a & $c) ^ ($b & $c));
[276] Fix | Delete
$h = $g;
[277] Fix | Delete
$g = $f;
[278] Fix | Delete
$f = $e;
[279] Fix | Delete
$e = SHA256::sum($d, $T1);
[280] Fix | Delete
$d = $c;
[281] Fix | Delete
$c = $b;
[282] Fix | Delete
$b = $a;
[283] Fix | Delete
$a = SHA256::sum($T1, $T2);
[284] Fix | Delete
}
[285] Fix | Delete
[286] Fix | Delete
// compute the next hash set
[287] Fix | Delete
for($j = 0; $j < 8; $j++)
[288] Fix | Delete
$hashData->hash[$j] = SHA256::sum(${$vars{$j}}, $hashData->hash[$j]);
[289] Fix | Delete
}
[290] Fix | Delete
}
[291] Fix | Delete
[292] Fix | Delete
[293] Fix | Delete
// set up the display of the hash in hex.
[294] Fix | Delete
function hashHex(&$hashData)
[295] Fix | Delete
{
[296] Fix | Delete
$str = '';
[297] Fix | Delete
[298] Fix | Delete
reset($hashData->hash);
[299] Fix | Delete
do
[300] Fix | Delete
{
[301] Fix | Delete
$str .= sprintf('%08x', current($hashData->hash));
[302] Fix | Delete
}
[303] Fix | Delete
while(next($hashData->hash));
[304] Fix | Delete
[305] Fix | Delete
return $str;
[306] Fix | Delete
}
[307] Fix | Delete
[308] Fix | Delete
[309] Fix | Delete
// set up the output of the hash in binary
[310] Fix | Delete
function hashBin(&$hashData)
[311] Fix | Delete
{
[312] Fix | Delete
$str = '';
[313] Fix | Delete
[314] Fix | Delete
reset($hashData->hash);
[315] Fix | Delete
do
[316] Fix | Delete
{
[317] Fix | Delete
$str .= pack('N', current($hashData->hash));
[318] Fix | Delete
}
[319] Fix | Delete
while(next($hashData->hash));
[320] Fix | Delete
[321] Fix | Delete
return $str;
[322] Fix | Delete
}
[323] Fix | Delete
}
[324] Fix | Delete
[325] Fix | Delete
[326] Fix | Delete
//--------------
[327] Fix | Delete
// REMOVAL ALL FUNCTIONS AFTER THIS WHEN NOT TESTING
[328] Fix | Delete
//--------------
[329] Fix | Delete
[330] Fix | Delete
// format a string into 4 byte hex chunks
[331] Fix | Delete
function hexerize($str)
[332] Fix | Delete
{
[333] Fix | Delete
$n = 0;
[334] Fix | Delete
$b = 0;
[335] Fix | Delete
if(is_array($str))
[336] Fix | Delete
{
[337] Fix | Delete
reset($str);
[338] Fix | Delete
$o = 'array(' . sizeof($str) . ')::' . "\n\n";
[339] Fix | Delete
while($s = current($str))
[340] Fix | Delete
{
[341] Fix | Delete
$o .= hexerize($s);
[342] Fix | Delete
next($str);
[343] Fix | Delete
}
[344] Fix | Delete
$o .= 'end array;'."\n";
[345] Fix | Delete
}
[346] Fix | Delete
else
[347] Fix | Delete
{
[348] Fix | Delete
if(is_integer($str) || is_float($str))
[349] Fix | Delete
$str = pack('N',$str);
[350] Fix | Delete
$o = 'string(' . strlen($str) . ')' . "::\n";
[351] Fix | Delete
for($i = 0, $j = strlen($str); $i < $j; $i++, $b = $i % 4)
[352] Fix | Delete
{
[353] Fix | Delete
$o .= sprintf('%02X', ord($str{$i}));
[354] Fix | Delete
// only process when 32-bits have passed through
[355] Fix | Delete
if($i != 0 && $b == 3)
[356] Fix | Delete
{
[357] Fix | Delete
// process new line points
[358] Fix | Delete
if($n == 3)
[359] Fix | Delete
$o .= "\n";
[360] Fix | Delete
else
[361] Fix | Delete
$o .= ' ';
[362] Fix | Delete
++$n;
[363] Fix | Delete
$n %= 4;
[364] Fix | Delete
}
[365] Fix | Delete
}
[366] Fix | Delete
}
[367] Fix | Delete
[368] Fix | Delete
return $o . "\n";
[369] Fix | Delete
}
[370] Fix | Delete
[371] Fix | Delete
[372] Fix | Delete
// testing functions
[373] Fix | Delete
[374] Fix | Delete
function test1()
[375] Fix | Delete
{
[376] Fix | Delete
$it = 1;
[377] Fix | Delete
[378] Fix | Delete
echo '<pre>';
[379] Fix | Delete
[380] Fix | Delete
$test = array('abc','abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq');
[381] Fix | Delete
[382] Fix | Delete
foreach($test as $str)
[383] Fix | Delete
{
[384] Fix | Delete
echo 'Testing ' . var_export($str,true) . "\n";
[385] Fix | Delete
list($s1,$s2) = explode(' ', microtime());
[386] Fix | Delete
for($x = 0; $x < $it; $x++)
[387] Fix | Delete
$data = new SHA256Data($str);
[388] Fix | Delete
$data =& $data;
[389] Fix | Delete
list($e1,$e2) = explode(' ', microtime());
[390] Fix | Delete
echo hexerize($data->chunks);
[391] Fix | Delete
echo hexerize($data->hash);
[392] Fix | Delete
echo 'processing took ' . (($e2 - $s2 + $e1 - $s1) / $it) . ' seconds.' . "\n\n\n";
[393] Fix | Delete
}
[394] Fix | Delete
[395] Fix | Delete
echo '</pre>';
[396] Fix | Delete
}
[397] Fix | Delete
[398] Fix | Delete
function test2()
[399] Fix | Delete
{
[400] Fix | Delete
$it = 1;
[401] Fix | Delete
[402] Fix | Delete
echo '<pre>';
[403] Fix | Delete
[404] Fix | Delete
$test = array('abc','abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq');
[405] Fix | Delete
[406] Fix | Delete
foreach($test as $str)
[407] Fix | Delete
{
[408] Fix | Delete
echo 'Testing ' . var_export($str,true) . "\n";
[409] Fix | Delete
list($s1,$s2) = explode(' ', microtime());
[410] Fix | Delete
for($x = 0; $x < $it; $x++)
[411] Fix | Delete
$o = SHA256::hash($str);
[412] Fix | Delete
list($e1,$e2) = explode(' ', microtime());
[413] Fix | Delete
echo $o;
[414] Fix | Delete
echo 'processing took ' . (($e2 - $s2 + $e1 - $s1) / $it) . ' seconds.' . "\n\n\n";
[415] Fix | Delete
}
[416] Fix | Delete
[417] Fix | Delete
echo '</pre>';
[418] Fix | Delete
}
[419] Fix | Delete
[420] Fix | Delete
function testSum()
[421] Fix | Delete
{
[422] Fix | Delete
echo '<pre>';
[423] Fix | Delete
[424] Fix | Delete
echo SHA256::sum(1,2,3,4,5,6,7,8,9,10);
[425] Fix | Delete
[426] Fix | Delete
echo '</pre>';
[427] Fix | Delete
}
[428] Fix | Delete
[429] Fix | Delete
function testSpeedHash($it = 10)
[430] Fix | Delete
{
[431] Fix | Delete
$it = intval($it);
[432] Fix | Delete
if($it === 0)
[433] Fix | Delete
$it = 10;
[434] Fix | Delete
[435] Fix | Delete
set_time_limit(-1);
[436] Fix | Delete
[437] Fix | Delete
echo '<pre>' . "\n";
[438] Fix | Delete
[439] Fix | Delete
$test = array(
[440] Fix | Delete
''=>'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855',
[441] Fix | Delete
'abc'=>'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad',
[442] Fix | Delete
'message digest'=>'f7846f55cf23e14eebeab5b4e1550cad5b509e3348fbc4efa3a1413d393cb650',
[443] Fix | Delete
'secure hash algorithm'=>'f30ceb2bb2829e79e4ca9753d35a8ecc00262d164cc077080295381cbd643f0d',
[444] Fix | Delete
'SHA256 is considered to be safe'=>'6819d915c73f4d1e77e4e1b52d1fa0f9cf9beaead3939f15874bd988e2a23630',
[445] Fix | Delete
'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq'=>'248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1',
[446] Fix | Delete
'For this sample, this 63-byte string will be used as input data'=>'f08a78cbbaee082b052ae0708f32fa1e50c5c421aa772ba5dbb406a2ea6be342',
[447] Fix | Delete
'This is exactly 64 bytes long, not counting the terminating byte'=>'ab64eff7e88e2e46165e29f2bce41826bd4c7b3552f6b382a9e7d3af47c245f8',
[448] Fix | Delete
);
[449] Fix | Delete
[450] Fix | Delete
foreach($test as $str => $hash)
[451] Fix | Delete
{
[452] Fix | Delete
echo 'Testing ' . var_export($str,true) . "\n";
[453] Fix | Delete
echo 'Start time: ' . date('Y-m-d H:i:s') . "\n";
[454] Fix | Delete
if($it > 1)
[455] Fix | Delete
{
[456] Fix | Delete
list($s1,$s2) = explode(' ', microtime());
[457] Fix | Delete
$o = SHA256::hash($str);
[458] Fix | Delete
list($e1,$e2) = explode(' ', microtime());
[459] Fix | Delete
echo 'estimated time to perform test: ' . (($e2 - $s2 + $e1 - $s1) * $it) . ' seconds for ' . $it . ' iterations.' . "\n";
[460] Fix | Delete
}
[461] Fix | Delete
[462] Fix | Delete
$t = 0;
[463] Fix | Delete
for($x = 0; $x < $it; $x++)
[464] Fix | Delete
{
[465] Fix | Delete
list($s1,$s2) = explode(' ', microtime());
[466] Fix | Delete
$o = SHA256::hash($str);
[467] Fix | Delete
list($e1,$e2) = explode(' ', microtime());
[468] Fix | Delete
$t += $e2 - $s2 + $e1 - $s1;
[469] Fix | Delete
}
[470] Fix | Delete
echo var_export($o,true) . ' == ' . var_export($hash,true) . ' ' . (strcasecmp($o,$hash)==0 ? 'PASSED' : 'FAILED') . "\n";
[471] Fix | Delete
echo 'processing took ' . ($t / $it) . ' seconds.' . "\n\n\n";
[472] Fix | Delete
}
[473] Fix | Delete
[474] Fix | Delete
echo '</pre>';
[475] Fix | Delete
}
[476] Fix | Delete
[477] Fix | Delete
//testSpeedHash(1);
[478] Fix | Delete
[479] Fix | Delete
//--------------
[480] Fix | Delete
// END REMOVAL HERE
[481] Fix | Delete
//--------------
[482] Fix | Delete
[483] Fix | Delete
/* EOF :: Document Settings: tab:4; */
[484] Fix | Delete
[485] Fix | Delete
?>
[486] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function