一个很简单的验证码程序

原程序
http://vifo.vicp.net:8088/datalib/ShowTopic.asp?id=108:10:1:1

主程序共三个

我的调用方式

1<script language="javascript" src="/verify/num.asp"></script>

验证方式 if trim(Loginnum)<>trim(session("Loginnum")) then
Response.Write Error("验证码错误!")
Response.End
end if

num.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  
  8Private Function EncryptString(strString)   
  9'####################################################################   
 10'### Crypt Function ? 2001 by Slavic Kozyuk [email protected] ###   
 11'### Arguments: strString <\--- String you wish to encrypt ###   
 12'### Output: Encrypted HEX string ###   
 13'####################################################################   
 14  
 15Dim CharHexSet, intStringLen, strTemp, strRAW, I, intKey, intOffSet   
 16Randomize Timer   
 17  
 18intKey = Round((RND * 1000000) + 1000000) '##### Key Bitsize   
 19intOffSet = Round((RND * 1000000) + 1000000) '##### KeyOffSet Bitsize   
 20  
 21If IsNull(strString) = False Then   
 22strRAW = strString   
 23intStringLen = Len(strRAW)   
 24  
 25For i = 0 to intStringLen - 1   
 26strTemp = Left(strRAW, 1)   
 27strRAW = Right(strRAW, Len(strRAW) - 1)   
 28CharHexSet = CharHexSet & Hex(Asc(strTemp) * intKey)& Hex(intKey)   
 29Next   
 30  
 31EncryptString = CharHexSet & "|" & Hex(intOffSet + intKey) & "|" & Hex(intOffSet)   
 32Else   
 33EncryptString = ""   
 34End If   
 35End Function   
 36  
 37  
 38  
 39  
 40Private Function DeCryptString(strCryptString)   
 41'####################################################################   
 42'### Crypt Function ? 2001 by Slavic Kozyuk [email protected] ###   
 43'### Arguments: Encrypted HEX stringt ###   
 44'### Output: Decrypted ASCII string ###   
 45'####################################################################   
 46'### Note this function uses HexConv() and get_hxno() functions ###   
 47'### so make sure they are not removed ###   
 48'####################################################################   
 49  
 50Dim strRAW, arHexCharSet, I, intKey, intOffSet, strRawKey, strHexCrypData   
 51  
 52  
 53strRawKey = Right(strCryptString, Len(strCryptString) - InStr(strCryptString, "|"))   
 54intOffSet = Right(strRawKey, Len(strRawKey) - InStr(strRawKey,"|"))   
 55intKey = HexConv(Left(strRawKey, InStr(strRawKey, "|") - 1)) - HexConv(intOffSet)   
 56strHexCrypData = Left(strCryptString, Len(strCryptString) - (Len(strRawKey) + 1))   
 57  
 58  
 59arHexCharSet = Split(strHexCrypData, Hex(intKey))   
 60  
 61For i=0 to Ubound(arHexCharSet)   
 62strRAW = strRAW & Chr(HexConv(arHexCharSet(i))/intKey)   
 63Next   
 64  
 65DeCryptString = strRAW   
 66End Function   
 67  
 68  
 69  
 70Private Function HexConv(hexVar)   
 71Dim hxx, hxx_var, multiply   
 72IF hexVar <> "" THEN   
 73hexVar = UCASE(hexVar)   
 74hexVar = StrReverse(hexVar)   
 75DIM hx()   
 76REDIM hx(LEN(hexVar))   
 77hxx = 0   
 78hxx_var = 0   
 79FOR hxx = 1 TO LEN(hexVar)   
 80IF multiply = "" THEN multiply = 1   
 81hx(hxx) = mid(hexVar,hxx,1)   
 82hxx_var = (get_hxno(hx(hxx)) * multiply) + hxx_var   
 83multiply = (multiply * 16)   
 84NEXT   
 85hexVar = hxx_var   
 86HexConv = hexVar   
 87END IF   
 88End Function   
 89  
 90Private Function get_hxno(ghx)   
 91If ghx = "A" Then   
 92ghx = 10   
 93ElseIf ghx = "B" Then   
 94ghx = 11   
 95ElseIf ghx = "C" Then   
 96ghx = 12   
 97ElseIf ghx = "D" Then   
 98ghx = 13   
 99ElseIf ghx = "E" Then   
100ghx = 14   
101ElseIf ghx = "F" Then   
102ghx = 15   
103End If   
104get_hxno = ghx   
105End Function   
106  
107randomize   
108num = int(7999*rnd+2000) '计数器的值   
109num2 = EncryptString(num)   
110session("Loginnum")=num   

document.write("

1<img src="/verify/count.asp?sksid=```
2=num2
3```"/>

") ' 这里是调用图片的路径

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

numimg.asp

  1   
  2Dim a(10,10)   
  3  
  4a(0,1) = "0x3c" '数字0   
  5a(0,2) = "0x66"   
  6a(0,3) = "0xc3"   
  7a(0,4) = "0xc3"   
  8a(0,5) = "0xc3"   
  9a(0,6) = "0xc3"   
 10a(0,7) = "0xc3"   
 11a(0,8) = "0xc3"   
 12a(0,9) = "0x66"   
 13a(0,10)= "0x3c"   
 14  
 15a(1,1) = "0x18" '数字1   
 16a(1,2) = "0x1c"   
 17a(1,3) = "0x18"   
 18a(1,4) = "0x18"   
 19a(1,5) = "0x18"   
 20a(1,6) = "0x18"   
 21a(1,7) = "0x18"   
 22a(1,8) = "0x18"   
 23a(1,9) = "0x18"   
 24a(0,10)= "0x7e"   
 25  
 26  
 27a(2,1) = "0x3c" '数字2   
 28a(2,2) = "0x66"   
 29a(2,3) = "0x60"   
 30a(2,4) = "0x60"   
 31a(2,5) = "0x30"   
 32a(2,6) = "0x18"   
 33a(2,7) = "0x0c"   
 34a(2,8) = "0x06"   
 35a(2,9) = "0x06"   
 36a(2,10)= "0x7e"   
 37  
 38a(3,1) = "0x3c" '数字3   
 39a(3,2) = "0x66"   
 40a(3,3) = "0xc0"   
 41a(3,4) = "0x60"   
 42a(3,5) = "0x1c"   
 43a(3,6) = "0x60"   
 44a(3,7) = "0xc0"   
 45a(3,8) = "0xc0"   
 46a(3,9) = "0x66"   
 47a(3,10)= "0x38"   
 48  
 49a(4,1) = "0x38" '数字4   
 50a(4,2) = "0x3c"   
 51a(4,3) = "0x36"   
 52a(4,4) = "0x33"   
 53a(4,5) = "0x33"   
 54a(4,6) = "0x33"   
 55a(4,7) = "0xff"   
 56a(4,8) = "0x30"   
 57a(4,9) = "0x30"   
 58a(4,10)= "0xfe"   
 59  
 60a(5,1) = "0xfe" '数字5   
 61a(5,2) = "0xfe"   
 62a(5,3) = "0x06"   
 63a(5,4) = "0x06"   
 64a(5,5) = "0x3e"   
 65a(5,6) = "0x60"   
 66a(5,7) = "0xc0"   
 67a(5,8) = "0xc3"   
 68a(5,9) = "0x66"   
 69a(5,10)= "0x3c"   
 70  
 71a(6,1) = "0x60" '数字6   
 72a(6,2) = "0x30"   
 73a(6,3) = "0x18"   
 74a(6,4) = "0x0c"   
 75a(6,5) = "0x3e"   
 76a(6,6) = "0x63"   
 77a(6,7) = "0xc3"   
 78a(6,8) = "0xc3"   
 79a(6,9) = "0x66"   
 80a(6,10) ="0x3c"   
 81  
 82a(7,1) = "0xff" '数字7   
 83a(7,2) = "0xc0"   
 84a(7,3) = "0x60"   
 85a(7,4) = "0x30"   
 86a(7,5) = "0x18"   
 87a(7,6) = "0x18"   
 88a(7,7) = "0x18"   
 89a(7,8) = "0x18"   
 90a(7,9) = "0x18"   
 91a(7,10)= "0x18"   
 92  
 93a(8,1) = "0x3c" '数字8   
 94a(8,2) = "0x66"   
 95a(8,3) = "0xc3"   
 96a(8,4) = "0x66"   
 97a(8,5) = "0x3c"   
 98a(8,6) = "0x66"   
 99a(8,7) = "0xc3"   
100a(8,8) = "0xc3"   
101a(8,9) = "0x66"   
102a(8,10)= "0x3c"   
103  
104a(9,1) = "0x3c" '数字9   
105a(9,2) = "0x66"   
106a(9,3) = "0xc3"   
107a(9,4) = "0xc3"   
108a(9,5) = "0x66"   
109a(9,6) = "0x3c"   
110a(9,7) = "0x18"   
111a(9,8) = "0x0c"   
112a(9,9) = "0x06"   
113a(9,10)= "0x03"   
114  
Published At
Categories with Web编程
Tagged with
comments powered by Disqus