<%
Call CreateSafeCode()
Sub CreateSafeCode ()
'AddHeader 方法用于增加带有一个要发送到客户应用程序的特殊的HTTP头
Response.AddHeader "Pragma","no-cache"
Response.AddHeader "cache-ctrol","no-cache"
'指定响应的HTTP 内容类型为"Image/BMP"
Response.ContentType = "Image/BMP"
'生成
随机数,因为Rnd 生成一个小于1但大于或等于0的数,所以8999*Rnd +1000 得到的
'随机数为一个四位数
Randomize timer
SafeCode = cint(8999*Rnd+1000)
'将SafeCode 保存在SessionCode("SafeCode")中
Session("SafeCode") = SafeCode
' 定义一个二维数组,保存字符数据
Dim Letter(10,20)
'要显示的字符“0”
Letter(0,0) = "0000000000000000"
Letter(0,1) = "0000111110000000"
Letter(0,2) = "0001111111000000"
Letter(0,3) = "0011100011100000"
Letter(0,4) = "0011000001110000"
Letter(0,5) = "0111000000110000"
Letter(0,6) = "0110000000111000"
Letter(0,7) = "0110000000111000"
Letter(0,8) = "1110000000111000"
Letter(0,9) = "1100000000111000"
Letter(0,10) = "1100000000111000"
Letter(0,11) = "1110000000111000"
Letter(0,12) = "1110000000110000"
Letter(0,13) = "1110000000110000"
Letter(0,14) = "0110000000110000"
Letter(0,15) = "0111000001110000"
Letter(0,15) = "0011100001100000"
Letter(0,16) = "0001111111000000"
Letter(0,17) = "0000111110000000"
Letter(0,18) = "0000000000000000"
Letter(0,19) = "0000000000000000"
'要显示的字符“1”
Letter(1,0) = "0000000000000000"
Letter(1,1) = "0000000111000000"
Letter(1,2) = "0000000111000000"
Letter(1,3) = "0000001110000000"
Letter(1,4) = "0000001100000000"
Letter(1,5) = "0000001100000000"
Letter(1,6) = "0000001100000000"
Letter(1,7) = "0000011100000000"
Letter(1,8) = "0000011100000000"
Letter(1,9) = "0000011100000000"
Letter(1,10) = "0000011000000000"
Letter(1,11) = "0000011000000000"
Letter(1,12) = "0000011000000000"
Letter(1,13) = "0000011000000000"
Letter(1,14) = "0000011000000000"
Letter(1,15) = "0000011000000000"
Letter(1,16) = "0000011000000000"
Letter(1,17) = "0000001000000000"
Letter(1,18) = "0000000000000000"
Letter(1,19) = "0000000000000000"
'要显示的字符“2”
Letter(2,0) = "0000000000000000"
Letter(2,1) = "0000111111000000"
Letter(2,2) = "0001111111100000"
Letter(2,3) = "0011100001110000"
Letter(2,4) = "0111000001110000"
Letter(2,5) = "0111000001100000"
Letter(2,6) = "0110000001100000"
Letter(2,7) = "0000000011100000"
Letter(2,8) = "0000000111000000"
Letter(2,9) = "0000000111000000"
Letter(2,10) = "0000001100000000"
Letter(2,11) = "0000011100000000"
Letter(2,12) = "0000111000000000"
Letter(2,13) = "0001100000000000"
Letter(2,14) = "0001100000000000"
Letter(2,15) = "0011000001110000"
Letter(2,16) = "0110111111110000"
Letter(2,17) = "0111111111111000"
Letter(2,18) = "0111110000000000"
Letter(2,19) = "0000000000000000"
'要显示的字符“3”
Letter(3,0) = "0000000000000000"
Letter(3,1) = "0000111111100000"
Letter(3,2) = "0011111111100000"
Letter(3,3) = "0111000011110000"
Letter(3,4) = "0110000001100000"
Letter(3,5) = "0100000011100000"
Letter(3,6) = "0000000011100000"
Letter(3,7) = "0000000111000000"
Letter(3,8) = "0000001100000000"
Letter(3,9) = "0000011111000000"
Letter(3,10) = "0000010011100000"
Letter(3,11) = "0000000001110000"
Letter(3,12) = "0000000001110000"
Letter(3,13) = "0000000001110000"
Letter(3,14) = "0000000001110000"
Letter(3,15) = "0000000001100000"
Letter(3,16) = "1110000011100000"
Letter(3,17) = "1111111111000000"
Letter(3,18) = "0111111110000000"
Letter(3,19) = "0000000000000000"
'要显示的字符“4”
Letter(4,0) = "0000000000000000"
Letter(4,1) = "0000000011100000"
Letter(4,2) = "0000000111100000"
Letter(4,3) = "0000001110000000"
Letter(4,4) = "0000011101110000"
Letter(4,5) = "0000111001110000"
Letter(4,6) = "0000110001100000"
Letter(4,7) = "0001100011100000"
Letter(4,8) = "0011100011000000"
Letter(4,9) = "0111000011000000"
Letter(4,10) = "0110000011000000"
Letter(4,11) = "0110000011000000"
Letter(4,12) = "1100011111111000"
Letter(4,13) = "1111111111110000"
Letter(4,14) = "1111111110000000"
Letter(4,15) = "1110000110000000"
Letter(4,16) = "0000000111000000"
Letter(4,17) = "0000000011000000"
Letter(4,18) = "0000000011000000"
Letter(4,19) = "0000000010000000"
'要显示的字符“5”
Letter(5,0) = "0000000000000000"
Letter(5,1) = "0000110000010000"
Letter(5,2) = "0001111111111000"
Letter(5,3) = "0001111111110000"
Letter(5,4) = "0001111000000000"
Letter(5,5) = "0001100000000000"
Letter(5,6) = "0011100000000000"
Letter(5,7) = "0011100000000000"
Letter(5,8) = "0011111111000000"
Letter(5,9) = "0011111111100000"
Letter(5,10) = "0000000001100000"
Letter(5,11) = "0000000001100000"
Letter(5,12) = "0000000001100000"
Letter(5,13) = "0000000001100000"
Letter(5,14) = "0000000001100000"
Letter(5,15) = "0000000001100000"
Letter(5,16) = "0000000111100000"
Letter(5,17) = "0111111111000000"
Letter(5,18) = "0011111100000000"
Letter(5,19) = "0000000010000000"
'要显示的字符“6”
Letter(6,0) = "0000000000000000"
Letter(6,1) = "0000001111000000"
Letter(6,2) = "0000011110000000"
Letter(6,3) = "0000111000000000"
Letter(6,4) = "0001110000000000"
Letter(6,5) = "0011100000000000"
Letter(6,6) = "0011000000000000"
Letter(6,7) = "0011000000000000"
Letter(6,8) = "0111111111000000"
Letter(6,9) = "0111111111100000"
Letter(6,10) = "0111000001110000"
Letter(6,11) = "0110000000110000"
Letter(6,12) = "0110000000110000"
Letter(6,13) = "0110000000110000"
Letter(6,14) = "0110000000110000"
Letter(6,15) = "0111000001110000"
Letter(6,16) = "0011000001110000"
Letter(6,17) = "0011111111100000"
Letter(6,18) = "0001111111000000"
Letter(6,19) = "0000000000000000"
'要显示的字符“7”
Letter(7,0) = "0000000000000000"
Letter(7,1) = "0010011111111000"
Letter(7,2) = "0111111111110000"
Letter(7,3) = "0111111001110000"
Letter(7,4) = "0000000001100000"
Letter(7,5) = "0000000011100000"
Letter(7,6) = "0000000011000000"
Letter(7,7) = "0000000011000000"
Letter(7,8) = "0000000011000000"
Letter(7,9) = "0000000111000000"
Letter(7,10) = "0000000110000000"
Letter(7,11) = "0000000110000000"
Letter(7,12) = "0000000110000000"
Letter(7,13) = "0000000110000000"
Letter(7,14) = "0000001110000000"
Letter(7,15) = "0000001110000000"
Letter(7,16) = "0000001110000000"
Letter(7,17) = "0000000100000000"
Letter(7,18) = "0000000100000000"
Letter(7,19) = "0000000000000000"
'要显示的字符“8”
Letter(8,0) = "0000000000000000"
Letter(8,1) = "0000111111000000"
Letter(8,2) = "0001111111100000"
Letter(8,3) = "0011100001100000"
Letter(8,4) = "0011000001100000"
Letter(8,5) = "0111000001110000"
Letter(8,6) = "0111000001100000"
Letter(8,7) = "0011000001100000"
Letter(8,8) = "0011110111100000"
Letter(8,9) = "0001111111100000"
Letter(8,10) = "0011100011110000"
Letter(8,11) = "0111000000110000"
Letter(8,12) = "0111000000110000"
Letter(8,13) = "0110000000111000"
Letter(8,14) = "0110000000110000"
Letter(8,15) = "0110000000110000"
Letter(8,16) = "0111000001110000"
Letter(8,17) = "0011111111110000"
Letter(8,18) = "0001111111000000"
Letter(8,19) = "0000000000000000"
'要显示的字符“9”
Letter(9,0) = "0000000000000000"
Letter(9,1) = "0001111111000000"
Letter(9,2) = "0011111111100000"
Letter(9,3) = "0111000011100000"
Letter(9,4) = "0111000001110000"
Letter(9,5) = "0110000000110000"
Letter(9,6) = "0110000000110000"
Letter(9,7) = "0110000000110000"
Letter(9,8) = "0110000000110000"
Letter(9,9) = "0111000001110000"
Letter(9,10) = "0011111111110000"
Letter(9,11) = "0001111111110000"
Letter(9,12) = "0000000001100000"
Letter(9,13) = "0000000001100000"
Letter(9,14) = "0000000011100000"
Letter(9,15) = "0000000111000000"
Letter(9,16) = "0000001110000000"
Letter(9,17) = "0000011100000000"
Letter(9,18) = "0001111000000000"
Letter(9,19) = "0000000000000000"
'显示一个8位的灰度图
' 输出图像文件头
Response.BinaryWrite ChrB(66) & ChrB(77) & ChrB(54) & ChrB(9) &_
ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) &_
ChrB(0) & ChrB(0) & ChrB(54) & ChrB(4) & ChrB(0) & ChrB(0)
' 输出图像信息头
Response.BinaryWrite ChrB(40) & ChrB(0) & ChrB(0) & ChrB(0) &_
ChrB(64) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(20) & ChrB(0) &_
ChrB(0) & ChrB(0) & ChrB(1) & ChrB(0) &ChrB(8) & ChrB(0) & ChrB(0) &_
ChrB(0) & ChrB(0) & ChrB(0) & ChrB(0) & ChrB(5) & 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 = 0 To 255
Response.BinaryWrite ChrB(255-i) & ChrB(255-i) & ChrB(255-i) & ChrB(0)
Next
'输出图像数据
'图像的每一行
For iTemp1 = 19 to 0 Step -1
'图像上显示的每一个字
For iTemp2 = 1 to 4
'获得SafeCode 第iTemp2 个字符,保存在SafeCodePer 中
SafeCodePer = Mid(SafeCode,iTemp2,1)
'从字符数据Letter 数组中找到SafeCodePer 对应的数组
'例如1对应的数组为Letter(1,0) 到Letter(1,19),iTemp 指定具体的行
SafeCodeLetter = Letter(SafeCodePer,iTemp1)
'每个字的每一个像素
For iTemp3 = 1 to 16
If Rnd*99 + 1<20 Then'20为随机生成杂点的概率,可以修改
'随机生成杂点的颜色
'这样就产生了位置和颜色都随机的像素点
color = Rnd*255
Response.BinaryWrite ChrB(color)
Else
Pixel = Mid(SafeCodeLetter,iTemp3,1)*255'获得像素值
Response.BinaryWrite ChrB(Pixel)
End If
Next
Next
Next
End Sub
%>