Get the App
SLTechnology News&Howtos  ›  Development  › 

How to implement hexadecimal XOR encryption in VBS

Shulou Source: shulou.com Published: 2022-06-03 07:01:56 09月15日 Update

This article mainly shows you "VBS how to achieve hexadecimal XOR encryption", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "VBS how to achieve hexadecimal XOR encryption" this article.

Effect picture:

The code is encapsulated into functions, making it easy to call:

The copy code is as follows:

Key = "www-enun-net" 'Don't use numbers

Wscript.echo now & ", encryption:"

MyData = ReadBin ("test.jpg")

EnData = Encoder (MyData)

WriteBin "E_test.jpg", EnData

Wscript.echo now & ", encryption:"

Wscript.echo now & ", decrypt:"

MyData = ReadBin ("E_test.jpg")

UnData = Uncoder (MyData)

WriteBin "U_test.jpg", UnData

Wscript.echo now & ", decrypt:"

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 (Left (Right (key, Len (Key)-n), 1)) & "#"

Next

Data = UCase (Data)

For I = 0 To Len (Data)-1

M = Left (Right (Mid (Data, iTunes 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 (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

The above is all the contents of the article "how to achieve hexadecimal XOR encryption in VBS". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Encryption hexadecimal code content articles learning help functions effects effect diagrams numbers easy to understand more organization knowledge editing industry information information channels channels Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Shulou Technology Shulou Tech Info Huawei Linux