Advertisement
Guest User

Untitled

a guest
Jan 27th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. Function base32_decoder(ByVal b321 As String)
  2.  
  3.  
  4. Dim lut As New Dictionary(Of Char, Integer) From {{"A"c, 0}, {"B"c, 1}, {"C"c, 2}, {"D"c, 3}, {"E"c, 4}, {"F"c, 5}, {"G"c, 6}, {"H"c, 7}, {"I"c, 8}, {"J"c, 9}, {"K"c, 10}, {"L"c, 11}, {"M"c, 12}, {"N"c, 13}, {"O"c, 14}, {"P"c, 15}, {"Q"c, 16}, {"R"c, 17}, {"S"c, 18}, {"T"c, 19}, {"U"c, 20}, {"V"c, 21}, {"W"c, 22}, {"X"c, 23}, {"Y"c, 24}, {"Z"c, 25}, {"2"c, 26}, {"3"c, 27}, {"4"c, 28}, {"5"c, 29}, {"6"c, 30}, {"7"c, 31}}
  5.  
  6.  
  7. Dim b32 As String = b321.ToUpper
  8.  
  9.  
  10. Dim l As Integer = b321.Length
  11.  
  12.  
  13. Dim n As Integer = 0
  14.  
  15.  
  16. Dim j As Integer = 0
  17.  
  18.  
  19. Dim binary = New List(Of Char)
  20.  
  21. For i As Integer = 0 To l - 1
  22.  
  23.  
  24. n = n << 5
  25.  
  26.  
  27. n = n + lut(b32(i))
  28.  
  29. j = j + 5
  30.  
  31. If j >= 8 Then
  32.  
  33.  
  34. j = j - 8
  35.  
  36.  
  37. binary.Add(Chr((n And (&HFF << j)) >> j).ToString.PadLeft(2, "0"))
  38.  
  39.  
  40. End If
  41.  
  42.  
  43. Next
  44.  
  45.  
  46. Return System.Text.Encoding.UTF8.GetBytes(New String(binary.ToArray()))
  47.  
  48.  
  49. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement