function _lock2key($_LOCK) {
$lockLength = strlen ($_LOCK);
$h = ord($_LOCK{0}) ^ ord( $_LOCK{ $lockLength - 1} ) ^ ord( $_LOCK{ $lockLength - 2} ) ^ 5;
// echo $h . "<br>";
while ($h > 255) {
$h = $h - 256;
}
$h = (($h<<4) & 240) | (($h>>4) & 15);
$a = $h;
if ($a == '126' or // '~'
$a == '124' or // '|'
$a == '96' or // '`'
$a == '36' or // '$'
$a == '5' or // '^E'
$a == '0') // NUL
{
$LockToKey = "/%DCN";
if ($a < 100) $LockToKey .="0";
if ($a < 10) $LockToKey .="0";
$LockToKey .= $a; // As a string integer
$LockToKey .= "%/";
} else {
$LockToKey = chr ($a); // No transformation.
}
for ($j = 1; $j < strlen($_LOCK); $j++) {
$h = ord($_LOCK{$j}) ^ ord($_LOCK{$j-1});
while ($h > 255) {
$h = $h - 256;
}
$h = (($h<<4) & 240) | (($h>>4) & 15);
// echo $j . " - " . ($h*16) . "";
$a = $h;
if ($a == '126' or // '~'
$a == '124' or // '|'
$a == '96' or // '`'
$a == '36' or // '$'
$a == '5' or // '^E'
$a == '0') // NUL
{
$LockToKey .= "/%DCN";
if ($a < 100) $LockToKey .="0";
if ($a < 10) $LockToKey .="0";
$LockToKey .= $a; // As a string integer
$LockToKey .= "%/";
} else {
$LockToKey .= chr ($a); // No transformation.
}
}
return $LockToKey;
}