php function _lock2key _LOCK From http dcplusplus sourceforge net wiki

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
function _lock2key($_LOCK) {
// From: http://dcplusplus.sourceforge.net/wiki/index.php/LockToKey#PHP
$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;
}
?>