Added base64 encoding and decoding
This commit is contained in:
parent
434d36c76d
commit
160696871f
2 changed files with 62 additions and 0 deletions
43
atob.bm
Normal file
43
atob.bm
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
Function atob$ (strng As String)
|
||||
Const B64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
|
||||
Dim c1 As _Unsigned _Byte
|
||||
Dim c2 As _Unsigned _Byte
|
||||
Dim c3 As _Unsigned _Byte
|
||||
Dim t1 As _Unsigned _Byte
|
||||
Dim t2 As _Unsigned _Byte
|
||||
Dim t3 As _Unsigned _Byte
|
||||
Dim t4 As _Unsigned _Byte
|
||||
Dim i As Long
|
||||
Dim Buffer As String
|
||||
|
||||
For i = 1 To Len(strng) Step 3
|
||||
c1 = Asc(Mid$(strng, i, 1))
|
||||
t1 = _SHR((c1), 2)
|
||||
Buffer = Buffer + Mid$(B64, t1 + 1, 1)
|
||||
If Len(strng) >= i + 1 Then
|
||||
c2 = Asc(Mid$(strng, i + 1, 1))
|
||||
t2 = (_SHL((c1 And &B00000011), 4)) Or (_SHR((c2), 4))
|
||||
Buffer = Buffer + Mid$(B64, t2 + 1, 1)
|
||||
Else
|
||||
t2 = (_SHL((c1 And &B00000011), 4))
|
||||
Buffer = Buffer + Mid$(B64, t2 + 1, 1)
|
||||
Buffer = Buffer + "=="
|
||||
atob$ = Buffer
|
||||
Exit Function
|
||||
End If
|
||||
If Len(strng) >= i + 2 Then
|
||||
c3 = Asc(Mid$(strng, i + 2, 1))
|
||||
t3 = (_SHL((c2 And &B00001111), 2)) Or (_SHR((c3), 6))
|
||||
Buffer = Buffer + Mid$(B64, t3 + 1, 1)
|
||||
t4 = c3 And &B00111111
|
||||
Buffer = Buffer + Mid$(B64, t4 + 1, 1)
|
||||
Else
|
||||
t3 = (_SHL((c2 And &B00001111), 2))
|
||||
Buffer = Buffer + Mid$(B64, t3 + 1, 1)
|
||||
Buffer = Buffer + "="
|
||||
atob$ = Buffer
|
||||
Exit Function
|
||||
End If
|
||||
Next
|
||||
atob$ = Buffer
|
||||
End Function
|
||||
Loading…
Add table
Add a link
Reference in a new issue