Author Topic: Mifare1 序號轉換函數  (Read 5744 times)

admin

  • Administrator
  • *****
  • Posts: 0
    • View Profile
Mifare1 序號轉換函數
« on: October 12, 2010, 01:38:46 AM »
Code: [Select]
Attribute VB_Name = "modMiFare1Funct"
Option Explicit

Public Function GetMifare1SerialNo(tmpAlterCode As String) As String
    On Error GoTo ErrHandler
    Dim tmpResult As String
    Dim DecNum As Variant
    Dim NextHexDigit As Double
    Dim HexNum As String
    HexNum = ""
    DecNum = tmpAlterCode
    While DecNum <> 0
        NextHexDigit = DecNum - (Int(DecNum / 16) * 16)
        If NextHexDigit < 10 Then
        HexNum = Chr(Asc(NextHexDigit)) & HexNum
        Else
        HexNum = Chr(Asc("A") + NextHexDigit - 10) & HexNum
        End If
        DecNum = Int(DecNum / 16)
    Wend
    While Len(HexNum) < 8
        HexNum = "0" & HexNum
    Wend
   
    If Len(HexNum) = 8 Then
        tmpResult = Mid(HexNum, 7, 2) & Mid(HexNum, 5, 2) & Mid(HexNum, 3, 2) & Mid(HexNum, 1, 2)   
    End If
   
ErrHandler:
    GetMifare1SerialNo = tmpResult
End Function

Public Function GetAlternateCode(tmpCode As String) As String
    On Error GoTo ErrHandler
    Dim lo1 As Integer, lo2 As Integer
    Dim hi1 As Long, hi2 As Long
    Dim tmpResult As String
    Dim tmpString As String
    Const Hx = "&H"
    Const BigShift = 65536
    Const LilShift = 256, Two = 2
   
    If Len(tmpCode) = 8 Then
        tmpString = Mid(tmpCode, 7, 2) & Mid(tmpCode, 5, 2) & Mid(tmpCode, 3, 2) & Mid(tmpCode, 1, 2)
        tmpString = Right$("0000000" & tmpString,
       
        If IsNumeric(Hx & tmpString) Then
            lo1 = CInt(Hx & Right$(tmpString, Two))
            hi1 = CLng(Hx & Mid$(tmpString, 5, Two))
            lo2 = CInt(Hx & Mid$(tmpString, 3, Two))
            hi2 = CLng(Hx & Left$(tmpString, Two))
            tmpResult = CStr(CCur(hi2 * LilShift + lo2) * BigShift + (hi1 * LilShift) + lo1)
            While Len(tmpResult) < 10
                tmpResult = "0" & tmpResult                       
            Wend
        End If
    Else
        tmpResult = tmpCode
    End If
   
ErrHandler:
    GetAlternateCode = tmpResult
End Function

Public Function GetWG26toLowerCode(tmpWG26 As String) As String
    Dim tmpHexCode As String
    Dim tmpDecimal As Long
    tmpDecimal = cuVal(tmpWG26)
    tmpHexCode = Hex(tmpDecimal)
    While Len(tmpHexCode) < 4
        tmpHexCode = "0" & tmpHexCode
    Wend
    GetWG26toLowerCode = tmpHexCode
End Function
« Last Edit: October 12, 2010, 01:44:43 AM by Roy Chan »