WS_SYSMENU
CAPTION "Base64 demo by LC"
FONT 9, "宋体", 0, 0, 0x0
BEGIN
LTEXT "请输入字符串:", IDC_STATIC, 11, 7, 130, 10
EDITTEXT IDC_EDIT_INPUT, 11, 20, 173, 12, ES_AUTOHSCROLL
DEFPUSHBUTTON "编码(&E)", IDC_BUTTON_ENCODE, 38, 39, 52, 15
PUSHBUTTON "解码(&D)", IDC_BUTTON_DECODE, 104, 39, 52, 15
END
如果你发现了有bug,一定要告诉我啊,并请来信讨论!lcother@163.net
最后给大家留下一个小小的习题,你知道下面这串Base64编码的原文是什么吗? :)
0LvQu8T6xM3XxdDU19O/tM3qztK1xEJhc2U2NL3Ms8yjoSCjuqOp
VB: Base64 加/解密 (只适用于英文)
使用:
call encode(.......) 加密
call decode(.......) 解密
' -------- Cut Begins here-----
Private Const base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
Public Function Encode(DecryptedText As String) As String
Dim c1, c2, c3 As Integer
Dim w1 As Integer
Dim w2 As Integer
Dim w3 As Integer
Dim w4 As Integer
Dim n As Integer
Dim retry As String
For n = 1 To Len(DecryptedText) Step 3
c1 = Asc(Mid$(DecryptedText, n, 1))
c2 = Asc(Mid$(DecryptedText, n + 1, 1) + Chr$(0))
c3 = Asc(Mid$(DecryptedText, n + 2, 1) + Chr$(0))
w1 = Int(c1 / 4)
w2 = (c1 And 3) * 16 + Int(c2 / 16)
If Len(DecryptedText) >= n + 1 Then w3 = (c2 And 15) * 4 + Int(c3 / 64) Else w3 = -1
If Len(DecryptedText) >= n + 2 Then w4 = c3 And 63 Else w4 = -1
retry = retry + mimeencode(w1) + mimeencode(w2) + mimeencode(w3) + mimeencode(w4)
Next
Encode = retry
End Function
Public Function Decode(a As String) As String
Dim w1 As Integer
Dim w2 As Integer
Dim w3 As Integer
Dim w4 As Integer
Dim n As Integer
Dim retry As String
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 retry = retry + Chr$(((w1 * 4 + Int(w2 / 16)) And 255))
If w3 >= 0 Then retry = retry + Chr$(((w2 * 16 + Int(w3 / 4)) And 255))
If w4 >= 0 Then retry = retry + Chr$(((w3 * 64 + w4) And 255))
Next
Decode = retry
End Function
Private Function mimeencode(w As Integer) As String
If w >= 0 Then mimeencode = Mid$(base64, w + 1, 1) Else mimeencode = ""
End Function
Private Function mimedecode(a As String) As Integer
If Len(a) = 0 Then mimedecode = -1: Exit Function
mimedecode = InStr(base64, a) - 1
End Function
' -------- Cut Ends -----
……