zoukankan      html  css  js  c++  java
  • ASP 简单的异或加密方法

    <%
    最简单的加密方法:XOR
    ----------------------

    g_CryptThis = "中国-China"
    strFullKeyLen = Len(g_CryptThis)

    strFullKey = KeyGen(strFullKeyLen)

    Response.Write "<p>原始字符串: " & g_CryptThis & "<p>"
    Response.Write "<p>密钥: " & strFullKey  & "<p>"
    Response.Write "<p>加密后: " & Server.URLEncode(EnCrypt(g_CryptThis)) & "<p>"
    Response.Write "<p>解密后: " & DeCrypt(EnCrypt(g_CryptThis)) & "<p>"

    异或加密
    Function EnCrypt(strCryptThis)
       Dim strChar, iKeyChar, iStringChar, i
       for i = 1 to Len(strCryptThis)
          iKeyChar = Asc(mid(strFullKey,i,1))
          iStringChar = Asc(mid(strCryptThis,i,1))
          iCryptChar = iKeyChar Xor iStringChar
          strEncrypted =  strEncrypted & Chr(iCryptChar)
       next
       EnCrypt = strEncrypted
    End Function

    异或解密
    Function DeCrypt(strEncrypted)
    Dim strChar, iKeyChar, iStringChar, i
       for i = 1 to Len(strEncrypted)
          iKeyChar = (Asc(mid(strFullKey,i,1)))
          iStringChar = Asc(mid(strEncrypted,i,1))
          iDeCryptChar = iKeyChar Xor iStringChar
          strDecrypted =  strDecrypted & Chr(iDeCryptChar)
       next
       DeCrypt = strDecrypted
    End Function

    产生指定长度的随机密钥
    Function KeyGen(strlength)
        Dim i,UB
        Dim Temp
        Dim Poss
        Poss = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
        Temp = ""

        UB = Len(Poss)
        For i = 1 To strlength
            Randomize
            Temp = Temp & Mid(Poss,Int((UB - 0 + 1) * Rnd + 1),1)
        Next
        KeyGen = Temp
    End Function
    %>
  • 相关阅读:
    【第36题】2019年OCP认证12C题库062考试最新考试原题
    004 基本命令 touch cp mv 命令
    003 基本指令 mkdir rm -rf(暴力删除)
    002 文件目录类的指令 cd ls
    001 指定运行级别
    005 抽象工厂模式
    006 使用类加载器加载资源文件
    004 方法反射
    003 属性反射
    003 工厂方法模式
  • 原文地址:https://www.cnblogs.com/love2wllw/p/1730662.html
Copyright © 2011-2022 走看看