找回密码
 立即注册→加入我们

QQ登录

只需一步,快速开始

搜索
热搜: 下载 VB C 实现 编写
查看: 3965|回复: 2

【VB】最简单之验证码生成算法

[复制链接]

85

主题

175

回帖

3990

积分

用户组: 超级版主

No. 418

UID
418
精华
14
威望
53 点
宅币
1974 个
贡献
1582 次
宅之契约
0 份
在线时间
252 小时
注册时间
2014-8-9
发表于 2014-12-12 00:11:22 | 显示全部楼层 |阅读模式

欢迎访问技术宅的结界,请注册或者登录吧。

您需要 登录 才可以下载或查看,没有账号?立即注册→加入我们

×
应同学装逼需求,特写简单装逼向验证码生成算法,高手喷口留情,有兴趣的朋友看过来:
进来身体有恙,夜不能寐(非想妹子也),无暇打理生存。不少未完成之贴,望站长海涵。

开门见码:

  1. VERSION 5.00
  2. Begin VB.Form Form1
  3.    Caption         =   "Form1"
  4.    ClientHeight    =   2940
  5.    ClientLeft      =   60
  6.    ClientTop       =   600
  7.    ClientWidth     =   4680
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   2940
  10.    ScaleWidth      =   4680
  11.    StartUpPosition =   3  'Windows Default
  12.    Begin VB.CommandButton Command2
  13.       Caption         =   "OK"
  14.       Enabled         =   0   'False
  15.       Height          =   855
  16.       Left            =   2640
  17.       TabIndex        =   3
  18.       Top             =   840
  19.       Width           =   975
  20.    End
  21.    Begin VB.TextBox Text1
  22.       Height          =   285
  23.       Left            =   120
  24.       TabIndex        =   2
  25.       Top             =   1200
  26.       Width           =   2415
  27.    End
  28.    Begin VB.CommandButton Command1
  29.       Caption         =   "Change"
  30.       Height          =   855
  31.       Left            =   2640
  32.       TabIndex        =   1
  33.       Top             =   0
  34.       Width           =   975
  35.    End
  36.    Begin VB.PictureBox P
  37.       BackColor       =   &H00FFFFFF&
  38.       ForeColor       =   &H00000000&
  39.       Height          =   855
  40.       Left            =   0
  41.       ScaleHeight     =   795
  42.       ScaleWidth      =   2595
  43.       TabIndex        =   0
  44.       Top             =   0
  45.       Width           =   2655
  46.    End
  47. End
  48. Attribute VB_Name = "Form1"
  49. Attribute VB_GlobalNameSpace = False
  50. Attribute VB_Creatable = False
  51. Attribute VB_PredeclaredId = True
  52. Attribute VB_Exposed = False
  53. Option Explicit '从这里算真正开始

  54. Dim ans As Single

  55. Private Sub Command1_Click()
  56.     Randomize '初始化随机数生成器
  57.     Command2.Enabled = True '免得不输就pass
  58.     Dim a As Integer, b As Integer, c(3) As String, d As String
  59.     'a放第一个数,b放第二个数,c放操作符,d保存操作符
  60.     Dim i As Integer '计数器变量留着待用
  61.    
  62.     c(1) = "+"
  63.     c(2) = "-"
  64.     c(3) = "*"
  65.    
  66.     a = Int(Rnd * 10 + 1) '第一个随机数
  67.     b = Int(Rnd * 10 + 1) '第二个随机数
  68.    
  69.    
  70.     P.Cls '清屏
  71.     '第一个数
  72.     P.FontName = Screen.Fonts(Int(Rnd * 15) + 1) '字体名
  73.     P.FontSize = Int(Rnd * 16) + 8 '字号
  74.     P.FontBold = CBool(Int(Rnd + 1)) '是否粗体
  75.     P.FontItalic = CBool(Int(Rnd + 1)) '是否斜体
  76.     P.ForeColor = RGB(Int(Rnd * 254 + 1), Int(Rnd * 254 + 1), Int(Rnd * 254 + 1)) '随机颜色
  77.     '定位
  78.     P.CurrentX = Int(Rnd() * 10) + 10
  79.     P.CurrentY = Int(Rnd() * 50) + 1
  80.     P.Print CStr(a) '打印
  81.    
  82.     操作符
  83.     P.FontName = Screen.Fonts(Int(Rnd * 15) + 1)
  84.     P.FontSize = Int(Rnd * 16) + 8
  85.     P.FontBold = CBool(Int(Rnd + 1))
  86.     P.FontItalic = CBool(Int(Rnd + 1))
  87.     P.ForeColor = RGB(Int(Rnd * 254 + 1), Int(Rnd * 254 + 1), Int(Rnd * 254 + 1))
  88.     P.CurrentX = Int(Rnd() * 500) + 500
  89.     P.CurrentY = Int(Rnd() * 50) + 1
  90.     d = c(Int(Rnd * 3) + 1) '随机操作符
  91.     P.Print d
  92.    
  93.     '第二个数字,原理同上,解释略
  94.     P.FontName = Screen.Fonts(Int(Rnd * 15) + 1)
  95.     P.FontSize = Int(Rnd * 16) + 8
  96.     P.FontBold = CBool(Int(Rnd + 1))
  97.     P.FontItalic = CBool(Int(Rnd + 1))
  98.     P.ForeColor = RGB(Int(Rnd * 254 + 1), Int(Rnd * 254 + 1), Int(Rnd * 254 + 1))
  99.     P.CurrentX = Int(Rnd() * 1000) + 1000
  100.     P.CurrentY = Int(Rnd() * 50) + 1
  101.     P.Print CStr(b)
  102.    
  103.     '瞎画一些线条
  104.     For i = 1 To 7
  105.         P.ForeColor = RGB(Int(Rnd * 254 + 1), Int(Rnd * 254 + 1), Int(Rnd * 254 + 1))
  106.         P.Line (Rnd * P.ScaleWidth, Rnd * P.ScaleWidth)-(Rnd * P.ScaleWidth, Rnd * P.ScaleWidth)
  107.     Next
  108.     '瞎画一些点
  109.     For i = 1 To 100
  110.         P.ForeColor = RGB(Int(Rnd * 254 + 1), Int(Rnd * 254 + 1), Int(Rnd * 254 + 1))
  111.         P.PSet (Rnd * P.ScaleWidth, Rnd * P.ScaleWidth)
  112.     Next
  113.    
  114.     '判定运算,计算结果
  115.     Select Case d
  116.     Case "+"
  117.         ans = a + b
  118.     Case "-"
  119.         ans = a - b
  120.     Case "*"
  121.         ans = a * b
  122.     End Select
  123. End Sub

  124. Private Sub Command2_Click()
  125.     If Val(Text1) = ans And Text1 <> "" Then
  126.         MsgBox "Pass!", 48
  127.     Else
  128.         Call Command1_Click
  129.         Text1 = ""
  130.     End If
  131. End Sub
复制代码


捕获.JPG
In the beginning I was not the best.
And the world was also not the best.
But I still know that I am who I am.
Because I think that it is good.
I have been working hard.
I have been keeping growth with the world.
And it was so.
回复

使用道具 举报

1112

主题

1653

回帖

7万

积分

用户组: 管理员

一只技术宅

UID
1
精华
245
威望
744 点
宅币
24263 个
贡献
46222 次
宅之契约
0 份
在线时间
2298 小时
注册时间
2014-1-26
发表于 2014-12-12 00:24:08 | 显示全部楼层
哈哈哈 改天我弄个更屌的。
回复 赞! 靠!

使用道具 举报

0

主题

13

回帖

18

积分

用户组: 初·技术宅

UID
606
精华
0
威望
2 点
宅币
1 个
贡献
0 次
宅之契约
0 份
在线时间
0 小时
注册时间
2014-12-21
发表于 2014-12-21 06:54:41 | 显示全部楼层
很有收获,谢谢
回复 赞! 靠!

使用道具 举报

QQ|Archiver|小黑屋|技术宅的结界 ( 滇ICP备16008837号 )|网站地图

GMT+8, 2024-5-1 19:53 , Processed in 0.037481 second(s), 31 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表