Qualcuno mi può trasformare questo codice VB in PHP??

Grazie in anticipo..
codice:
Public Function LockToKey(lck As String) As String
  Dim h As Integer, j As Integer, n As Integer
  n = 5
  h = InStr(1, lck, " ")
  If h Then lck = Left$(lck, h - 1)
  h = Asc(lck) Xor Asc(Right$(lck, 1)) Xor Asc(Right$(lck, 2)) Xor n
  h = (h \ 16) Xor (h * 16)
  Do While h > 255
    h = h - 256
  Loop
  Select Case h
    Case 0, 5, 36, 96, 124, 126
      LockToKey = "/%DCN" & Right$("00" & CStr(h), 3) & "%/"
    Case Else
      LockToKey = Chr$(h)
  End Select
  For j = 2 To Len(lck)
    h = Asc(Mid$(lck, j, 1)) Xor Asc(Mid$(lck, j - 1, 1))
    h = (h \ 16) Xor (h * 16)
    Do While h > 255
      h = h - 256
    Loop
    Select Case h
      Case 0, 5, 36, 96, 124, 126
        LockToKey = LockToKey & "/%DCN" & Right$("00" & CStr(h), 3) & "%/"
      Case Else
        LockToKey = LockToKey & Chr$(h)
    End Select
  Next
End Function