Freeware
Programme
VB-Bibliotheken
VB-Sourcecode Tipps&Tricks
|
|
|
|
MIME-Kodierung (base64)
Schonmal z.B. beim E-Mail-Transfer auf MIME-kodierte Zeichenketten wie z.B. "VmlzdWFsIEJhc2lj"
getroffen? Mit diesen Funktionen ist die Umwandlung in Klartext kein Problem:
MsgBox base64_decode$("VmlzdWFsIEJhc2lj")
ergibt:
Visual Basic
Auch die Erzeugung von MIME-Strings ist ganz einfach:
mime$ = base64_encode$("Visual Basic")
Const base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
Function base64_encode$(a$)
c$ = ""
For n% = 1 To Len(a$) Step 3
c1% = Asc(Mid$(a$, n%, 1))
c2% = Asc(Mid$(a$, n% + 1, 1) + Chr$(0))
c3% = Asc(Mid$(a$, n% + 2, 1) + Chr$(0))
w1% = Int(c1% / 4)
w2% = (c1% And 3) * 16 + Int(c2% / 16)
If Len(a$) >= n% + 1 Then w3% = (c2% And 15) * 4 + Int(c3% / 64) Else w3% = -1
If Len(a$) >= n% + 2 Then w4% = c3% And 63 Else w4% = -1
c$ = c$ + mimeencode$(w1%) + mimeencode$(w2%) + mimeencode$(w3%) + mimeencode$(w4%)
Next
base64_encode$ = c$
End Function
Function base64_decode$(a$)
c$ = ""
For n% = 1 To Len(a$) Step 4
w1% = mimedecode%(Mid$(a$, n%, 1))
w2% = mimedecode%(Mid$(a$, n% + 1, 1))
w3% = mimedecode%(Mid$(a$, n% + 2, 1))
w4% = mimedecode%(Mid$(a$, n% + 3, 1))
If w2% >= 0 Then c$ = c$ + Chr$(((w1% * 4 + Int(w2% / 16)) And 255))
If w3% >= 0 Then c$ = c$ + Chr$(((w2% * 16 + Int(w3% / 4)) And 255))
If w4% >= 0 Then c$ = c$ + Chr$(((w3% * 64 + w4%) And 255))
Next
base64_decode$ = c$
End Function
Private Function mimeencode$(w%)
If w% >= 0 Then mimeencode$ = Mid$(base64, w% + 1, 1) Else mimeencode$ = ""
End Function
Private Function mimedecode%(a$)
If Len(a$) = 0 Then mimedecode% = -1: Exit Function
mimedecode% = InStr(base64, a$) - 1
End Function
|
Vollständigkeitshalber auch die Algorithmen für "quoted printable":
Function quotedprintable_encode$(a$)
b$ = ""
For n% = 1 To Len(a$)
If Asc(Mid$(a$, n%, 1)) < 16 Then
b$ = b$ + "=0" + Hex$(Asc(Mid$(a$, n%, 1)))
ElseIf Asc(Mid$(a$, n%, 1)) < 32 Or Asc(Mid$(a$, n%, 1)) > 126 Or Mid$(a$, n%, 1) = "=" Then
b$ = b$ + "=" + Hex$(Asc(Mid$(a$, n%, 1)))
Else
b$ = b$ + Mid$(a$, n%, 1)
End If
Next
quotedprintable_encode$ = b$
End Function
Function quotedprintable_decode$(ByVal a$)
f% = 0
Do
f% = InStr(f% + 1, a$, "=")
If f% = 0 Or f% > Len(a$) - 2 Then Exit Do
a$ = Left$(a$, f% - 1) + Chr$(Val("&H" + Mid$(a$, f% + 1, 2))) + Mid$(a$, f% + 3)
Loop
quotedprintable_decode$ = a$
End Function
|
|
|