VBS hex-XOR or cryptographic implementation code _vbs

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.