[验证码实现] Captcha 验证码类,一个很个性的验证码类 (转载)
- /// <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[] + b[], a[] + b[], a[] + b[] };
- }
- private static double[] scalarProduct(double[] vector, double scalar)
- {
- return new double[] { vector[] * scalar, vector[] * scalar, vector[] * scalar };
- }
- private static double dotProduct(double[] a, double[] b)
- {
- return a[] * b[] + a[] * b[] + a[] * b[];
- }
- 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[] * b[] - a[] * b[]),
- (a[] * b[] - a[] * b[]),
- (a[] * b[] - a[] * b[])
- };
- }
- private static double[] vectorProductIndexed(double[] v, double[] m, int i)
- {
- return new double[]
- {
- v[i + ] * m[] + v[i + ] * m[] + v[i + ] * m[] + v[i + ] * m[],
- v[i + ] * m[] + v[i + ] * m[] + v[i + ] * m[] + v[i + ] * m[],
- v[i + ] * m[] + v[i + ] * m[] + v[i + ] * m[]+ v[i + ] * m[],
- v[i + ] * m[] + v[i + ] * m[] + v[i + ] * m[]+ v[i + ] * m[]
- };
- }
- private static double[] vectorProduct(double[] v, double[] m)
- {
- return vectorProductIndexed(v, m, );
- }
- private static double[] matrixProduct(double[] a, double[] b)
- {
- double[] o1 = vectorProductIndexed(a, b, );
- double[] o2 = vectorProductIndexed(a, b, );
- double[] o3 = vectorProductIndexed(a, b, );
- double[] o4 = vectorProductIndexed(a, b, );
- return new double[]
- {
- o1[], o1[], o1[], o1[],
- o2[], o2[], o2[], o2[],
- o3[], o3[], o3[], o3[],
- o4[], o4[], o4[], o4[]
- };
- }
- private static double[] cameraTransform(double[] C, double[] A)
- {
- double[] w = normalize(addVector(C, scalarProduct(A, -)));
- double[] y = new double[] { , , };
- double[] u = normalize(crossProduct(y, w));
- double[] v = crossProduct(w, u);
- double[] t = scalarProduct(C, -);
- return new double[]
- {
- u[], v[], w[], ,
- u[], v[], w[], ,
- u[], v[], w[], ,
- dotProduct(u, t), dotProduct(v, t), dotProduct(w, t),
- };
- }
- private static double[] viewingTransform(double fov, double n, double f)
- {
- fov *= (Math.PI / );
- double cot = 1.0 / Math.Tan(fov / );
- return new double[] { cot, , , , , cot, , , , , (f + n) / (f - n), -, , , * f * n / (f - n), };
- }
- public static Image Generate(string captchaText)
- {
- int fontsize = ;
- Font font = new Font("Arial", fontsize);
- SizeF sizeF;
- using (Graphics g = Graphics.FromImage(new Bitmap(, )))
- {
- sizeF = g.MeasureString(captchaText, font, , 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, , );
- }
- Random rnd = new Random();
- double[] T = cameraTransform(new double[] { rnd.Next(-, ), -, rnd.Next(, ) }, new double[] { , , });
- T = matrixProduct(T, viewingTransform(, , ));
- double[][] coord = new double[image2d_x * image2d_y][];
- int count = ;
- for (int y = ; y < image2d_y; y += )
- {
- for (int x = ; x < image2d_x; x++)
- {
- int xc = x - image2d_x / ;
- int zc = y - image2d_y / ;
- double yc = -(double)(image2d.GetPixel(x, y).ToArgb() & 0xff) / * ;
- double[] xyz = new double[] { xc, yc, zc, };
- xyz = vectorProduct(xyz, T);
- coord[count] = xyz;
- count++;
- }
- }
- int image3d_x = ;
- int image3d_y = image3d_x * / ;
- 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 = ;
- double scale = 1.75 - (double)image2d_x / ;
- for (int y = ; y < image2d_y; y += )
- {
- for (int x = ; x < image2d_x; x++)
- {
- if (x > )
- {
- double x0 = coord[count - ][] * scale + image3d_x / ;
- double y0 = coord[count - ][] * scale + image3d_y / ;
- double x1 = coord[count][] * scale + image3d_x / ;
- double y1 = coord[count][] * scale + image3d_y / ;
- g.DrawLine(new Pen(fgcolor), (float)x0, (float)y0, (float)x1, (float)y1);
- }
- count++;
- }
- }
- }
- return image3d;
- }
- }
[验证码实现] Captcha 验证码类,一个很个性的验证码类 (转载)的更多相关文章
- Confluence 6 配置验证码(Captcha)来防止垃圾
如果你的 Confluence 站点是对公众开放的(允许匿名用户使用,添加评论,创建页面等),你可能会发现你的站点会被自动创建很多垃圾页面,评论或者其他垃圾内容. 你可以配置让 Confluence ...
- 一个漂亮的php验证码类
一个漂亮的php验证码类(分享) 作者: 字体:[增加 减小] 类型:转载 下面小编就为大家分享一个漂亮的php验证码类.需要的朋友可以过来参考下 直接上代码: 复制代码 代码如下: //验证 ...
- Python&selenium&tesseract自动化测试随机码、验证码(Captcha)的OCR识别解决方案参考
在自动化测试或者安全渗透测试中,Captcha验证码的问题经常困扰我们,还好现在OCR和AI逐渐发展起来,在这块解决上越来越支撑到位. 我推荐的几种方式,一种是对于简单的验证码,用开源的一些OCR图片 ...
- DVWA-全等级验证码Insecure CAPTCHA
DVWA简介 DVWA(Damn Vulnerable Web Application)是一个用来进行安全脆弱性鉴定的PHP/MySQL Web应用,旨在为安全专业人员测试自己的专业技能和工具提供合法 ...
- 用Java制作一个简单的图片验证码
//Java实现简单验证码功能 package project; import java.awt.Color; import java.awt.Font;import java.awt.Graphic ...
- PHP入门培训教程 一个漂亮的PHP验证码
如何写一个漂亮的PHP验证码?兄弟连PHP培训 小编分享一段代码给大家: <?php class Imagecode{ private $width ; private $height; pri ...
- 接口 ThreadMXBean 一个很好用的线程管理接口类 可以参考 jdk 帮助文档
概述 软件包 类 使用 树 已过时 索引 帮助 JavaTM Platform Standard Ed. 6 上一个类 下一个类 框架 无框架 所有类 摘要: 嵌套 ...
- Makefile经典教程(一个很棒很清晰的讲解)【转】
转自:https://blog.csdn.net/seven_amber/article/details/70216216 该篇文章为转载,是对原作者系列文章的总汇加上标注. 支持原创,请移步陈浩大神 ...
- 【Android】java生成炫酷验证码,不区分大小写。登陆,发送手机验证码,防止注册机,android开发
作者:程序员小冰,CSDN博客:http://blog.csdn.net/qq_21376985 QQ986945193 微博:http://weibo.com/mcxiaobing 首先给大家看一下 ...
随机推荐
- Unity3D插件之Easy Touch 3.1(1): Easy Joystick
先看官方介绍:https://www.assetstore.unity3d.com/#/content/3322 (Allows you to quickly and easily develop a ...
- Automator 简单使用流程
iOS开发中常常要用到图片缩放的工作,有些需求流程很奇葩,根本找不到现成的工具去实现. 这时候,你可以去想一想Automator了. 示例:要把文件夹下所有的图片文件都缩小成原来的一半(搞iOS开发的 ...
- 【转】Android中intent传递对象和Bundle的用法
原文网址:http://blog.csdn.net/lixiang0522/article/details/8642202 android中的组件间传递的对象一般实现Parcelable接口,当然也可 ...
- Asp.net--Ajax前后台数据交互
转自:http://www.cnblogs.com/guolebin7/archive/2011/02/22/1961737.html 代码由前后台两部分组成: 前台:(新建一个Default.asp ...
- linux下建立无线wifi------简单实用!
一 安装必要软件安装hostapd : sudo apt-get install hostapd安装DHCP: sudo apt-get install dhcp3-server 二 配置 ...
- I Hate It HDOJ---1754
I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- SVG事件响应
1 UIEvents(用户界面事件) focusin(onfocusin):一个元素获得焦点(例如,一段文本被选中) focusout(onfocusout):一个元素失去焦点(例如,一段文本 ...
- ORA-12504: TNS:listener was not given the SERVICE_NAME in CONNECT_DATA
Centos5.5 安装Oracle11g客户端,配置了本地的net服务后,用sqlplus连接报错: tnsnames.ora配置如下 orcl = (DESCRIPTION = (ADDRESS ...
- 《C程序设计语言现代方法》第5章 选择语句
关系运算符的优先级低于算术运算符,关系运算符都是左结合的. 判等运算符的优先级低于关系运算符,判等运算符也是左结合的. 逻辑运算符将任何非零值操作数作为真值来处理,同时将任何零值操作数作为假值来处理. ...
- java 删除字符串中的特定字符
/** * Delete any character in a given String. * @param inString the original String * @param charsTo ...