欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

VBS 十六进制异或加密实现代码

程序员文章站 2022-03-21 16:42:07
效果图: 代码都封装成函数了,方便调用: 复制代码 代码如下:key = "www-enun-net" '不要用数字 wscript.echo now & ", 加密...
效果图:

VBS 十六进制异或加密实现代码

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

复制代码 代码如下:

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