加入杂点象素asp验证码生成程序

call createsafecode()   '调用createsafecode过程
sub createsafecode()   '定义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"

 '24位图
 '输出图像文件头
 'response.binarywrite chrb(66) & chrb(77) & chrb(54) & chrb(15) & chrb(0) & chrb(0) & chrb(0) & chrb(0) &  chrb(0) & chrb(0) & chrb(54) & chrb(0) & 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(24) & chrb(0) & chrb(0) & chrb(0) & chrb(0) & chrb(0) & chrb(0) & chrb(15) & 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 itemp1=19 to 0 step -1   '每一行
  'for itemp2=1 to len(safecode)   '每一个字
   'for itemp3=1 to 16   '每一个像素
    'response.binarywrite vcolordata(mid(letter(mid(safecode,itemp2,1),itemp1),itemp3,1))
   'next
  'next
 'next
 
 '显示一个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   '图像上显示的每一个字
   for itemp3=1 to 16   '每个字的每一个像素
    '获得safecode第itemp2个字符,保存在safecodeper中
    safecodeper=mid(safecode,itemp2,1)
    '从字符数据letter数组中找到safecodeper对应的数组,例如1对应的数组为letter(1,0)到letter(1,19),itemp指定具体的行
    safecodeletter=letter(safecodeper,itemp1)
    '获得像素值

    '代替代码
    '图片中加入杂点象素
    pixel=mid(safecodeletter,itemp3,1)*255
    if rnd*99+1<5 then   '5为随机生成杂点的概率,可以修改
     response.binarywrite chrb(128)   '杂点的颜色为128
    else
     response.binarywrite chrb(pixel)
    end if
    '代替结束

   next
  next
 next
end sub
%>

时间: 2024-10-29 13:24:49

加入杂点象素asp验证码生成程序的相关文章

asp验证码生成程序

//原创:www.111cn.net 注明:转载请注明www.111cn.net // 下面来说说asp程序生成验证的方法. <% Option Explicit Response.buffer=true NumCode dim znum Function NumCode()         Response.Expires = -1         Response.AddHeader "Pragma","no-cache"         Response

jsp验证码生成程序与调用方法

jsp教程验证码生成程序与调用方法 package com.city.sxzlc.servlet; import java.awt.Color; import java.awt.Graphics; import java.awt.image.BufferedImage; import java.io.IOException; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Random; impo

php 验证码生成程序[可自动判断php gd库]

php 验证码生成程序[可自动判断php gd库] function ShowKey() { $key=strtolower(domake_password(4)); $set=esetcookie("checkkey",$key);  //是否支持gd库 if (function_exists("imagejpeg")) {    header ("Content-type: image/jpeg");    $img=imagecreate(

asp验证码源码

asp验证码源码 调用方法,是b.htm 页面  <form name="form1">   <Input type="text" name="a"><br>   <input type="text" name="b"><br><span><img id="yzm" src="yzm.asp"

使用Java设计验证码生成程序

    我们来设计一个简单的验证码生成程序:验证码一个由4位的数字.字母随机组合而成图像,为了避免被光学字元识别(OCR,Optical Character Recognition)之类的程序识别出图片中的数字而失去效果,我们给图像中添加上几条干扰线. 1 package password; 2 /** 3 * 使用Java设计验证码生成程序 4 * @author hellokitty燕 5 */ 6 import java.awt.Color; 7 import java.awt.Font;

asp 完整高安全验证码生成程序

<%@CodePage="65001"%> <script language="vbscript" runat="server">  Option Explicit '显示声明  Dim showErrorImg  showErrorImg = False  function ChkPost()   dim server_v1,server_v2   chkpost=false   server_v1=Cstr(Reque

支持中文/英文/数字的动网ASP验证码类修改教程

完美支持中文验证码,英文及数字验证码. 设置起来相对比较简单,打开文件(Dv_GetCode.asp)进行相应参数修改: 以下是引用片段:   mCodeType     = 0        '0数字,1字母,2汉字     mCodeTotal    = 4        '生成的验证码个数     mMaxWidth    = 30        '可取的一个字符的最大宽度     mMinWidth    = 25        '可取的一个字符的最小宽度     mMaxHeight 

连接数据库的ASP树图生成程序

程序|连接数据库 <%'*****************************'******* 连接数据库的树图生成程序 ********'*****************************'假设你已建立了SQLServer数据库UnitTree,并在该库中建立了表:'Units(ID 单位序号整数唯一,Name 单位名称字符串,UpID 上级单位序号整数)'注:UpID=0表示该单位是根结点单位:'输入一些数据如:(1,AA,0)(2,AABB,1)(3,AACC,1)(4,AAB

ASP验证码的程序及原理

程序|验证码   ##### 版权所有 转载请保留 谢谢合作   ##### 部分程序取自网络   ##### 作者:扬子   ##### Email: yangzinet@hotmail.com   ##### QQ: 21112856   ##### WebSite: www.tingfo.net         一共4个页面:form.asp; chk.asp; num.asp; count.asp   得到一个随即数字.加密!   解密后成成XBM图片   利用session 判断