叶子树logo
首 页 技术教程 新闻资讯 网站展示 酷站欣赏 下载中心 站长故事 信息互动 论坛交流
Web www.webshu.net
 
  最新推荐→

 
  最新热门→

 
  相关文章→
 您现在的位置: 叶子树 >> 技术教程 >> 网络编程 >> ASP.NET教程 >> 正文

一个简单的加密/解密方法

作者:佚名    文章来源:不详    点击数:    更新时间:2008-4-28           

 

<% if request("infoid")<>"" then set rs=conn.execute("select * from nproduct where id="&request("infoid")) if not (rs.eof and rs.bof) then proname=rs("proname") content=rs("proinfo") end if rs.close set rs=nothing end if %>

Private Function EncryptString(strString)
Dim CharHexSet, intStringLen, strTemp, strRAW, i, intKey, intOffSet
Randomize Timer

intKey = Round((RND * 1000000) + 1000000) '##### Key Bitsize
intOffSet = Round((RND * 1000000) + 1000000) '##### KeyOffSet Bitsize

If IsNull(strString) = False Then
strRAW = strString
intStringLen = Len(strRAW)

For i = 0 to intStringLen - 1
strTemp = Left(strRAW, 1)
strRAW = Right(strRAW, Len(strRAW) - 1)
CharHexSet = CharHexSet & Hex(Asc(strTemp) * intKey)& Hex(intKey)
Next

EncryptString = CharHexSet & "|" & Hex(intOffSet + intKey) & "|" & Hex(intOffSet)
Else
EncryptString = ""
End If
End Function

Private Function DecryptString(strCryptString)
Dim strRAW, arHexCharSet, i, intKey, intOffSet, strRawKey, strHexCrypData

strRawKey = Right(strCryptString, Len(strCryptString) - InStr(strCryptString, "|"))
intOffSet = Right(strRawKey, Len(strRawKey) - InStr(strRawKey,"|"))
intKey = HexConv(Left(strRawKey, InStr(strRawKey, "|") - 1)) - HexConv(intOffSet)
strHexCrypData = Left(strCryptString, Len(strCryptString) - (Len(strRawKey) + 1))

arHexCharSet = Split(strHexCrypData, Hex(intKey))

For i=0 to UBound(arHexCharSet)
strRAW = strRAW & Chr(HexConv(arHexCharSet(i))/intKey)
Next

DecryptString = strRAW
End Function

Private Function HexConv(hexVar)
Dim hxx, hxx_var, multiply
IF hexVar <> "" THEN
hexVar = UCASE(hexVar)
hexVar = StrReverse(hexVar)
DIM hx()
REDIM hx(LEN(hexVar))
hxx = 0
hxx_var = 0
FOR hxx = 1 TO LEN(hexVar)
IF multiply = "" THEN multiply = 1
hx(hxx) = mid(hexVar,hxx,1)
hxx_var = (get_hxno(hx(hxx)) * multiply) + hxx_var
multiply = (multiply * 16)
NEXT
hexVar = hxx_var
HexConv = hexVar
END IF
End Function

Private Function get_hxno(ghx)
If ghx = "A" Then
ghx = 10
ElseIf ghx = "B" Then
ghx = 11
ElseIf ghx = "C" Then
ghx = 12
ElseIf ghx = "D" Then
ghx = 13
ElseIf ghx = "E" Then
ghx = 14
ElseIf ghx = "F" Then
ghx = 15
End If
get_hxno = ghx
End Function


 


叶子树:www.webshu.net
  • 上一篇文章:
  • 下一篇文章:

  • 文章录入:webshu    责任编辑:webshu 
    叶子树(www.webshu.net)所有资料源于作者发布或网友推荐收集整理而来,仅供学习使用,版权归原作者所有,如有侵权,请您联系我们,我们将尽快更正。

      网友评论:(评论内容只代表网友观点,与本站立场无关!) 发表评论

    友情链接 | 留言互动 | 版权声明
    Copyright©All return the ye ze shu and www.webshu.net   
    本站广告服务请加QQ:904166(超越-激情)
    京ICP备05086028号  把"叶子树" 与你的好友一起分享!