-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetBase64.vbs
90 lines (83 loc) · 2.29 KB
/
GetBase64.vbs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
on error resume next
Set argv = WScript.Arguments
If argv.Count = 0 Then
data = Inputbox("欢迎使用 Base64 编码小工具!"& vbCrLf& " "& vbCrLf& "请输入源码:" ,"Base64 编码小工具")
If data =vbEmpty Then
WScript.Quit
End If
data = ConvertStringToUTF8(data)
Else
data=""
With CreateObject("ADODB.Stream")
.Mode = 3: .Type = 1: .Open: .LoadFromFile argv(0)
.Read(3)
For j = 3 To .Size - 1
tmp = AscB(.Read(1))
If tmp < 16 Then
tmp = "0" & Hex(tmp)
Else tmp = Hex(tmp)
End If
data =data & tmp
Next
.Close
End With
End If
newdata = ""
For j = 1 To Len(data) Step 2
tmp = CLng("&H"&Mid(data,j,2))
m = ""
Do
m = m & tmp mod 2
tmp = tmp\2
Loop Until tmp=0
m = StrReverse(m)
Do While Len(m)<8
m = "0" & m
Loop
newdata = newdata & m
Next
res = ""
For j = 1 To Len(newdata) Step 6
tmp = Mid(newdata, j, 6)
num = 0
For i = 1 To 6
m = Mid(tmp, i, 1)
if m = "" Then m = 0
num = num * 2 + m
Next
If num <= 25 Then
res = res & chr(65+num)
ElseIf num <= 51 Then
res = res & chr(71+num)
ElseIf num <=61 Then
res = res & chr(num-4)
ElseIf num = 62 Then
res = res & "+"
ElseIf num = 63 Then
res = res & "/"
End If
Next
tmp = Len(res) mod 4
If tmp <>0 Then
For j = 1 To 4-tmp
res = res & "="
Next
End If
Set fso=CreateObject("Scripting.FileSystemObject")
Set ts = fso.CreateTextFile("base64.txt", true)
ts.write res
WScript.Echo "Base64 编码是:"&vbCrlf&" "& vbCrLf & res &vbCrlf&" "& vbCrLf& "Base64 编码将自动导出到同目录下的“base64.txt”文件中。"
'InputBox "结果如下","",res,"Base64 编码小工具"
Function ConvertStringToUTF8(TextString)
Set objXmlDom = CreateObject("Microsoft.XMLDOM")
Set objNode = objXmlDom.CreateElement("Binary")
objNode.DataType = "bin.hex"
With CreateObject("ADODB.Stream")
.Type = 2:.Charset = "UTF-8":.Open
.WriteText TextString
.Position = 0:.Type = 1
objNode.nodeTypedValue = .Read
.Close
End With
ConvertStringToUTF8 = Mid(objNode.Text,7)
End Function