Call Com_CreatValidCode("ValidCode")
Sub Com_CreatValidCode(pSN)
'Author: Layen
'QQ: 84815733
'E-mail: [email protected]
' 禁止緩存
Response.Expires = -9999
Response.AddHeader "Pragma","no-cache"
Response.AddHeader "cache-ctrol","no-cache"
Response.ContentType = "Image/BMP"
Randomize
Dim i, ii, iii
Const cOdds = 8 ' 雜點出現的機率
Const cAmount = 36 ' 文字數量
Const cCode = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
' 顏色的資料(字符,背景)
Dim vColorData(1)
vColorData(0) = ChrB(0) & ChrB(0) & ChrB(0) ' 藍0,綠0,紅0(黑色)
vColorData(1) = ChrB(250) & ChrB(236) & ChrB(211) ' 藍250,綠236,紅211(淺藍色)
' 隨機產生字符
Dim vCode(4), vCodes
For i = 0 To 3
vCode(i) = Int(Rnd * cAmount)
vCodes = vCodes & Mid(cCode, vCode(i) + 1, 1)
Next
Session(pSN) = vCodes '記錄入Session
' 字元的數據
Dim vNumberData(35)
vNumberData(0) = "11100001111101111011110111101111010010111101001011110100101111010010111101111011101011110100101111011110111010
vNumberData(1) = "11110111111100011111111101111111110111111111011111111101111111110111111111011111111111111011011111101111101010
vNumberData(2) = "111000011111011110111101110111111111011111111011111111011111111011111111011111110111111110111111110111111010101010
vNumberData(3) = "111000011111011110111101110111111110111111100111111111101111111111011110111101110111111111101111011110111010101010
vNumberData(4) = "11111011111111101111111100111111101011111101101111110110111111000000111111101111101111110000001111111011111
vNumberData(5) = "1100000011110111111111011111111101000111110011101111111110111111110100011111001110111111111011111111101111011110111101101101
vNumberData(6) = "11110001111110111011110111111111011111111101000111110011101111011110111101111011110111101111011110111101110101010
vNumberData(7) = "11000000111101110111110111011111111011111111101111111101111111110111111111011111111101111
vNumberData(8) = "11100001111101111011110111011110111101111100001111110110111110111101111011110111011111011110111101111011101010101
vNumberData(9) = "11100011111101110111110111011110111101111011100111110001011111111101111111110111101101110
vNumberData(10) = "1111011111111101111111101011111110101111111010111111101011111100000111110111011110111111000001111101110111010
vNumberData(11) = "10000001111101111011110111101111011101111100001111110111011111011110111101111011101111101111011110111011101010101010
vNumberData(12) = "11100000111101111011101111011101111111110111111111011111111101111111110111110111111111011111111101111011101010101
vNumberData(13) = "10000011111101110111110111011110111101111011110111101111011110111101111011101111101111011110111101110111010101010
vNumberData(14) = "10000001111101111011110110111111011011111100001111110110111111011011111101111111011111101101111110111111010
vNumberData(15) = "10000001111101111011110110111111011011111100001111110110111111011011111101111111011111101101111110111111110
vNumberData(16) = "1110000111110111011110111011110111111111011111111101111111110111100011101111011111111110111000111011110111101010101
vNumberData(17) = "10001000111101110111110111011111011101111100000111110111011111011101111101110111101111101110111110111011101010101010
vNumberData(18) = "1100000111111101111111110111111111011111111101111111111111101111111110111111111011111111101111111110111111111011111011111111101101111110111101010
vNumberData(19) = "1110000011111110111111111011111111101111111110111111111111111111111110111111111011111111011111111101111111110111101110110
vNumberData(20) = "1000100011110111011111011011111101011111110001111111010111111101101111110110111110110101010
vNumberData(21) = "1000111111110111111111011111111011111111101111111111011111111101111111110111111111111110111010101011010101010101010
vNumberData(22) = "1000100011110010011111001001111100100111110101011111010101111101010111110111011101011111010101111101010111010
vNumberData(23) = "1000100011110011011111001101111101010111110101011111010101111101100111110111101010111110110011111011001111010101010
vNumberData(24) = "11100011111101110111101111011101111101110111110111011111011101111101110111110111110111011111011101111011101010101
vNumberData(25) = "1000000111110111101111011110111101111011110000011111011111111101111111110111111111111110111101111011111110
vNumberData(26) = "1110001111110111011110111101110111110111011111011101111101110111110111010011011111011101111101110100110111010101010
vNumberData(27) = "1000001111110111011111011101111101110111110000111111010111111101101111110110111111010101010
vNumberData(28) = "111000001111011110111101110111101111111111001111111111001111111111101111011110111001111111111011110111011010101010
vNumberData(29) = "10000000111011011011111101111111110111111111011111111101111111111011111111101111011111111101111111110111110110101
vNumberData(30) = "1000100011110111011111011101111101110111110111011111011110111110111011111011101111011111011101111101110111101010101
vNumberData(31) = "10001000111101110111110111011111011101111110101111111010111111101011111110101111101111111010111111101011111
vNumberData(32) = "100101001111010101111101010111110101011111010101111100100111111010111111101011111001111110101111111010111110101011
vNumberData(33) = "10001000111101110111111010111111101011111111011111111101111111101011111110101111011111111010111111101011101010101010
vNumberData(34) = "10001000111101110111110111011111101011111110101111111101111111110111111111011111011111111101111111110111110110101
vNumberData(35) = "1100000011110111011111111101111111101111111110111111110111111111101111111111111101111111110111111110111111011101010107010101010101010101010101301013373
新
Response.BinaryWrite ChrB(66) & ChrB(77) & ChrB(230) & ChrB(4) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) &_
ChrB(0) & ChrB(0) & ChrB(54) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(40) & ChrB(0) &_
ChrB(0) & ChrB(0) & ChrB(40) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(10) & ChrB(0) &_
ChrB(0) & ChrB(0) & ChrB(1) & ChrB(0)
' 輸出影像資訊頭
Response.BinaryWrite ChrB(24) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(176) & ChrB(4) &_
ChrB(0) & ChrB(0) & ChrB(18) & ChrB(11) & ChrB(0) & ChrB(0) & ChrB(18) & ChrB(11) &_
ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) &_
ChrB(0) & ChrB(0)
For i = 9 To 0 Step -1 ' 歷經所有行
為 ii = 0 To 3 ' 歷經所有字
0 iii = 1 To 10 ' 歷經所有像素
' 逐行、逐字、逐像素輸出影像數據
If Rnd * 99 + 1 < cOdds Then ' 隨機產生雜點
Response.BinaryWrite vColorData(0)
Else
Response.BinaryWrite vColorData(Mid(vNumberData(vCode(ii)), i * 10 + iii, 1))
End If
Next
Next
Next
End Sub