ASP验证码的实现原理及源码
作者:扬子 来源:tingfo.net 时间:2007-10-02 12:14:00
共4个页面:form.asp; chk.asp; num.asp; count.asp,得到一个随即数字。加密解密后成成XBM图片,利用 session 判断。
form.asp
<%
’### To encrypt/decrypt include this code in your page
’### strMyEncryptedString = EncryptString(strString)
’### strMyDecryptedString = DeCryptString(strMyEncryptedString)
’### You are free to use this code as long as credits remain in place
’### also if you improve this code let me know.
Private Function EncryptString(strString)
’####################################################################
’### Crypt Function (C) 2001 by Slavic Kozyuk grindkore@yahoo.com ###
’### Arguments: strString <--- String you wish to encrypt ###
’### Output: Encrypted HEX string ###
’####################################################################
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)
’####################################################################
’### Crypt Function (C) 2001 by Slavic Kozyuk grindkore@yahoo.com ###
’### Arguments: Encrypted HEX stringt ###
’### Output: Decrypted ASCII string ###
’####################################################################
’### Note this function uses HexConv() and get_hxno() functions ###
’### so make sure they are not removed ###
’####################################################################
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
%>
<%
randomize
num = int(7999*rnd+2000) ’计数器的值
num2 = EncryptString(num)
session("pwdt")=num
%>
<form action="chk.asp" method=post>
请输入验证码: <input type="text" name="pwds">
<img src="count.asp?sksid=<%=num2%>"> <input type=submit value=提交>
</form>
标签:验证码,原理
0
投稿
猜你喜欢
Python图片批量自动抠图去背景的代码详解
2022-11-30 17:20:39
页面中横排布局的思考
2008-01-18 12:56:00
Python分析最近大火的网剧《隐秘的角落》
2023-07-17 07:09:04
tensorflow中的数据类型dtype用法说明
2023-08-28 05:44:30
python查找特定名称文件并按序号、文件名分行打印输出的方法
2023-11-27 03:35:35
CSS框架带来的效率提升
2007-12-27 20:01:00
Django 中间键和上下文处理器的使用
2022-04-19 05:04:56
使用python库xlsxwriter库来输出各种xlsx文件的示例
2022-04-27 14:50:30
JS中判断null、undefined与NaN的方法
2024-04-19 09:54:05
Go语言实现的树形结构数据比较算法实例
2023-08-06 18:18:39
Python tkinter 多选按钮控件 Checkbutton方法
2022-12-31 08:38:46
vue实现表单验证功能
2024-06-05 10:03:59
python装饰器代码解析
2021-12-29 19:39:07
JavaScript导出Excel实例详解
2023-09-06 15:51:27
Qzoneing主题视觉设计分享
2009-07-21 18:12:00
js取得当前鼠标的X,Y坐标
2007-09-27 19:52:00
php for 循环语句使用方法详细说明
2023-11-17 21:43:21
python单元测试unittest实例详解
2023-10-16 08:26:49
JavaScript实现五子棋游戏的方法详解
2024-04-30 10:11:54
SQLSERVER数据库备份后无法还原的解决办法
2024-01-21 14:05:01