点击下载 Captcha.zip

  1. /// <summary>
  2. /// 类说明:条码生成类
  3. /// 编 码 人:苏飞
  4. /// 联系方式:361983679
  5. /// 更新网站:[url=http://www.sufeinet.com/thread-655-1-1.html]http://www.sufeinet.com/thread-655-1-1.html[/url]
  6. /// </summary>
  7. using System;
  8. using System.Drawing;
  9.  
  10. public static class Captcha
  11. {
  12. private static double[] addVector(double[] a, double[] b)
  13. {
  14. return new double[] { a[] + b[], a[] + b[], a[] + b[] };
  15. }
  16.  
  17. private static double[] scalarProduct(double[] vector, double scalar)
  18. {
  19. return new double[] { vector[] * scalar, vector[] * scalar, vector[] * scalar };
  20. }
  21.  
  22. private static double dotProduct(double[] a, double[] b)
  23. {
  24. return a[] * b[] + a[] * b[] + a[] * b[];
  25. }
  26.  
  27. private static double norm(double[] vector)
  28. {
  29. return Math.Sqrt(dotProduct(vector, vector));
  30. }
  31.  
  32. private static double[] normalize(double[] vector)
  33. {
  34. return scalarProduct(vector, 1.0 / norm(vector));
  35. }
  36.  
  37. private static double[] crossProduct(double[] a, double[] b)
  38. {
  39. return new double[]
  40. {
  41. (a[] * b[] - a[] * b[]),
  42. (a[] * b[] - a[] * b[]),
  43. (a[] * b[] - a[] * b[])
  44. };
  45. }
  46.  
  47. private static double[] vectorProductIndexed(double[] v, double[] m, int i)
  48. {
  49. return new double[]
  50. {
  51. v[i + ] * m[] + v[i + ] * m[] + v[i + ] * m[] + v[i + ] * m[],
  52. v[i + ] * m[] + v[i + ] * m[] + v[i + ] * m[] + v[i + ] * m[],
  53. v[i + ] * m[] + v[i + ] * m[] + v[i + ] * m[]+ v[i + ] * m[],
  54. v[i + ] * m[] + v[i + ] * m[] + v[i + ] * m[]+ v[i + ] * m[]
  55. };
  56. }
  57.  
  58. private static double[] vectorProduct(double[] v, double[] m)
  59. {
  60. return vectorProductIndexed(v, m, );
  61. }
  62.  
  63. private static double[] matrixProduct(double[] a, double[] b)
  64. {
  65. double[] o1 = vectorProductIndexed(a, b, );
  66. double[] o2 = vectorProductIndexed(a, b, );
  67. double[] o3 = vectorProductIndexed(a, b, );
  68. double[] o4 = vectorProductIndexed(a, b, );
  69.  
  70. return new double[]
  71. {
  72. o1[], o1[], o1[], o1[],
  73. o2[], o2[], o2[], o2[],
  74. o3[], o3[], o3[], o3[],
  75. o4[], o4[], o4[], o4[]
  76. };
  77. }
  78.  
  79. private static double[] cameraTransform(double[] C, double[] A)
  80. {
  81. double[] w = normalize(addVector(C, scalarProduct(A, -)));
  82. double[] y = new double[] { , , };
  83. double[] u = normalize(crossProduct(y, w));
  84. double[] v = crossProduct(w, u);
  85. double[] t = scalarProduct(C, -);
  86.  
  87. return new double[]
  88. {
  89. u[], v[], w[], ,
  90. u[], v[], w[], ,
  91. u[], v[], w[], ,
  92. dotProduct(u, t), dotProduct(v, t), dotProduct(w, t),
  93. };
  94. }
  95.  
  96. private static double[] viewingTransform(double fov, double n, double f)
  97. {
  98. fov *= (Math.PI / );
  99. double cot = 1.0 / Math.Tan(fov / );
  100. return new double[] { cot, , , , , cot, , , , , (f + n) / (f - n), -, , , * f * n / (f - n), };
  101. }
  102.  
  103. public static Image Generate(string captchaText)
  104. {
  105. int fontsize = ;
  106. Font font = new Font("Arial", fontsize);
  107.  
  108. SizeF sizeF;
  109. using (Graphics g = Graphics.FromImage(new Bitmap(, )))
  110. {
  111. sizeF = g.MeasureString(captchaText, font, , StringFormat.GenericDefault);
  112. }
  113.  
  114. int image2d_x = (int)sizeF.Width;
  115. int image2d_y = (int)(fontsize * 1.3);
  116.  
  117. Bitmap image2d = new Bitmap(image2d_x, image2d_y);
  118. Color black = Color.Black;
  119. Color white = Color.White;
  120.  
  121. using (Graphics g = Graphics.FromImage(image2d))
  122. {
  123. g.Clear(black);
  124. g.DrawString(captchaText, font, Brushes.White, , );
  125. }
  126.  
  127. Random rnd = new Random();
  128. double[] T = cameraTransform(new double[] { rnd.Next(-, ), -, rnd.Next(, ) }, new double[] { , , });
  129. T = matrixProduct(T, viewingTransform(, , ));
  130.  
  131. double[][] coord = new double[image2d_x * image2d_y][];
  132.  
  133. int count = ;
  134. for (int y = ; y < image2d_y; y += )
  135. {
  136. for (int x = ; x < image2d_x; x++)
  137. {
  138. int xc = x - image2d_x / ;
  139. int zc = y - image2d_y / ;
  140. double yc = -(double)(image2d.GetPixel(x, y).ToArgb() & 0xff) / * ;
  141. double[] xyz = new double[] { xc, yc, zc, };
  142. xyz = vectorProduct(xyz, T);
  143. coord[count] = xyz;
  144. count++;
  145. }
  146. }
  147.  
  148. int image3d_x = ;
  149. int image3d_y = image3d_x * / ;
  150. Bitmap image3d = new Bitmap(image3d_x, image3d_y);
  151. Color fgcolor = Color.White;
  152. Color bgcolor = Color.Black;
  153. using (Graphics g = Graphics.FromImage(image3d))
  154. {
  155. g.Clear(bgcolor);
  156. count = ;
  157. double scale = 1.75 - (double)image2d_x / ;
  158. for (int y = ; y < image2d_y; y += )
  159. {
  160. for (int x = ; x < image2d_x; x++)
  161. {
  162. if (x > )
  163. {
  164. double x0 = coord[count - ][] * scale + image3d_x / ;
  165. double y0 = coord[count - ][] * scale + image3d_y / ;
  166. double x1 = coord[count][] * scale + image3d_x / ;
  167. double y1 = coord[count][] * scale + image3d_y / ;
  168. g.DrawLine(new Pen(fgcolor), (float)x0, (float)y0, (float)x1, (float)y1);
  169. }
  170. count++;
  171. }
  172. }
  173. }
  174. return image3d;
  175. }
  176. }

[验证码实现] Captcha 验证码类,一个很个性的验证码类 (转载)的更多相关文章

  1. Confluence 6 配置验证码(Captcha)来防止垃圾

    如果你的 Confluence 站点是对公众开放的(允许匿名用户使用,添加评论,创建页面等),你可能会发现你的站点会被自动创建很多垃圾页面,评论或者其他垃圾内容. 你可以配置让 Confluence ...

  2. 一个漂亮的php验证码类

    一个漂亮的php验证码类(分享)   作者: 字体:[增加 减小] 类型:转载 下面小编就为大家分享一个漂亮的php验证码类.需要的朋友可以过来参考下   直接上代码: 复制代码 代码如下: //验证 ...

  3. Python&selenium&tesseract自动化测试随机码、验证码(Captcha)的OCR识别解决方案参考

    在自动化测试或者安全渗透测试中,Captcha验证码的问题经常困扰我们,还好现在OCR和AI逐渐发展起来,在这块解决上越来越支撑到位. 我推荐的几种方式,一种是对于简单的验证码,用开源的一些OCR图片 ...

  4. DVWA-全等级验证码Insecure CAPTCHA

    DVWA简介 DVWA(Damn Vulnerable Web Application)是一个用来进行安全脆弱性鉴定的PHP/MySQL Web应用,旨在为安全专业人员测试自己的专业技能和工具提供合法 ...

  5. 用Java制作一个简单的图片验证码

    //Java实现简单验证码功能 package project; import java.awt.Color; import java.awt.Font;import java.awt.Graphic ...

  6. PHP入门培训教程 一个漂亮的PHP验证码

    如何写一个漂亮的PHP验证码?兄弟连PHP培训 小编分享一段代码给大家: <?php class Imagecode{ private $width ; private $height; pri ...

  7. 接口 ThreadMXBean 一个很好用的线程管理接口类 可以参考 jdk 帮助文档

    概述  软件包   类  使用  树  已过时  索引  帮助  JavaTM Platform Standard Ed. 6  上一个类   下一个类 框架    无框架    所有类 摘要: 嵌套 ...

  8. Makefile经典教程(一个很棒很清晰的讲解)【转】

    转自:https://blog.csdn.net/seven_amber/article/details/70216216 该篇文章为转载,是对原作者系列文章的总汇加上标注. 支持原创,请移步陈浩大神 ...

  9. 【Android】java生成炫酷验证码,不区分大小写。登陆,发送手机验证码,防止注册机,android开发

    作者:程序员小冰,CSDN博客:http://blog.csdn.net/qq_21376985 QQ986945193 微博:http://weibo.com/mcxiaobing 首先给大家看一下 ...

随机推荐

  1. Unity3D插件之Easy Touch 3.1(1): Easy Joystick

    先看官方介绍:https://www.assetstore.unity3d.com/#/content/3322 (Allows you to quickly and easily develop a ...

  2. Automator 简单使用流程

    iOS开发中常常要用到图片缩放的工作,有些需求流程很奇葩,根本找不到现成的工具去实现. 这时候,你可以去想一想Automator了. 示例:要把文件夹下所有的图片文件都缩小成原来的一半(搞iOS开发的 ...

  3. 【转】Android中intent传递对象和Bundle的用法

    原文网址:http://blog.csdn.net/lixiang0522/article/details/8642202 android中的组件间传递的对象一般实现Parcelable接口,当然也可 ...

  4. Asp.net--Ajax前后台数据交互

    转自:http://www.cnblogs.com/guolebin7/archive/2011/02/22/1961737.html 代码由前后台两部分组成: 前台:(新建一个Default.asp ...

  5. linux下建立无线wifi------简单实用!

    一 安装必要软件安装hostapd :    sudo apt-get install hostapd安装DHCP:    sudo apt-get install dhcp3-server 二 配置 ...

  6. I Hate It HDOJ---1754

    I Hate It Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  7. SVG事件响应

    1 UIEvents(用户界面事件)  focusin(onfocusin):一个元素获得焦点(例如,一段文本被选中)  focusout(onfocusout):一个元素失去焦点(例如,一段文本 ...

  8. ORA-12504: TNS:listener was not given the SERVICE_NAME in CONNECT_DATA

    Centos5.5 安装Oracle11g客户端,配置了本地的net服务后,用sqlplus连接报错: tnsnames.ora配置如下 orcl = (DESCRIPTION = (ADDRESS ...

  9. 《C程序设计语言现代方法》第5章 选择语句

    关系运算符的优先级低于算术运算符,关系运算符都是左结合的. 判等运算符的优先级低于关系运算符,判等运算符也是左结合的. 逻辑运算符将任何非零值操作数作为真值来处理,同时将任何零值操作数作为假值来处理. ...

  10. java 删除字符串中的特定字符

    /** * Delete any character in a given String. * @param inString the original String * @param charsTo ...