qb64-include/atob.bm

23 lines
800 B
Text
Raw Normal View History

2022-09-19 01:27:48 +02:00
$if atob = undefined then
$let atob = defined
2022-10-07 09:17:31 +02:00
Function atob$ (s As String)
2022-05-09 12:36:52 +02:00
Const B64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
2022-10-07 09:17:31 +02:00
Dim c1 As _Byte
Dim c2 As _Byte
Dim c3 As _Byte
Dim c4 As _Byte
2022-05-09 12:36:52 +02:00
Dim i As Long
2022-10-07 09:17:31 +02:00
Dim As String Buffer
For i = 1 To Len(s) Step 4
c1 = InStr(B64, Mid$(s, i + 0, 1)) - 1
c2 = InStr(B64, Mid$(s, i + 1, 1)) - 1
c3 = InStr(B64, Mid$(s, i + 2, 1)) - 1
c4 = InStr(B64, Mid$(s, i + 3, 1)) - 1
If c2 > -1 Then Buffer = Buffer + Chr$(((c1 * 4 + c2 \ 16) And 255))
If c3 > -1 Then Buffer = Buffer + Chr$(((c2 * 16 + c3 \ 4) And 255))
If c4 > -1 Then Buffer = Buffer + Chr$(((c3 * 64 + c4) And 255))
Next i
2022-05-09 12:36:52 +02:00
atob$ = Buffer
2022-09-19 01:27:48 +02:00
End Function
$end if