QQ Authentication Code identification source code (c#/net1.1)

Source: Internet
Author: User
Tags abs bool comparison continue integer tostring valid
Verification Code | Source Code QQ Authentication Code identification source code (c#/net1.1)


Using System;

Namespace QQ
{
<summary>
Summary description of the YZM.
</summary>
public class Yzm
{
Public yzm (Public System.Drawing.Bitmap pic)
{
THIS.BP = pic;
}
<summary>
Deposits an int value into a 4-byte array of bytes (converted from a high address, with the value of the highest address participating in the "and operation" with an unsigned integer)
</summary>
<param name= "Thevalue" > int value to be processed </param>
<param name= "Thebuff" > character array for storing information </param>
public static void Getbytesfromint (int thevalue, byte[] thebuff)
{
Long v1=0; Long v2=0; Long v3=0; Long v4=0;
UINT b1= (UINT) 4278190080; UINT b2= (UINT) 16711680; UINT b3= (UINT) 65280; UINT b4= (UINT) 255;
V1=thevalue & B1;
V2=thevalue & B2;
V3=thevalue & B3;
V4=thevalue & b4;
Thebuff[0]= (Byte) (v1>>24);
Thebuff[1]= (Byte) (v2>>16);
Thebuff[2]= (Byte) (v3>>8);
thebuff[3]= (byte) v4;
}
<summary>
Deposits a ushort value into a 2-byte array of bytes (converted from a high address, with the value of the highest address participating in the "and operation" with an unsigned integer)
</summary>
<param name= "Thevalue" > UShort value to be processed </param>
<param name= "Thebuff" > character array for storing information </param>
public static void Getbytesfromushort (UShort thevalue, byte[] thebuff)
{
UShort V1=0; UShort V2=0;
UShort b1= (ushort) 65280; UShort b2= (ushort) 255;
V1= (ushort) (Thevalue & B1);
V2= (ushort) (Thevalue & B2);
Thebuff[0]= (Byte) (v1>>8);
Thebuff[1]= (Byte) (v2);
}
<summary>
Converts a 4-byte array of bytes into an int value
</summary>
<param name= "Thebuff" > character array </param>
<returns></returns>
public static int Getintfrombyte (byte[] thebuff)
{
int jieguo=0;
Long mid=0;
Long m1=0; Long m2=0; Long m3=0; Long m4=0;
M1= (thebuff[0]<<24);
M2= (THEBUFF[1]&LT;&LT;16);
M3= (THEBUFF[2]&LT;&LT;8);
M4=THEBUFF[3];
MID=M1+M2+M3+M4;
jieguo= (int) mid;
return Jieguo;
}
<summary>
Converts a 2-byte array of bytes into a ushort value
</summary>
<param name= "Thebuff" > character array </param>
<returns></returns>
public static ushort Getushortfrombyte (byte[] thebuff)
{
int jieguo1=0;
jieguo1= (thebuff[0]<<8) +thebuff[1];
UShort jieguo= (ushort) jieguo1;
return Jieguo;
}
<summary>
Write in-memory data to the hard disk (save the feature library)
</summary>
<param name= "Thefile" > Save location </param>
public static void WriteToFile (String thefile)
{
System.IO.FileStream fs = new System.IO.FileStream (Thefile,system.io.filemode.openorcreate, System.IO.FileAccess.ReadWrite);
Byte[] Buff0=new byte[4];
Getbytesfromint (DATANUM,BUFF0);
Fs. Write (buff0,0,4);
for (int ii=0;ii<datanum;ii++)
{
for (int jj=0;jj<20;jj++)
{
Byte[] Buff=new byte[2];
Getbytesfromushort (Datap[ii,jj],buff);
Fs. Write (buff,0,2);
}
Fs. WriteByte (dataxy[ii,0]);
Fs. WriteByte (dataxy[ii,1]);
Fs. WriteByte (Datachar[ii]);
}
Fs. Close ();
}
<summary>
Read information from a file and save it in the appropriate location in memory
</summary>
<param name= "thefile" > Feature library Files </param>
public static void ReadFromFile (String thefile)
{
int allnum=0;
Byte[] Buff=new byte[4];
System.IO.FileStream fs = new System.IO.FileStream (thefile,system.io.filemode.open,system.io.fileaccess.read);
Fs. Read (buff,0,4);
Allnum=getintfrombyte (Buff);
Byte[] Buff0=new byte[2];
for (int ii=0;ii<allnum;ii++)
{
for (int jj=0;jj<20;jj++)
{
Fs. Read (buff0,0,2);
Datap[ii,jj]=getushortfrombyte (BUFF0);
}
Fs. Read (buff0,0,1);
DATAXY[II,0]=BUFF0[0];
Fs. Read (buff0,0,1);
DATAXY[II,1]=BUFF0[0];
Fs. Read (buff0,0,1);
DATACHAR[II]=BUFF0[0];
}
Datanum=allnum;
Fs. Close ();
}
<summary>
Verification Code Picture
</summary>
Public System.Drawing.Bitmap BP =new System.Drawing.Bitmap (49,20);
<summary>
Length of the feature library
</summary>
public static int datanum=0;
<summary>
Feature Library data
</summary>
public static ushort[,] datap=new ushort[100000,20];
<summary>
Length and height
</summary>
public static byte[,] dataxy=new byte[100000,2];
<summary>
The corresponding character
</summary>
public static byte[] Datachar=new byte[100000];
<summary>
Data waiting to be processed
</summary>
Public ushort[] Datapic=new ushort[20];
<summary>
Effective length
</summary>
public byte xlpic=0;
<summary>
Effective width
</summary>
public byte ylpic=0;
<summary>
Retrieving records that exist in a feature library
</summary>
public string GetChar ()
{
If it is not found, it returns an empty string
String jieguo= "";
for (int ii=0;ii<datanum;ii++)
{
Count the number of pixels in a row that are different, if the record is considered to exist within 4 lines
This method is relatively primitive, but it is more suitable for running on multiple threads because the program only makes a simple logical comparison
If you can collect more feature libraries, the recognition rate can reach more than 80%
(You may need to increase the capacity of the feature library to 15W or more at this time)
Of course, we can improve the product matching algorithm (such as the use of key points) to achieve a higher recognition rate with fewer feature libraries, but
There is a greater chance of identifying errors and consuming more CPU time on multiple threads.
int notsamenum=0;
if (Dataxy[ii,0]!=xlpic | | dataxy[ii,1]!=ylpic)
{
Continue
}
for (int jj=0;jj<20;jj++)
{
if (DATAP[II,JJ]!=DATAPIC[JJ])
{
notsamenum++;
}
}
if (notsamenum<4)
{
Char cj= (char) datachar[ii];
Return CJ. ToString ();
}
}
return Jieguo;
}
<summary>
Check to see if related records already exist in the feature library
</summary>
BOOL Ischardatain ()
{
BOOL Jieguo=false;
for (int ii=0;ii<datanum;ii++)
{
Count the number of pixels in a row that are different, if the record is considered to exist within 4 lines
This method is relatively primitive, but it is more suitable for running on multiple threads because the program only makes a simple logical comparison
If you can collect more feature libraries, the recognition rate can reach more than 80%
(You may need to increase the capacity of the feature library to 15W or more at this time)
Of course, we can improve the product matching algorithm (such as the use of key points) to achieve a higher recognition rate with fewer feature libraries, but
There is a greater chance of identifying errors and consuming more CPU time on multiple threads.
int notsamenum=0;
if (System.Math.Abs (dataxy[ii,0]-xlpic) >1 | | System.Math.Abs (dataxy[ii,1]-ylpic) >1)
{
Continue
}
for (int jj=0;jj<20;jj++)
{
if (DATAP[II,JJ]!=DATAPIC[JJ])
{
notsamenum++;
}
}
if (notsamenum<4)
{
String asdasd= ((char) datachar[ii]). ToString ();
return true;
}
}
return Jieguo;
}
<summary>
Add to the feature library and temporarily place the corresponding characters as spaces to treat people with recognition
</summary>
void Adddatawithnullchar ()
{
if (This.ischardatain ())
{
Return
}
for (int ii=0;ii<20;ii++)
{
DATAP[DATANUM,II]=THIS.DATAPIC[II];
}
temporarily place the corresponding characters as spaces to treat people with recognition
datachar[datanum]=32;
Dataxy[datanum,0]=this.xlpic;
Dataxy[datanum,1]=this.ylpic;
datanum++;
}
<summary>
Check that the verification code picture can be divided into 4 parts, if you can check whether 4 characters already exist in the feature library, if it does not exist,
Add to the feature library and temporarily place the corresponding character as a space to treat people with recognition
</summary>
public void Writetodata ()
{
bool[,] picpixel=new bool[49,20];
for (int ii=0;ii<49;ii++)
{
for (int jj=0;jj<20;jj++)
{
if (BP. GetPixel (II,JJ). Getbrightness () <0.999)
{
Picpixel[ii,jj]=true;
}
}
}
Int[] Index=new int[8];
int indexnum=0;
BOOL Black=false;
for (int ii=0;ii<49;ii++)
{
BOOL Haveblack=false;
for (int jj=0;jj<20;jj++)
{
if (PICPIXEL[II,JJ])
{
Haveblack=true;
Break
}
}
if (Haveblack && black==false)
{
Index[indexnum]=ii;
indexnum++;
Black=true;
}
if (!haveblack && black)
{
Index[indexnum]=ii;
indexnum++;
Black=false;
}
}
if (indexnum<7)
{
Return
}
if (indexnum==7)
{
index[7]=49;
}
//****
for (int ii=0;ii<4;ii++)
{
int x1=index[ii*2];
int x2=index[ii*2+1];
int y1=0,y2=19;
BOOL Mb=false;
for (int jj=0;jj<20;jj++)
{
for (int kk=x1;kk<x2;kk++)
{
if (PICPIXEL[KK,JJ])
{
Mb=true;
Break
}
}
if (MB)
{
Y1=JJ;
Break
}
}
Mb=false;
for (int jj=19;jj>=0;jj--)
{
for (int kk=x1;kk<x2;kk++)
{
if (PICPIXEL[KK,JJ])
{
Mb=true;
Break
}
}
if (MB)
{
Y2=JJ;
Break
}
}
* * Above is the scope to obtain a valid area
for (int jj=0;jj<20;jj++)
{
this.datapic[jj]=0;
this.datapic[jj]=0;
}
This.xlpic= (Byte) (X2-X1);
If the character width exceeds 16 pixels, it is not processed
if (xlpic>16)
{
Continue
}
This.ylpic= (Byte) (y2-y1+1);
int ys=-1;
Ushort[] Addin=new ushort[]{1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768};
for (int jj=y1;jj<=y2;jj++)
{
ys++;
int xs=-1;
for (int kk=x1;kk<x2;kk++)
{
xs++;
if (PICPIXEL[KK,JJ])
{
This.datapic[ys]= (ushort) (This.datapic[ys]+addin[xs]);
}
}
}
This.adddatawithnullchar ();
}
//****
}
<summary>
Identify pictures
</summary>
<returns> return recognition results (if the string length is less than 4 indicates recognition failure) </returns>
public string Ocrpic ()
{
String jieguo= "";
bool[,] picpixel=new bool[49,20];
for (int ii=0;ii<49;ii++)
{
for (int jj=0;jj<20;jj++)
{
if (BP. GetPixel (II,JJ). Getbrightness () <0.999)
{
Picpixel[ii,jj]=true;
}
}
}
Int[] Index=new int[8];
int indexnum=0;
BOOL Black=false;
for (int ii=0;ii<49;ii++)
{
BOOL Haveblack=false;
for (int jj=0;jj<20;jj++)
{
if (PICPIXEL[II,JJ])
{
Haveblack=true;
Break
}
}
if (Haveblack && black==false)
{
Index[indexnum]=ii;
indexnum++;
Black=true;
}
if (!haveblack && black)
{
Index[indexnum]=ii;
indexnum++;
Black=false;
}
}
if (indexnum<7)
{
return Jieguo;
}
if (indexnum==7)
{
index[7]=49;
}
//****
for (int ii=0;ii<4;ii++)
{
int x1=index[ii*2];
int x2=index[ii*2+1];
int y1=0,y2=19;
BOOL Mb=false;
for (int jj=0;jj<20;jj++)
{
for (int kk=x1;kk<x2;kk++)
{
if (PICPIXEL[KK,JJ])
{
Mb=true;
Break
}
}
if (MB)
{
Y1=JJ;
Break
}
}
Mb=false;
for (int jj=19;jj>=0;jj--)
{
for (int kk=x1;kk<x2;kk++)
{
if (PICPIXEL[KK,JJ])
{
Mb=true;
Break
}
}
if (MB)
{
Y2=JJ;
Break
}
}
* * Above is the scope to obtain a valid area
for (int jj=0;jj<20;jj++)
{
this.datapic[jj]=0;
this.datapic[jj]=0;
}
This.xlpic= (Byte) (X2-X1);
If the character width exceeds 16 pixels, it is not processed
if (xlpic>16)
{
Continue
}
This.ylpic= (Byte) (y2-y1+1);
int ys=-1;
Ushort[] Addin=new ushort[]{1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768};
for (int jj=y1;jj<=y2;jj++)
{
ys++;
int xs=-1;
for (int kk=x1;kk<x2;kk++)
{
xs++;
if (PICPIXEL[KK,JJ])
{
This.datapic[ys]= (ushort) (This.datapic[ys]+addin[xs]);
}
}
}
Jieguo=jieguo+this.getchar ();
}
return Jieguo;
}
}
}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.