标题:ASP图形验证码的问题
只看楼主
伤不起!
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2011-5-9
 问题点数:0 回复次数:0 
ASP图形验证码的问题
各位大大大家好~小弟刚刚接触ASP汉字图形验证码,还不是很懂。。看到网上的段代码,不知道这一段是干嘛用的,望各位大大解惑~~
就是输出图像信息头后的代码,这段代码是走的过程是干嘛用的呢,为什么要这么做啊~通宵坐等各位大大解惑啊。。不好意思,有注释也看不懂啊
For i = UnitHeight-1 To 0 Step -1 ' 历经所有行
For ii = 0 To codeLen-1 ' 历经所有字
For iii = 1 To UnitWidth ' 历经所有像素
If Rnd * 99 + 1 >= cOdds Then' 逐行、逐字、逐像素地输出图像数据
Response.BinaryWrite vColorData(Mid(vCode(ii), i * UnitWidth + iii, 1))
Else ' 随机生成杂点
Response.BinaryWrite vColorData(1-CInt(Mid(vCode(ii), i * UnitWidth + iii, 1)))
End If
Next
Next
Next
End Sub
Function pcd_doubter(str,UnitWidth,UnitHeight,DotsLimit,tryCount,dbtTimes)
Randomize
Dim x1,x2,y1,y2,xOffSet,yOffSet,direction,flag,rows,step,yu,yuStr,i,ii,iii,f1,f2
For f1=1 To dbtTimes'干扰次数
For f2=1 To tryCount'避免删除有效点超过上限的尝试次数限制
'随机确定2个端点
x1 = int(Rnd*UnitWidth)
x2 = int(Rnd*UnitWidth)
y1 = int(Rnd*UnitHeight)
y2 = int(Rnd*UnitHeight)
'x,y位移量
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(num,lens)
Dim ret,i
ret = ""
While (num>0)
ret = ret & ChrB(num mod 256)
num = num \ 256
WEnd
For i=Lenb(ret) To lens-1
ret = ret & chrB(0)
Next
Num2ChrB = ret
End Function
%>  
搜索更多相关主题的帖子: 验证码 汉字 
2011-05-14 01:53



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-339783-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.074250 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved