简单验证码识别[人人网手机登陆]

Eddy 发布于2011-3-16 18:6:49 分类: 程序设计 已浏览loading 网友评论4条 我要评论

黑客防线上的一篇文章,应该算是最简单的验证码了,学习了下。以下代码修改自源文章,稍微优化了下。

代码:

Option Explicit
Private P(3 To 11, 5 To 34) As Boolean

Private Sub Command1_Click()
On Error Resume Next

If Inet1.StillExecuting Then
    Inet1.Cancel
End If

Dim picByte() As Byte
picByte = Inet1.OpenURL("http://3g.renren.com/randimg?post=_REQUESTFRIEND_88193bf7488cd4d0169d399541bdb4a7&rnd=1300194185024", icByteArray)

Dim ntime, stime
stime = Now
While Inet1.StillExecuting
    DoEvents
    ntime = Now
    If DateDiff("s", stime, ntime) > 3 Then MsgBox "验证码获取超时": Exit Sub
Wend

Open App.Path & "\test.gif" For Binary As #1
Put #1, , picByte
Close #1

Picture1.AutoSize = True
Picture1.ScaleMode = vbPixels
Picture1.Picture = LoadPicture(App.Path & "\test.gif")
End Sub

Private Sub Command2_Click()
On Error Resume Next

Dim i As Integer, j As Integer, s As String

Text1 = ""
For i = 3 To 11
    For j = 5 To 34
        P(i, j) = IIf(Picture1.Point(j, i) <> 0, True, False)
        s = s & IIf(Picture1.Point(j, i) <> 0, "□", "■")
    Next j
    s = s & vbCrLf
Next i
Text1 = s
Me.Caption = "识别结果" & Very(5, 11) & Very(13, 19) & Very(21, 27) & Very(29, 34)
End Sub

Private Function Very(ByVal col1 As Integer, ByVal col2 As Integer) As Integer
Dim i As Integer, j As Integer
Dim yesCount As Integer, yesCount2 As Integer
For i = col1 To col2
    If P(3, i) Then yesCount = yesCount + 1
Next

Select Case yesCount
    Case 6
    Very = 7
    Case 1
    Very = 4
    Case 5
    Very = 5
   
    Case 2
    For i = col1 To col2
        If P(11, i) Then yesCount2 = yesCount2 + 1
    Next
    Select Case yesCount2
        Case 2
        Very = 0
        Case 4
        Very = 9
        Case 5
        Very = 1
    End Select
   
    Case 4
     For i = col1 To col2
        If P(7, i) Then yesCount2 = yesCount2 + 1
    Next
    Select Case yesCount2
        Case 1
        Very = 2
        Case 2
        Very = 3
        Case 3
        Very = 6
        Case 4
        Very = 8
    End Select
End Select
End Function

 

已经有(4)位网友发表了评论,你也评一评吧!
原创文章如转载,请注明:转载自Eddy Blog
原文地址:http://www.rrgod.com/program/745.html     欢迎订阅Eddy Blog

  1. 发表于2011-3-18 10:27:51

    简单吗?我怎么感觉也蛮复杂的啊 。。。看来我的能力有限啊

    Eddy 于 2011-3-18 15:49:58 回复
    不懂这个当然觉得复杂了^

  2. 发表于2011-3-18 10:38:46

    好多代码啊。。呵呵、、、

  3. 发表于2012-10-29 0:33:54

    能写上几行注释么?看得有点不明白

    Eddy 于 2012-10-29 9:39:16 回复
    自己试着运行动态调试下就明白了

  4. 发表于2013-2-20 22:59:46

    是vb代码?

记住我的信息,下次不用再输入 欢迎给Eddy Blog留言