Effect Chart:
The code is encapsulated into functions for easy invocation:
Copy Code code as follows:
Key = "Www-enun-net" ' Don't use numbers
WScript.Echo Now &, Encrypting: "
MyData = Readbin ("test.jpg")
Endata = Encoder (MyData)
Writebin "E_test.jpg", Endata
WScript.Echo Now &, Encrypting: "
WScript.Echo Now &, Decrypting: "
MyData = Readbin ("e_test.jpg")
Undata = Uncoder (MyData)
Writebin "U_test.jpg", Undata
WScript.Echo Now &, Decrypting: "
Function Readbin (FileName)
dim Stream, Objxml, Mynode
set objxml = CreateObject (" Microsoft.XMLDOM ")
set Mynode = objxml.createelement (" binary ")
set Stream = CreateObject (" ADODB ". Stream ")
mynode.datatype =" Bin.hex "
stream.type = 1
stream.open
Stream.loadfromfile FileName
mynode.nodetypedvalue = stream.read
stream.close
ReadBin = Mynode.text
set mynode = Nothing
set Stream = Nothing
set objxml = Nothing
End Function
Function writebin (FileName, Bufferdata)
dim Stream, Objxml, Mynode
set objxml = CreateObject (" Microsoft.XMLDOM ")
set Mynode = objxml.createelement (" binary ")
set Stream = CreateObject (" ADODB ". Stream ")
mynode.datatype =" Bin.hex "
mynode.text = bufferdata
stream.type = 1
Stream.open
stream.write mynode.nodetypedvalue
stream.savetofile FileName, 2
Stream.Close
set stream = Nothing
set mynode = Nothing
set objxml = Nothing
End function
Function encoder (Data)
dim K, M
for n = 0 to Len (Key)-1
k = k & ASC , Len (Key)-N), 1) & "#"
next
data = UCase (data)
for i = 0 to Len (data)-1
m = Left (right (data, i+1, 1), Len (data)-I, 1)
for j = 0 to Len (Key)-1
if i Mod Len (Key) = j Then
encoder = encoder & Hex ((ASC (M) Xor Split (K, "#") (j))
&nbs P; end If
next
next
End Function
Function Uncoder (Data)
Dim K
For n = 0 to Len (Key)-1
k = k & "#" & Asc (Left (right (key, Len (key)-N), 1) & "#X"
Next
K = k & k
data = UCase (data)
For i = 1 to Len (Data) Step 2
For j = 1 to Len (Key) * 2
If i Mod Len (Key) *2 = J Then
Uncoder = Uncoder & Chr (Split (K, "#") (j) Xor ("&h" & Mid (Data, I, 2))
End If
Next
Next
End Function