找回密码
 注册
【阿里云】2核2G云新老同享 99元/年,续费同价华为云精选云产品特惠做网站就用糖果主机Jtti,新加坡服务器,美国服务器,香港服务器
查看: 658|回复: 4

ASP验证码的程序及原理

[复制链接]
发表于 2005 年 6 月 12 日 14:16:45 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

×
  ##### 版权所有 转载请保留 谢谢合作
##### 部分程序取自网络
##### 作者:扬子
##### Email: yangzinet@hotmail.com
##### QQ: 21112856
##### WebSite: www.tingfo.net

一共4个页面:form.asp; chk.asp; num.asp; count.asp
得到一个随即数字。加密!
解密后成成XBM图片
利用session 判断

form.asp
  1. <%
  2. '### To encrypt/decrypt include this code in your page
  3. '### strMyEncryptedString = EncryptString(strString)
  4. '### strMyDecryptedString = DeCryptString(strMyEncryptedString)
  5. '### You are free to use this code as long as credits remain in place
  6. '### also if you improve this code let me know.
  7. Private Function EncryptString(strString)
  8. '####################################################################
  9. '### Crypt Function (C) 2001 by Slavic Kozyuk [email]grindkore@yahoo.com[/email] ###
  10. '### Arguments: strString <--- String you wish to encrypt ###
  11. '### Output: Encrypted HEX string ###
  12. '####################################################################
  13. Dim CharHexSet, intStringLen, strTemp, strRAW, i, intKey, intOffSet
  14. Randomize Timer
  15. intKey = Round((RND * 1000000) + 1000000) '##### Key Bitsize
  16. intOffSet = Round((RND * 1000000) + 1000000) '##### KeyOffSet Bitsize
  17. If IsNull(strString) = False Then
  18. strRAW = strString
  19. intStringLen = Len(strRAW)
  20. For i = 0 to intStringLen - 1
  21. strTemp = Left(strRAW, 1)
  22. strRAW = Right(strRAW, Len(strRAW) - 1)
  23. CharHexSet = CharHexSet & Hex(Asc(strTemp) * intKey)& Hex(intKey)
  24. Next
  25. EncryptString = CharHexSet & "|" & Hex(intOffSet + intKey) & "|" & Hex(intOffSet)
  26. Else
  27. EncryptString = ""
  28. End If
  29. End Function
  30. Private Function DeCryptString(strCryptString)
  31. '####################################################################
  32. '### Crypt Function (C) 2001 by Slavic Kozyuk [email]grindkore@yahoo.com[/email] ###
  33. '### Arguments: Encrypted HEX stringt ###
  34. '### Output: Decrypted ASCII string ###
  35. '####################################################################
  36. '### Note this function uses HexConv() and get_hxno() functions ###
  37. '### so make sure they are not removed ###
  38. '####################################################################
  39. Dim strRAW, arHexCharSet, i, intKey, intOffSet, strRawKey, strHexCrypData
  40. strRawKey = Right(strCryptString, Len(strCryptString) - InStr(strCryptString, "|"))
  41. intOffSet = Right(strRawKey, Len(strRawKey) - InStr(strRawKey,"|"))
  42. intKey = HexConv(Left(strRawKey, InStr(strRawKey, "|") - 1)) - HexConv(intOffSet)
  43. strHexCrypData = Left(strCryptString, Len(strCryptString) - (Len(strRawKey) + 1))
  44. arHexCharSet = Split(strHexCrypData, Hex(intKey))
  45. For i=0 to UBound(arHexCharSet)
  46. strRAW = strRAW & Chr(HexConv(arHexCharSet(i))/intKey)
  47. Next
  48. DeCryptString = strRAW
  49. End Function
  50. Private Function HexConv(hexVar)
  51. Dim hxx, hxx_var, multiply
  52. IF hexVar <> "" THEN
  53. hexVar = UCASE(hexVar)
  54. hexVar = StrReverse(hexVar)
  55. DIM hx()
  56. REDIM hx(LEN(hexVar))
  57. hxx = 0
  58. hxx_var = 0
  59. FOR hxx = 1 TO LEN(hexVar)
  60. IF multiply = "" THEN multiply = 1
  61. hx(hxx) = mid(hexVar,hxx,1)
  62. hxx_var = (get_hxno(hx(hxx)) * multiply) + hxx_var
  63. multiply = (multiply * 16)
  64. NEXT
  65. hexVar = hxx_var
  66. HexConv = hexVar
  67. END IF
  68. End Function
  69. Private Function get_hxno(ghx)
  70. If ghx = "A" Then
  71. ghx = 10
  72. ElseIf ghx = "B" Then
  73. ghx = 11
  74. ElseIf ghx = "C" Then
  75. ghx = 12
  76. ElseIf ghx = "D" Then
  77. ghx = 13
  78. ElseIf ghx = "E" Then
  79. ghx = 14
  80. ElseIf ghx = "F" Then
  81. ghx = 15
  82. End If
  83. get_hxno = ghx
  84. End Function
  85. %>
  86. <%
  87. randomize
  88. num = int(7999*rnd+2000) '计数器的值
  89. num2 = EncryptString(num)
  90. session("pwdt")=num
  91. %>
  92. <form action="chk.asp" method=post>
  93. 请输入验证码: <input type="text" name="pwds">
  94. <img src="count.asp?sksid=<%=num2%>"> <input type=submit value=提交>
  95. </form>
复制代码




chk.asp
  1. <%
  2. if trim(request.form("pwds"))<>trim(session("pwdt")) then
  3. %>
  4. 输入错误: 应该为:<%=session("pwdt")%>,可你输入的是:<%=request.form("pwds")%>
  5. <%
  6. else
  7. %>
  8. 输入正确
  9. <%end if%>
复制代码




count.asp
  1. <!--#include file="num.asp"-->
  2. <%
  3. '### To encrypt/decrypt include this code in your page
  4. '### strMyEncryptedString = EncryptString(strString)
  5. '### strMyDecryptedString = DeCryptString(strMyEncryptedString)
  6. '### You are free to use this code as long as credits remain in place
  7. '### also if you improve this code let me know.
  8. Private Function EncryptString(strString)
  9. '####################################################################
  10. '### Crypt Function (C) 2001 by Slavic Kozyuk [email]grindkore@yahoo.com[/email] ###
  11. '### Arguments: strString <--- String you wish to encrypt ###
  12. '### Output: Encrypted HEX string ###
  13. '####################################################################
  14. Dim CharHexSet, intStringLen, strTemp, strRAW, i, intKey, intOffSet
  15. Randomize Timer
  16. intKey = Round((RND * 1000000) + 1000000) '##### Key Bitsize
  17. intOffSet = Round((RND * 1000000) + 1000000) '##### KeyOffSet Bitsize
  18. If IsNull(strString) = False Then
  19. strRAW = strString
  20. intStringLen = Len(strRAW)
  21. For i = 0 to intStringLen - 1
  22. strTemp = Left(strRAW, 1)
  23. strRAW = Right(strRAW, Len(strRAW) - 1)
  24. CharHexSet = CharHexSet & Hex(Asc(strTemp) * intKey)& Hex(intKey)
  25. Next
  26. EncryptString = CharHexSet & "|" & Hex(intOffSet + intKey) & "|" & Hex(intOffSet)
  27. Else
  28. EncryptString = ""
  29. End If
  30. End Function
  31. Private Function DeCryptString(strCryptString)
  32. '####################################################################
  33. '### Crypt Function (C) 2001 by Slavic Kozyuk [email]grindkore@yahoo.com[/email] ###
  34. '### Arguments: Encrypted HEX stringt ###
  35. '### Output: Decrypted ASCII string ###
  36. '####################################################################
  37. '### Note this function uses HexConv() and get_hxno() functions ###
  38. '### so make sure they are not removed ###
  39. '####################################################################
  40. Dim strRAW, arHexCharSet, i, intKey, intOffSet, strRawKey, strHexCrypData
  41. strRawKey = Right(strCryptString, Len(strCryptString) - InStr(strCryptString, "|"))
  42. intOffSet = Right(strRawKey, Len(strRawKey) - InStr(strRawKey,"|"))
  43. intKey = HexConv(Left(strRawKey, InStr(strRawKey, "|") - 1)) - HexConv(intOffSet)
  44. strHexCrypData = Left(strCryptString, Len(strCryptString) - (Len(strRawKey) + 1))
  45. arHexCharSet = Split(strHexCrypData, Hex(intKey))
  46. For i=0 to UBound(arHexCharSet)
  47. strRAW = strRAW & Chr(HexConv(arHexCharSet(i))/intKey)
  48. Next
  49. DeCryptString = strRAW
  50. End Function
  51. Private Function HexConv(hexVar)
  52. Dim hxx, hxx_var, multiply
  53. IF hexVar <> "" THEN
  54. hexVar = UCASE(hexVar)
  55. hexVar = StrReverse(hexVar)
  56. DIM hx()
  57. REDIM hx(LEN(hexVar))
  58. hxx = 0
  59. hxx_var = 0
  60. FOR hxx = 1 TO LEN(hexVar)
  61. IF multiply = "" THEN multiply = 1
  62. hx(hxx) = mid(hexVar,hxx,1)
  63. hxx_var = (get_hxno(hx(hxx)) * multiply) + hxx_var
  64. multiply = (multiply * 16)
  65. NEXT
  66. hexVar = hxx_var
  67. HexConv = hexVar
  68. END IF
  69. End Function
  70. Private Function get_hxno(ghx)
  71. If ghx = "A" Then
  72. ghx = 10
  73. ElseIf ghx = "B" Then
  74. ghx = 11
  75. ElseIf ghx = "C" Then
  76. ghx = 12
  77. ElseIf ghx = "D" Then
  78. ghx = 13
  79. ElseIf ghx = "E" Then
  80. ghx = 14
  81. ElseIf ghx = "F" Then
  82. ghx = 15
  83. End If
  84. get_hxno = ghx
  85. End Function
  86. %>
  87. <%
  88. Dim Image
  89. Dim Width, Height
  90. Dim num
  91. Dim digtal
  92. Dim Length
  93. Dim sort
  94. Length = 4 '自定计数器长度
  95. Redim sort( Length )
  96. num=cint(DeCryptString(request.querystring("sksid")))
  97. digital = ""
  98. For I = 1 To Length -Len( num ) '补0
  99. digital = digital & "0"
  100. Next
  101. For I = 1 To Len( num )
  102. digital = digital & Mid( num, I, 1 )
  103. Next
  104. For I = 1 To Len( digital )
  105. sort(I) = Mid( digital, I, 1 )
  106. Next
  107. Width = 8 * Len( digital ) '图像的宽度
  108. Height = 10 '图像的高度,在本例中为固定值
  109. Response.ContentType="image/x-xbitmap"
  110. hc=chr(13) & chr(10)
  111. Image = "#define counter_width " & Width & hc
  112. Image = Image & "#define counter_height " & Height & hc
  113. Image = Image & "static unsigned char counter_bits[]={" & hc
  114. For I = 1 To Height
  115. For J = 1 To Length
  116. Image = Image & a(sort(J),I) & ","
  117. Next
  118. Next
  119. Image = Left( Image, Len( Image ) - 1 ) '去掉最后一个逗号
  120. Image = Image & "};" & hc
  121. %>
  122. <%
  123. Response.Write Image
  124. %>
复制代码




num.asp
  1. <%
  2. Dim a(10,10)
  3. a(0,1) = "0x3c" '数字0
  4. a(0,2) = "0x66"
  5. a(0,3) = "0xc3"
  6. a(0,4) = "0xc3"
  7. a(0,5) = "0xc3"
  8. a(0,6) = "0xc3"
  9. a(0,7) = "0xc3"
  10. a(0,8) = "0xc3"
  11. a(0,9) = "0x66"
  12. a(0,10)= "0x3c"
  13. a(1,1) = "0x18" '数字1
  14. a(1,2) = "0x1c"
  15. a(1,3) = "0x18"
  16. a(1,4) = "0x18"
  17. a(1,5) = "0x18"
  18. a(1,6) = "0x18"
  19. a(1,7) = "0x18"
  20. a(1,8) = "0x18"
  21. a(1,9) = "0x18"
  22. a(0,10)= "0x7e"
  23. a(2,1) = "0x3c" '数字2
  24. a(2,2) = "0x66"
  25. a(2,3) = "0x60"
  26. a(2,4) = "0x60"
  27. a(2,5) = "0x30"
  28. a(2,6) = "0x18"
  29. a(2,7) = "0x0c"
  30. a(2,8) = "0x06"
  31. a(2,9) = "0x06"
  32. a(2,10)= "0x7e"
  33. a(3,1) = "0x3c" '数字3
  34. a(3,2) = "0x66"
  35. a(3,3) = "0xc0"
  36. a(3,4) = "0x60"
  37. a(3,5) = "0x1c"
  38. a(3,6) = "0x60"
  39. a(3,7) = "0xc0"
  40. a(3,8) = "0xc0"
  41. a(3,9) = "0x66"
  42. a(3,10)= "0x38"
  43. a(4,1) = "0x38" '数字4
  44. a(4,2) = "0x3c"
  45. a(4,3) = "0x36"
  46. a(4,4) = "0x33"
  47. a(4,5) = "0x33"
  48. a(4,6) = "0x33"
  49. a(4,7) = "0xff"
  50. a(4,8) = "0x30"
  51. a(4,9) = "0x30"
  52. a(4,10)= "0xfe"
  53. a(5,1) = "0xfe" '数字5
  54. a(5,2) = "0xfe"
  55. a(5,3) = "0x06"
  56. a(5,4) = "0x06"
  57. a(5,5) = "0x3e"
  58. a(5,6) = "0x60"
  59. a(5,7) = "0xc0"
  60. a(5,8) = "0xc3"
  61. a(5,9) = "0x66"
  62. a(5,10)= "0x3c"
  63. a(6,1) = "0x60" '数字6
  64. a(6,2) = "0x30"
  65. a(6,3) = "0x18"
  66. a(6,4) = "0x0c"
  67. a(6,5) = "0x3e"
  68. a(6,6) = "0x63"
  69. a(6,7) = "0xc3"
  70. a(6,8) = "0xc3"
  71. a(6,9) = "0x66"
  72. a(6,10) ="0x3c"
  73. a(7,1) = "0xff" '数字7
  74. a(7,2) = "0xc0"
  75. a(7,3) = "0x60"
  76. a(7,4) = "0x30"
  77. a(7,5) = "0x18"
  78. a(7,6) = "0x18"
  79. a(7,7) = "0x18"
  80. a(7,8) = "0x18"
  81. a(7,9) = "0x18"
  82. a(7,10)= "0x18"
  83. a(8,1) = "0x3c" '数字8
  84. a(8,2) = "0x66"
  85. a(8,3) = "0xc3"
  86. a(8,4) = "0x66"
  87. a(8,5) = "0x3c"
  88. a(8,6) = "0x66"
  89. a(8,7) = "0xc3"
  90. a(8,8) = "0xc3"
  91. a(8,9) = "0x66"
  92. a(8,10)= "0x3c"
  93. a(9,1) = "0x3c" '数字9
  94. a(9,2) = "0x66"
  95. a(9,3) = "0xc3"
  96. a(9,4) = "0xc3"
  97. a(9,5) = "0x66"
  98. a(9,6) = "0x3c"
  99. a(9,7) = "0x18"
  100. a(9,8) = "0x0c"
  101. a(9,9) = "0x06"
  102. a(9,10)= "0x03"
  103. %>
复制代码
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
发表于 2005 年 6 月 14 日 13:09:15 | 显示全部楼层
【腾讯云】2核2G云服务器新老同享 99元/年,续费同价
支持, 很有用的
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

发表于 2005 年 6 月 14 日 16:57:18 | 显示全部楼层
网站在线批量查找替换程序

网站在线批量查找替换程序

如果您的网站某个目录下有很多文件,这些文件需要同时,修改其中相同内容时,可以用我们开发的网页修改小精灵,只需要在我的网站留下你的邮箱,说明需要什么代码,我会在两个工作日内发给你
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

发表于 2005 年 6 月 15 日 00:19:07 | 显示全部楼层
支持!
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

发表于 2005 年 6 月 15 日 11:18:39 | 显示全部楼层
呵呵
很好
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|金光论坛

GMT+8, 2024 年 11 月 19 日 22:45 , Processed in 0.117898 second(s), 21 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表