破解校内的图片识别码。

原创 2007年10月06日 21:46:00

 

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace XiaoNei.VerifyImage
{
    
public static class Verify
    
{
        
private static int[,] imageDatas;
        
private static String code;
        
private static Bitmap image;

        
/**//// <summary>
        
/// 获取验证码
        
/// </summary>
        
/// <param name="filename">输入文件名</param>
        
/// <returns>验证码</returns>

       
        
public static String getCode(String filename)      
        
{
            Bitmap image 
= new Bitmap(filename);
            readDatas(image);
            code 
= "" + getBestCode(getSimple(35)) +
                    getBestCode(getSimple(
313)) +
                    getBestCode(getSimple(
321)) +
                    getBestCode(getSimple(
329));
            Console.WriteLine(code);

            
//测试识别是否正确,文件名中含有验证码
            
//if (filename.IndexOf(code) < 0)
               
// Console.WriteLine("Error");
            return code;
        }


        
/**//// <summary>
        
/// 初始化数据
        
/// </summary>

        private static void readDatas(Bitmap image)
        
{

            imageDatas 
= new int[image.Height, image.Width];
            Color pixelColor;
            
for (int h = 0; h < image.Height; h++)
            
{
                
for (int w = 0; w < image.Width; w++)
                
{
                    pixelColor 
= image.GetPixel(w, h);

                    imageDatas[h, w] 
= pixelColor.R > 0 ? 1 : 0;
                }
//for
            }
//for
        }

        
/**//// <summary>
        
/// 取数字块
        
/// </summary>
        
/// <param name="x">横坐标</param>
        
/// <param name="y">纵坐标</param>
        
/// <returns>一维数组</returns>

        private static int[] getSimple(int x, int y)
        
{
            
int[] simple = new int[9 * 6];
            
int count = 0;
            
for (int h = x; h < x + 9; h++)
            
{
                
for (int w = y; w < y + 6; w++)
                
{
                    simple[count
++= imageDatas[h, w];
                }

            }

            
return simple;
        }

        
/**//// <summary>
        
/// 最和谐的数字
        
/// </summary>
        
/// <param name="x">数字块</param>
        
/// <returns>结果</returns>

        private static int getBestCode(int[] x)
        
{
            
int bestNumber = -1;
            
double bestVal = 0.0;
            
for (int index = 0; index < 10; index++)
            
{
                
double val = compareSimple(NumberData.getNumber(index), x);
                
if (bestVal <= val)
                
{
                    bestVal 
= val;
                    bestNumber 
= index;
                }

            }

            
return bestNumber;
        }

        
/**//// <summary>
        
/// 获取两个数字图像数组的和谐百分比
        
/// </summary>
        
/// <param name="t">匹配数字数组</param>
        
/// <param name="x">待匹配数字数组</param>
        
/// <returns>和谐百分比</returns>

        private static double compareSimple(int[] t, int[] x)
        
{
            
int count = 0;
            
int val = 0;
            
for (int i = 0; i < t.Length; i++)
            
{
                
if (1 == t[i])
                
{
                    count
++;
                    
if (1 == x[i])
                    
{
                        val
++;
                    }

                }

            }

            
return (val + 0.0/ count;
        }

    }



}


最近在做一个校内刷人气的小工具,顺便把图像识别搞了一下。 把源代码贴出来。请高手指教。

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Net; 
using System.IO;
using System.Text;

namespace XiaoNei.VerifyImage
{
   
public  class DownLoadImage
    
{
        
/// <summary>
        
/// 从图片地址下载图片到本地磁盘
        
/// </summary>
        
/// <param name="ToLocalPath">图片本地磁盘地址</param>
        
/// <param name="Url">图片网址</param>
        
/// <returns></returns>

        public static bool SavePhotoFromUrl(string FileName, string Url)
        
{
            
bool Value = false;
            WebResponse response 
= null;
            Stream stream 
= null;

            
try
            
{
                HttpWebRequest request 
= (HttpWebRequest)WebRequest.Create(Url);

                response 
= request.GetResponse();
                stream 
= response.GetResponseStream();

                
if (!response.ContentType.ToLower().StartsWith("text/"))
                
{
                    Value 
= SaveBinaryFile(response, FileName);

                }


            }

            
catch (Exception err)
            
{
                
string aa = err.ToString();
            }

            
return Value;
        }

        
/// <summary>
        
/// Save a binary file to disk.
        
/// </summary>
        
/// <param name="response">The response used to save the file</param>

        // 将二进制文件保存到磁盘
        private static bool SaveBinaryFile(WebResponse response, string FileName)
        
{
            
bool Value = true;
            
byte[] buffer = new byte[1024];

            
try
            
{
                
if (File.Exists(FileName))
                    File.Delete(FileName);
                Stream outStream 
= System.IO.File.Create(FileName);
                Stream inStream 
= response.GetResponseStream();

                
int l;
                
do
                
{
                    l 
= inStream.Read(buffer, 0, buffer.Length);
                    
if (l > 0)
                        outStream.Write(buffer, 
0, l);
                }

                
while (l > 0);

                outStream.Close();
                inStream.Close();
            }

            
catch
            
{
                Value 
= false;
            }

            
return Value;
        }



    }

}

 

 

using System;
using System.Collections.Generic;
using System.Text;

namespace XiaoNei.VerifyImage
{
    
public class NumberData
    
{

        
public static int[] getNumber(int n)
        
{
            
switch (n)
            
{
                
case 0return num0; }
                
case 1return num1; }
                
case 2return num2; }
                
case 3return num3; }
                
case 4return num4; }
                
case 5return num5; }
                
case 6return num6; }
                
case 7return num7; }
                
case 8return num8; }
                
case 9return num9; }
                
defaultreturn num0; }
            }

        }





        
public static int[] num0 = {
        
0,0,1,1,0,0,
        
0,1,0,0,1,0,
        
1,0,0,0,0,1,
        
1,0,0,0,0,1,
        
1,0,0,0,0,1,
        
1,0,0,0,0,1,
        
1,0,0,0,0,1,
        
0,1,0,0,1,0,
        
0,0,1,1,0,0
    }
;

        
public static int[] num1 = {
        
0,0,1,1,0,0,
        
0,1,0,1,0,0,
        
0,0,0,1,0,0,
        
0,0,0,1,0,0,
        
0,0,0,1,0,0,
        
0,0,0,1,0,0,
        
0,0,0,1,0,0,
        
0,0,0,1,0,0,
        
0,1,1,1,1,1
    }
;

        
public static int[] num2 = {
        
1,1,1,1,0,0,
        
0,0,0,0,1,0,
        
0,0,0,0,1,0,
        
0,0,0,0,1,0,
        
0,0,0,1,0,0,
        
0,0,1,0,0,0,
        
0,1,0,0,0,0,
        
1,0,0,0,0,0,
        
1,1,1,1,1,0
    }
;

        
public static int[] num3 = {
        
1,1,1,1,0,0,
        
0,0,0,0,1,0,
        
0,0,0,0,1,0,
        
0,0,0,1,0,0,
        
0,1,1,0,0,0,
        
0,0,0,1,0,0,
        
0,0,0,0,1,0,
        
0,0,0,0,1,0,
        
0,1,1,1,0,0
    }
;

        
public static int[] num4 = {
        
0,0,0,0,1,0,
        
0,0,0,1,1,0,
        
0,0,1,0,1,0,
        
0,1,0,0,1,0,
        
1,0,0,0,1,0,
        
1,1,1,1,1,1,
        
0,0,0,0,1,0,
        
0,0,0,0,1,0,
        
0,0,0,0,1,0
    }
;

        
public static int[] num5 = {
        
1,1,1,1,1,0,
        
1,0,0,0,0,0,
        
1,0,0,0,0,0,
        
1,1,1,0,0,0,
        
0,0,0,1,0,0,
        
0,0,0,0,1,0,
        
0,0,0,0,1,0,
        
0,0,0,1,0,0,
        
1,1,1,0,0,0
    }
;
        
public static int[] num6 = {
        
0,0,1,1,1,1,
        
0,1,0,0,0,0,
        
1,0,0,0,0,0,
        
1,0,1,1,0,0,
        
1,1,0,0,1,0,
        
1,0,0,0,0,1,
        
1,0,0,0,0,1,
        
0,1,0,0,1,0,
        
0,0,1,1,0,0
    }
;
        
public static int[] num7 = {
        
1,1,1,1,1,1,
        
0,0,0,0,0,1,
        
0,0,0,0,1,0,
        
0,0,0,1,0,0,
        
0,0,0,1,0,0,
        
0,0,1,0,0,0,
        
0,0,1,0,0,0,
        
0,1,0,0,0,0,
        
0,1,0,0,0,0
    }
;

        
public static int[] num8 = {
        
0,1,1,1,1,0,
        
1,0,0,0,0,1,
        
1,0,0,0,0,1,
        
0,1,0,0,1,0,
        
0,1,1,1,1,0,
        
1,0,0,0,0,1,
        
1,0,0,0,0,1,
        
1,0,0,0,0,1,
        
0,1,1,1,1,0
    }
;

        
public static int[] num9 = {
        
0,0,1,1,0,0,
        
0,1,0,0,1,0,
        
1,0,0,0,0,1,
        
1,0,0,0,0,1,
        
0,1,0,0,1,1,
        
0,0,1,1,0,1,
        
0,0,0,0,0,1,
        
0,0,0,0,1,0,
        
1,1,1,1,0,0
    }
;

    }


}


 

 

 

相关文章推荐

校内网礼物图片

  • 2008年01月23日 11:18
  • 258KB
  • 下载

【Web安全学习笔记】Web安全实践(15)CSRF(跨站请求伪造)-从校内的插入图片说起

【Web安全学习笔记】: 原文链接:http://www.cnblogs.com/xuanhun/archive/2009/04/23/1442239.html 作者:玄魂 其他安全专栏文章:...

常用的五笔识别码练习句

  • 2017年08月06日 09:33
  • 27KB
  • 下载

五笔字型 识别码.ppt

  • 2009年10月30日 10:04
  • 260KB
  • 下载

pci设备身份识别码介绍说明

什么是“PCI ID”?根据PCI 规范,Windows 9x/NT/XP系统,通过VID、DID、SID、SVID、RID及CC等6个识别代码对某一个PCI设备进行最终身份识别,并通过这些代码引导操...
  • mish84
  • mish84
  • 2016年03月21日 09:51
  • 1973

Wii识别码检测软件

  • 2015年07月01日 02:29
  • 6.27MB
  • 下载

模式识别码是距离分类

  • 2014年11月27日 12:56
  • 2KB
  • 下载

(转)获取设备唯一识别码和Mac地址

下面这个工具类提供了一些方法,可以获取设备AndroidID、IMEI、序列号、以及由他们组成的唯一识别码、网卡的MAC地址、蓝牙MAC地址。代码如下: DeviceInfoUtil: view ...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:破解校内的图片识别码。
举报原因:
原因补充:

(最多只允许输入30个字)