Skip to content

Instantly share code, notes, and snippets.

@sean3z
Created December 29, 2022 23:25
Show Gist options
  • Save sean3z/e8b85497b7e599d22145932c03ba80dc to your computer and use it in GitHub Desktop.
Save sean3z/e8b85497b7e599d22145932c03ba80dc to your computer and use it in GitHub Desktop.
WOL Apgar routine in PHP
<?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);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment