JS APGAR Routine

By sean on May 29, 2012

APGAR is the one-way hashing algorithm all legacy Command and Conquer games use to send and store user passwords. This snippet is a simple port of the PHP version submitted some time ago.

function apgar(s) {
    if (s.length != 8) {  return false; }
    var s = s.split(''), o = new Array();
    var u = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./';
    for( var i = 0; i <= 7; i++ ) {
        var a = s[(8 - i)], r = ( (i == 0) ? 0 : a.charCodeAt(0));
        var j = s[i].charCodeAt(0), x = ( (j & 1) ? (j << 1) & r : j ^ r);
        var k = (x & 0x3f), f = u.substring(k, (k + 1));
        o.push(f);
    }
    return o.join('');
}

console.log('apgar', apgar('password')); // WaIMMsbf

Comments

Sign in to comment.
sean   -  May 29, 2012

Don't think so. It's strictly C&C related.

 Respond  
Hawkee   -  May 29, 2012

Does this have any modern applications? Every mention I see of it talks about C&C.

 Respond  
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.