当前位置: 网学 > 编程文档 > ASP > 正文

asp汉字中文图片验证码的实现代码

来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 13/06/16
位移量
xOffSet = Abs(x2-x1)
yOffSet = Abs(y2-y1)
If xOffSet >= yOffSet Then''以位移量较大方做横轴
direction = "x"
ReDim ary(xOffSet)''用来记录连线各点y值
''x2,y2存储x值较大的点
If x2 < x1 Then
i = x1
x1 = x2
x2 = i
i = y1
y1 = y2
y2 = i
End If
''判断从x1->x2在纵轴方向上是增是减
If y2 >= y1 Then
flag = 1
Else
flag = -1
End If
''下面计算连线上点的分布(先是平均分配各行的点,然后随机分配剩余的点到各行)
rows = yOffSet + 1''所占行数
step = (xOffSet+1) \ rows''各行平均分配的点
yu = (xOffSet+1) Mod rows''剩余的点数
ReDim ary2(rows-1)''用来记录剩余点的随机分配
While yu > 0
i = int(Rnd*rows)
ary2(i) = ary2(i)&"."''被分配到的行则加一个字符"."
yu = yu - 1
WEnd
iii = 0
''将连线的点信息记录到数组
For i=0 To rows-1
For ii=1 To step+Len(ary2(i))
ary(iii) = y1 + i*flag
iii = iii + 1
Next
Next
ii = 0
''统计连线上有效点的数量
For i=0 To xOffSet
If pcd_getDot(x1+i,ary(i),str,UnitWidth) = "0" Then ii = ii + 1
Next
Else
''这里是以y为横轴,原理与x时相同
direction = "y"
ReDim ary(yOffSet)
If y2 < y1 Then
i = x1
x1 = x2
x2 = i
i = y1
y1 = y2
y2 = i
End If
If x2 >= x1 Then
flag = 1
Else
flag = -1
End If
rows = xOffSet + 1
step = (yOffSet+1) \ rows
yu = (yOffSet+1) Mod rows
ReDim ary2(rows-1)
While yu > 0
i = int(Rnd*10)
If i < rows Then
ary2(i) = ary2(i)&"."
yu = yu - 1
End If
WEnd
iii = 0
For i=0 To rows-1
For ii=1 To step+Len(ary2(i))
ary(iii) = x1 + i*flag
iii = iii + 1
Next
Next
ii = 0
For i=0 To yOffSet
If pcd_getDot(ary(i),y1+i,str,UnitWidth) = "0" Then ii = ii + 1
Next
End If
''如未超过有效点上限则跳出循环,执行干扰
If ii <= DotsLimit Then Exit For
Next

If direction = "x" Then
''随机确定在纵轴方向上或下进行移动
If int(Rnd*10) > 4 Then
''变量连线上的点
For i=0 To xOffSet
''遍历移动
For ii=ary(i) To 1 Step -1
Call pcd_setDot(x1+i,ii,str,pcd_getDot(x1+i,ii-1,str,UnitWidth),UnitWidth)
Next
''添补空白
Call pcd_setDot(x1+i,0,str,"1",UnitWidth)
Next
Else
For i=0 To xOffSet
For ii=ary(i) To UnitHeight-2
Call pcd_setDot(x1+i,ii,str,pcd_getDot(x1+i,ii+1,str,UnitWidth),UnitWidth)
Next
Call pcd_setDot(x1+i,UnitHeight-1,str,"1",UnitWidth)
Next
End If
Else
If int(Rnd*10) > 4 Then
For i=0 To yOffSet
For ii=ary(i) To 1 Step -1
Call pcd_setDot(ii,y1+i,str,pcd_getDot(ii-1,y1+i,str,UnitWidth),UnitWidth)
Next
Call pcd_setDot(0,y1+i,str,"1",UnitWidth)
Next
Else
For i=0 To yOffSet
For ii=ary(i) To UnitWidth-2
Call pcd_setDot(ii,y1+i,str,pcd_getDot(ii+1,y1+i,str,UnitWidth),UnitWidth)
Next
Call pcd_setDot(UnitWidth-1,y1+i,str,"1",UnitWidth)
Next
End If
End If
Next
pcd_doubter = str
End Function

Rem 得到某点的字符
Function pcd_getDot(x,y,str,UnitWidth)
pcd_getDot = Mid(str,x+1+y*UnitWidth,1)
End Function

Rem 设置某点的字符
Sub pcd_setDot(x,y,ByRef str,newDot,UnitWidth)
str = Left(str,x+y*UnitWidth) & newDot & Right(str,Len(str)-x-y*UnitWidth-1)
End Sub

Rem 将数字转为bmp需要的格式 lens是目标字节长度
Function Num2ChrB(nu

网学推荐

免费论文

原创论文

浏览:
设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
湘ICP备09003080号