apgar routine

By sean on 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);
  }
}
?>

Comments

Sign in to comment.
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.