Created
May 12, 2020 18:40
-
-
Save rafinetiz/903bc590d86fdeee7cb62cde82d66608 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vs.php > | |
{ "x": 124585765, "y": 360809637, "z":521680731, "w": 406819} // sebelum for | |
{ "x": 171306982, "y": 636562185, "z": 2144330573, "w": 1121150324} // sesudah for | |
vs.js > | |
{ x: 124585765, y: 360809637, z: 521680731, w: 406819 } // sebelum for | |
{ x: 4422676, y: 513300356, z: -1713666090, w: 1902687725 } // sesudah for | |
kenapa ya kok output setelah for block berbeda? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const process = require('process') | |
var a,b,c,xors; | |
var textpattern = 'Angger Rafi Akbar'; | |
function rand() { | |
var t = xors.x ^ (xors.x << 11); | |
xors.x = xors.y; | |
xors.y = xors.z; | |
xors.z = xors.w; | |
xors.w = (xors.w ^ (xors.w >>> 19)) ^ (t ^ (t >>> 8)); | |
//return xors.w / 4294967296 + 0.5; | |
} | |
a = textpattern; | |
c = [123456789, 362436069, 521288629, 0]; | |
for (b = 0; b < a.length; b++) { | |
c[(b + 3) % 4] ^= (a.charCodeAt(b) << ((b * 11) % 16)); | |
} | |
xors = { | |
x: c[0], | |
y: c[1], | |
z: c[2], | |
w: c[3] | |
}; | |
console.log(xors) | |
for (a=0; a < 52; a++) rand(); | |
console.log(xors) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
zero fill right shift polyfill | |
https://stackoverflow.com/a/43359819 | |
*/ | |
function zeroShift($a, $b) { | |
if ($b >= 32 || $b < -32) { | |
$m = (int)($b/32); | |
$b = $b-($m*32); | |
} | |
if ($b < 0) { | |
$b = 32 + $b; | |
} | |
if ($b == 0) { | |
return (($a>>1)&0x7fffffff)*2+(($a>>$b)&1); | |
} | |
if ($a < 0) | |
{ | |
$a = ($a >> 1); | |
$a &= 0x7fffffff; | |
$a |= 0x40000000; | |
$a = ($a >> ($b - 1)); | |
} else { | |
$a = ($a >> $b); | |
} | |
return $a; | |
} | |
function shift_left_32( $a, $b ) { | |
return ($c = $a << $b ) && $c >= 0x7FFFFFFF ? ($c & 0x7FFFFFFF) : $c; | |
} | |
function is64($number) { | |
if ($number >= 0x7FFFFFFF) { | |
return '64bit'; | |
} else { | |
return '32bit'; | |
} | |
} | |
function randd(&$xors) { | |
$t = $xors['x'] ^ (shift_left_32($xors['x'], 11)); | |
$xors['x'] = $xors['y']; | |
$xors['y'] = $xors['z']; | |
$xors['z'] = $xors['w']; | |
$xors['w'] = ($xors['w'] ^ (zeroShift($xors['w'], 19))) ^ ($t ^ (zeroShift($t, 8))); | |
/* | |
echo sprintf("X: %d (%s)\nY: %d (%s)\nZ: %d (%s)\nW: %d (%s)\n\n", | |
$xors['x'], is64($xors['x']), | |
$xors['y'], is64($xors['y']), | |
$xors['z'], is64($xors['z']), | |
$xors['w'], is64($xors['w']) | |
); */ | |
} | |
$textpattern = 'Angger Rafi Akbar'; | |
$b = ''; | |
$c = ''; | |
$a = $textpattern; | |
$c = [123456789, 362436069, 521288629, 0]; | |
for ($b = 0; $b < strlen($a); $b++) { | |
$c[($b + 3) % 4] ^= (mb_ord($a[$b]) << (($b * 11) % 16)); | |
} | |
$xors = [ | |
'x' => $c[0], | |
'y' => $c[1], | |
'z' => $c[2], | |
'w' => $c[3] | |
]; | |
echo json_encode($xors); // sebelum for | |
for ($a = 0; $a < 52; $a++) randd($xors); | |
echo json_encode($xors); // sesudah for |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment