文件不要过大,最好不要超过 100 kb,密钥不要用数字,不想改了。理论上支持任何二进制文件格式
代码都封装成函数了,方便调用:
代码如下:
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
2025国考·省考课程试听报名