Skip to content

Instantly share code, notes, and snippets.

@sean3z
Created December 29, 2022 23:27
Show Gist options
  • Save sean3z/d6363b6becfd3776112a49f689761571 to your computer and use it in GitHub Desktop.
Save sean3z/d6363b6becfd3776112a49f689761571 to your computer and use it in GitHub Desktop.
WOL Apgar routine in Javascript
function apgar(s) {
if (s.length != 8) return false;
var s = s.split(''), o = [];
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment