apgar routine
Platform: PHP
Published May 23, 2010
Updated May 23, 2010
this is the one way routine Command and Conquer: Tiberian Sun uses to encrypt user passwords. pretty weak algorithm and extremely old game but, thought it would be fun to share. needed this to have the ability to match credentials for a server i'm developing. :)
<?php
echo apgar('password'); //result WaIMMsbf
function apgar( $a ) {
if ( strlen( $a ) == 8 ) {
$u = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
for ( $i = 0; $i <= 7; $i++ ) {
$r = ( ( $i == 0 ) ? 0 : ord( $a[8 - $i] ) );
$x = ( ord($a[$i]) & 1 ) ? ( ord($a[$i]) << 1 ) & $r : ord($a[$i]) ^ $r;
$o[] = substr($u, ($x & 0x3f), 1);
}
return implode('', $o);
}
}
?>