Private Sub base45decode(encodedString As String) As Byte()
'Dim alphabet() As String = Array As String("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"," ","$","%","*","+","-",".","/",":")
Dim mAlphabet As Map = CreateMap("0": 0, "1": 1, "2": 2, "3": 3, "4": 4, "5": 5, "6": 6, "7": 7, "8": 8, "9": 9, "A": 10, "B": 11, "C": 12, "D": 13, "E": 14, "F": 15, "G": 16, "H": 17, "I": 18, "J": 19, "K": 20, "L": 21, "M": 22, "N": 23, "O": 24, "P": 25, "Q": 26, "R": 27, "S": 28, "T": 29, "U": 30, "V": 31, "W": 32, "X": 33, "Y": 34, "Z": 35, " ": 36, "$": 37, "%": 38, "*": 39, "+": 40, "-": 41, ".": 42, "/": 43, ":": 44)
If encodedString.Length = 0 Then Return
If (encodedString.Length Mod 3) = 1 Then Return ' ERRORE
Dim i As Int, l As Long
Dim chunk3 As String, chunk2 As String, m As Int
Dim bb As B4XBytesBuilder
bb.Initialize
For i = 0 To encodedString.Length-1 Step 3
l = 0
If i+3 > encodedString.Length Then
chunk2 = encodedString.SubString2(i,i+2)
m = mAlphabet.GetDefault(chunk2.SubString2(1,2),-1)
If m = -1 Then Return
l = l + m * 45
m = mAlphabet.GetDefault(chunk2.SubString2(0,1),-1)
If m = -1 Then Return
l = l + m
Else
chunk3 = encodedString.SubString2(i,i+3)
m = mAlphabet.GetDefault(chunk3.SubString2(2,3),-1)
If m = -1 Then Return
l = m * 2025
m = mAlphabet.GetDefault(chunk3.SubString2(1,2),-1)
If m = -1 Then Return
l = l + m * 45
m = mAlphabet.GetDefault(chunk3.SubString2(0,1),-1)
If m = -1 Then Return
l = l + m
End If
If l >= 256 Then
bb.Append(Array As Byte(Floor( l / 256).As(Byte)))
bb.Append(Array As Byte((l Mod 256).As(Byte)))
Else
bb.Append(Array As Byte(l.As(Byte)))
End If
Next
Return bb.ToArray
End Sub