苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 71347|回复: 41
打印 上一主题 下一主题

[验证码破解] Captcha 验证码类,一个很个性的验证码类

[复制链接]
跳转到指定楼层
楼主
发表于 2012-10-20 16:36:38 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
导读部分
-------------------------------------------------------------------------------------------------------------
C#基类|C#自定义类|C#帮助类--系列导航文章
http://www.sufeinet.com/thread-655-1-1.html

下载前需要先回复哦
[post=1] Captcha.zip (1.73 KB, 下载次数: 282) [/post]
这是一个生成验证码的类,一个很有个性的验证码大家来试试吧
看看效果

下面看看代码吧
[C#] 纯文本查看 复制代码
/// <summary>
/// 类说明:条码生成类
/// 编 码 人:苏飞
/// 联系方式:361983679  
/// 更新网站:[url=http://www.sufeinet.com/thread-655-1-1.html]http://www.sufeinet.com/thread-655-1-1.html[/url]
/// </summary>
using System;
using System.Drawing;

public static class Captcha
{
    private static double[] addVector(double[] a, double[] b)
    {
        return new double[] { a[0] + b[0], a[1] + b[1], a[2] + b[2] };
    }

    private static double[] scalarProduct(double[] vector, double scalar)
    {
        return new double[] { vector[0] * scalar, vector[1] * scalar, vector[2] * scalar };
    }

    private static double dotProduct(double[] a, double[] b)
    {
        return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
    }

    private static double norm(double[] vector)
    {
        return Math.Sqrt(dotProduct(vector, vector));
    }

    private static double[] normalize(double[] vector)
    {
        return scalarProduct(vector, 1.0 / norm(vector));
    }

    private static double[] crossProduct(double[] a, double[] b)
    {
        return new double[] 
                { 
                    (a[1] * b[2] - a[2] * b[1]), 
                    (a[2] * b[0] - a[0] * b[2]), 
                    (a[0] * b[1] - a[1] * b[0]) 
                };
    }

    private static double[] vectorProductIndexed(double[] v, double[] m, int i)
    {
        return new double[]
                {
                    v[i + 0] * m[0] + v[i + 1] * m[4] + v[i + 2] * m[8] + v[i + 3] * m[12],
                    v[i + 0] * m[1] + v[i + 1] * m[5] + v[i + 2] * m[9] + v[i + 3] * m[13],
                    v[i + 0] * m[2] + v[i + 1] * m[6] + v[i + 2] * m[10]+ v[i + 3] * m[14],
                    v[i + 0] * m[3] + v[i + 1] * m[7] + v[i + 2] * m[11]+ v[i + 3] * m[15]
                };
    }

    private static double[] vectorProduct(double[] v, double[] m)
    {
        return vectorProductIndexed(v, m, 0);
    }

    private static double[] matrixProduct(double[] a, double[] b)
    {
        double[] o1 = vectorProductIndexed(a, b, 0);
        double[] o2 = vectorProductIndexed(a, b, 4);
        double[] o3 = vectorProductIndexed(a, b, 8);
        double[] o4 = vectorProductIndexed(a, b, 12);

        return new double[]
                {
                    o1[0], o1[1], o1[2], o1[3],
                    o2[0], o2[1], o2[2], o2[3],
                    o3[0], o3[1], o3[2], o3[3],
                    o4[0], o4[1], o4[2], o4[3]
                };
    }

    private static double[] cameraTransform(double[] C, double[] A)
    {
        double[] w = normalize(addVector(C, scalarProduct(A, -1)));
        double[] y = new double[] { 0, 1, 0 };
        double[] u = normalize(crossProduct(y, w));
        double[] v = crossProduct(w, u);
        double[] t = scalarProduct(C, -1);

        return new double[]
                {
                    u[0], v[0], w[0], 0,
                    u[1], v[1], w[1], 0,
                    u[2], v[2], w[2], 0,
                    dotProduct(u, t), dotProduct(v, t), dotProduct(w, t), 1
                };
    }

    private static double[] viewingTransform(double fov, double n, double f)
    {
        fov *= (Math.PI / 180);
        double cot = 1.0 / Math.Tan(fov / 2);
        return new double[] { cot, 0, 0, 0, 0, cot, 0, 0, 0, 0, (f + n) / (f - n), -1, 0, 0, 2 * f * n / (f - n), 0 };
    }

    public static Image Generate(string captchaText)
    {
        int fontsize = 24;
        Font font = new Font("Arial", fontsize);

        SizeF sizeF;
        using (Graphics g = Graphics.FromImage(new Bitmap(1, 1)))
        {
            sizeF = g.MeasureString(captchaText, font, 0, StringFormat.GenericDefault);
        }

        int image2d_x = (int)sizeF.Width;
        int image2d_y = (int)(fontsize * 1.3);

        Bitmap image2d = new Bitmap(image2d_x, image2d_y);
        Color black = Color.Black;
        Color white = Color.White;

        using (Graphics g = Graphics.FromImage(image2d))
        {
            g.Clear(black);
            g.DrawString(captchaText, font, Brushes.White, 0, 0);
        }

        Random rnd = new Random();
        double[] T = cameraTransform(new double[] { rnd.Next(-90, 90), -200, rnd.Next(150, 250) }, new double[] { 0, 0, 0 });
        T = matrixProduct(T, viewingTransform(60, 300, 3000));

        double[][] coord = new double[image2d_x * image2d_y][];

        int count = 0;
        for (int y = 0; y < image2d_y; y += 2)
        {
            for (int x = 0; x < image2d_x; x++)
            {
                int xc = x - image2d_x / 2;
                int zc = y - image2d_y / 2;
                double yc = -(double)(image2d.GetPixel(x, y).ToArgb() & 0xff) / 256 * 4;
                double[] xyz = new double[] { xc, yc, zc, 1 };
                xyz = vectorProduct(xyz, T);
                coord[count] = xyz;
                count++;
            }
        }

        int image3d_x = 256;
        int image3d_y = image3d_x * 9 / 16;
        Bitmap image3d = new Bitmap(image3d_x, image3d_y);
        Color fgcolor = Color.White;
        Color bgcolor = Color.Black;
        using (Graphics g = Graphics.FromImage(image3d))
        {
            g.Clear(bgcolor);
            count = 0;
            double scale = 1.75 - (double)image2d_x / 400;
            for (int y = 0; y < image2d_y; y += 2)
            {
                for (int x = 0; x < image2d_x; x++)
                {
                    if (x > 0)
                    {
                        double x0 = coord[count - 1][0] * scale + image3d_x / 2;
                        double y0 = coord[count - 1][1] * scale + image3d_y / 2;
                        double x1 = coord[count][0] * scale + image3d_x / 2;
                        double y1 = coord[count][1] * scale + image3d_y / 2;
                        g.DrawLine(new Pen(fgcolor), (float)x0, (float)y0, (float)x1, (float)y1);
                    }
                    count++;
                }
            }
        }
        return image3d;
    }
}





1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
沙发
发表于 2012-11-7 13:44:25 | 只看该作者
很好···
板凳
发表于 2012-11-28 13:44:10 | 只看该作者
三维立体的
地板
发表于 2012-11-30 16:29:36 | 只看该作者
LZ能发个验证码识别的例子么?
5
 楼主| 发表于 2012-11-30 16:39:04 | 只看该作者
liuhaolin8828 发表于 2012-11-30 16:29
LZ能发个验证码识别的例子么?

下周了吧,这周日恐怕是没有时间 了
6
发表于 2012-11-30 23:39:38 | 只看该作者
感觉还可以
7
发表于 2012-12-10 10:07:16 | 只看该作者
6846546546
8
发表于 2012-12-13 10:02:06 | 只看该作者
O(∩_∩)O谢谢
9
发表于 2013-1-5 09:45:07 | 只看该作者
来过
10
发表于 2013-1-19 16:59:19 | 只看该作者
想下来看看啊
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2025-4-25 05:20

© 2014-2021

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