反SPAM新思路—换Z-BLOG的验证码!

2019-01-13 19:40:43王振洲

    ' 输出图像数据
    For i = ImgHeight-1 To 0 Step -1    '行
      For ii = 0 To codeLen-1                    '字
          For iii = 0 To ActUnitWidth-1         '字宽
              flag = 0
              If onNoiseLine(noiseLine,ii*ActUnitWidth+iii,i) Then ' 干扰线
                   flag = 1
            ElseIf getUnitDot(posAry,vCode,ii,iii,i,UnitWidth,UnitHeight) = "0" Then
                flag = 1
            ElseIf getUnitDot(posAry,vCode,ii-1,iii+ActUnitWidth,i,UnitWidth,UnitHeight) = "0" Then
                flag = 1
            ElseIf getUnitDot(posAry,vCode,ii+1,iii-ActUnitWidth,i,UnitWidth,UnitHeight) = "0" Then
                flag = 1
            End If
            ' 随机生成杂点
            If Rnd * 99 + 1 < cOdds Then flag = 1 - flag
            Response.BinaryWrite vColorData(1-flag)
             Next
        Next
         For ii = 0 To ImgYuWidth-1
             Response.BinaryWrite vColorData(1)
         Next
    Next
End Sub

Rem 获取单元的点(考虑位移)
Function getUnitDot(ByRef posAry,ByRef vCode,i,ByVal x,ByVal y,UnitWidth,UnitHeight)
    getUnitDot = "1"
    If i < 0 Or i > UBound(vCode) Then Exit Function
    x = x - posAry(0,i)
    If x < 0 Or x >= UnitWidth Then Exit Function
    y = y - posAry(1,i)
    If y < 0 Or y >= UnitHeight Then Exit Function
    getUnitDot = Mid(vCode(i),y*UnitWidth+x+1,1)
End Function