程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 更多關於編程 >> VBS 十六進制異或加密實現代碼

VBS 十六進制異或加密實現代碼

編輯:更多關於編程
    文件不要過大,最好不要超過 100 KB,密鑰不要用數字,不想改了。理論上支持任何二進制文件格式  

    效果圖:

    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

    1. 上一頁:
    2. 下一頁:
    Copyright © 程式師世界 All Rights Reserved