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