VBS 十六进制异或加密实现代码
来源:易贤网 阅读:1342 次 日期:2014-05-09 16:53:27
温馨提示:易贤网小编为您整理了“VBS 十六进制异或加密实现代码”,方便广大网友查阅!

文件不要过大,最好不要超过 100 KB,密钥不要用数字,不想改了。理论上支持任何二进制文件格式

效果图:

1.jpg

代码都封装成函数了,方便调用:

代码如下:

Key = "www-enun-net" '不要用数字

Wscript.echo now & ", 加密: "

MyData = ReadBin("test.jpg")

EnData = Encoder(MyData)

WriteBin "E_test.jpg", EnData

Wscript.echo now & ", 加密: "

Wscript.echo now & ", 解密: "

MyData = ReadBin("E_test.jpg")

UnData = Uncoder(MyData)

WriteBin "U_test.jpg", UnData

Wscript.echo now & ", 解密: "

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, 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

Uncoder = Uncoder & Chr(Split(K, "#")(j) Xor ("&H" & Mid(Data, i, 2)))

End If

Next

Next

End Function

更多信息请查看IT技术专栏

更多信息请查看脚本栏目
易贤网手机网站地址:VBS 十六进制异或加密实现代码
由于各方面情况的不断调整与变化,易贤网提供的所有考试信息和咨询回复仅供参考,敬请考生以权威部门公布的正式信息和咨询为准!
关于我们 | 联系我们 | 人才招聘 | 网站声明 | 网站帮助 | 非正式的简要咨询 | 简要咨询须知 | 加入群交流 | 手机站点 | 投诉建议
工业和信息化部备案号:滇ICP备2023014141号-1 云南省教育厅备案号:云教ICP备0901021 滇公网安备53010202001879号 人力资源服务许可证:(云)人服证字(2023)第0102001523号
云南网警备案专用图标
联系电话:0871-65317125(9:00—18:00) 获取招聘考试信息及咨询关注公众号:hfpxwx
咨询QQ:526150442(9:00—18:00)版权所有:易贤网
云南网警报警专用图标