人人商城

PinBlock.php 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. function Pin2PinBlock( &$sPin )
  7. {
  8. $iTemp = 1;
  9. $sPinLen = strlen($sPin);
  10. $sBuf = array();
  11. $sBuf[0]=intval($sPinLen, 10);
  12. if($sPinLen % 2 ==0)
  13. {
  14. for ($i=0; $i<$sPinLen;)
  15. {
  16. $tBuf = substr($sPin, $i, 2);
  17. $sBuf[$iTemp] = intval($tBuf, 16);
  18. unset($tBuf);
  19. if ($i == ($sPinLen - 2))
  20. {
  21. if ($iTemp < 7)
  22. {
  23. $t = 0;
  24. for ($t=($iTemp+1); $t<8; $t++)
  25. {
  26. $sBuf[$t] = 0xff;
  27. }
  28. }
  29. }
  30. $iTemp++;
  31. $i = $i + 2; }
  32. }
  33. else
  34. {
  35. for ($i=0; $i<$sPinLen;)
  36. {
  37. if ($i ==($sPinLen-1))
  38. {
  39. $mBuf = substr($sPin, $i, 1) . "f";
  40. $sBuf[$iTemp] = intval($mBuf, 16);
  41. unset($mBuf);
  42. if (($iTemp)<7)
  43. {
  44. $t = 0;
  45. for ($t=($iTemp+1); $t<8; $t++)
  46. {
  47. $sBuf[$t] = 0xff;
  48. }
  49. }
  50. }
  51. else
  52. {
  53. $tBuf = substr($sPin, $i, 2);
  54. $sBuf[$iTemp] = intval($tBuf, 16);
  55. unset($tBuf);
  56. }
  57. $iTemp++;
  58. $i = $i + 2;
  59. }
  60. }
  61. return $sBuf;
  62. }
  63. function FormatPan(&$sPan)
  64. {
  65. $iPanLen = strlen($sPan);
  66. $iTemp = $iPanLen - 13;
  67. $sBuf = array();
  68. $sBuf[0] = 0x00;
  69. $sBuf[1] = 0x00;
  70. for ($i=2; $i<8; $i++)
  71. {
  72. $tBuf = substr($sPan, $iTemp, 2);
  73. $sBuf[$i] = intval($tBuf, 16);
  74. $iTemp = $iTemp + 2;
  75. }
  76. return $sBuf;
  77. }
  78. function Pin2PinBlockWithCardNO(&$sPin, &$sCardNO)
  79. {
  80. global $log;
  81. $sPinBuf = Pin2PinBlock($sPin);
  82. $iCardLen = strlen($sCardNO);
  83. if ($iCardLen <= 10)
  84. {
  85. return (1);
  86. }
  87. elseif ($iCardLen==11){
  88. $sCardNO = "00" . $sCardNO;
  89. }
  90. elseif ($iCardLen==12){
  91. $sCardNO = "0" . $sCardNO;
  92. }
  93. $sPanBuf = FormatPan($sCardNO);
  94. $sBuf = array();
  95. for ($i=0; $i<8; $i++)
  96. {
  97. $sBuf[$i] = vsprintf("%c", ($sPinBuf[$i] ^ $sPanBuf[$i]));
  98. }
  99. unset($sPinBuf);
  100. unset($sPanBuf);
  101. $sOutput = implode("", $sBuf); return $sOutput;
  102. }
  103. ?>