PinBlock.php
2.39 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
/**
* Author: gu_yongkang
* data: 20110510
* 密码转PIN
* Enter description here ...
* @param $spin
*/
function Pin2PinBlock( &$sPin )
{
// $sPin = "123456";
$iTemp = 1;
$sPinLen = strlen($sPin);
$sBuf = array();
//密码域大于10位
$sBuf[0]=intval($sPinLen, 10);
if($sPinLen % 2 ==0)
{
for ($i=0; $i<$sPinLen;)
{
$tBuf = substr($sPin, $i, 2);
$sBuf[$iTemp] = intval($tBuf, 16);
unset($tBuf);
if ($i == ($sPinLen - 2))
{
if ($iTemp < 7)
{
$t = 0;
for ($t=($iTemp+1); $t<8; $t++)
{
$sBuf[$t] = 0xff;
}
}
}
$iTemp++;
$i = $i + 2; //linshi
}
}
else
{
for ($i=0; $i<$sPinLen;)
{
if ($i ==($sPinLen-1))
{
$mBuf = substr($sPin, $i, 1) . "f";
$sBuf[$iTemp] = intval($mBuf, 16);
unset($mBuf);
if (($iTemp)<7)
{
$t = 0;
for ($t=($iTemp+1); $t<8; $t++)
{
$sBuf[$t] = 0xff;
}
}
}
else
{
$tBuf = substr($sPin, $i, 2);
$sBuf[$iTemp] = intval($tBuf, 16);
unset($tBuf);
}
$iTemp++;
$i = $i + 2;
}
}
return $sBuf;
}
/**
* Author: gu_yongkang
* data: 20110510
* Enter description here ...
* @param $sPan
*/
function FormatPan(&$sPan)
{
$iPanLen = strlen($sPan);
$iTemp = $iPanLen - 13;
$sBuf = array();
$sBuf[0] = 0x00;
$sBuf[1] = 0x00;
for ($i=2; $i<8; $i++)
{
$tBuf = substr($sPan, $iTemp, 2);
$sBuf[$i] = intval($tBuf, 16);
$iTemp = $iTemp + 2;
}
return $sBuf;
}
function Pin2PinBlockWithCardNO(&$sPin, &$sCardNO)
{
global $log;
$sPinBuf = Pin2PinBlock($sPin);
$iCardLen = strlen($sCardNO);
// $log->LogInfo("CardNO length : " . $iCardLen);
if ($iCardLen <= 10)
{
return (1);
}
elseif ($iCardLen==11){
$sCardNO = "00" . $sCardNO;
}
elseif ($iCardLen==12){
$sCardNO = "0" . $sCardNO;
}
$sPanBuf = FormatPan($sCardNO);
$sBuf = array();
for ($i=0; $i<8; $i++)
{
// $sBuf[$i] = $sPinBuf[$i] ^ $sPanBuf[$i]; //十进制
// $sBuf[$i] = vsprintf("%02X", ($sPinBuf[$i] ^ $sPanBuf[$i]));
$sBuf[$i] = vsprintf("%c", ($sPinBuf[$i] ^ $sPanBuf[$i]));
}
unset($sPinBuf);
unset($sPanBuf);
// return $sBuf;
$sOutput = implode("", $sBuf); //数组转换为字符串
return $sOutput;
}
?>