VBS hex-XOR or cryptographic implementation code

Source: Internet
Author: User
Tags split
The file should not be too large, preferably not more than KB, the key do not use numbers, do not want to change. Theoretically supports any binary file format

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 = no
 set objxml = Nothing
End function< /p>

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 = no
 set objxml = Nothing
End Function

Function encoder (Data)
 dim K, M
 for n = 0 to Len (Key)-1
  k = k & Asc ( Key, Len (key)-N, 1) & "#"
 next
 data = UCase (data)
 for i = 0 to Len (data)-1
 & nbsp 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))
    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
&NBSP;&NBSP;&NBSP;&NB Sp 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.