The crack of the Verification code 2-image Restore and slider position solver

Source: Internet
Author: User

In the previous chapter, we discussed the ideas and steps to crack the verification code, and this chapter will show you how to restore two background images and the target position of the solve slider.

First, picture restoration

Let's start by looking at what parameters are given to us on the page:

This is the full background map (FULLBG) of the page elements, you can see that they are from the same original image, but the location of the interception is different. Red box is the small picture in the original position, each small picture is 10 pixels wide, 58 pixels high, we look at the original image:

It's really messy, and I can't see anything at all. If we download the original image, and then follow the parameters on the page to intercept a 10 pixels wide, 58 pixels high small pictures together to get a complete background map, the code:

/*** Synthesize multiple images to a single image * *@paramaddress List of imgsrclist images *@paramtopleftpointlist offset per small image *@paramcountofline number of small images per line *@paramcutwidth width of each small image (pixels) *@paramcutheight height per small image (pixels) *@paramSavepath The saved path of the merged picture *@paramsubfix The suffix of the merged picture *@returnwhether the merge was successful*/     Public Static BooleanCombineimages (list<string> imgsrclist, list<string[]> topleftpointlist,intCountofline,intCutwidth,intcutheight, String Savepath, String subfix) {        if(Imgsrclist = =NULL|| Savepath = =NULL|| Savepath.trim (). Length () = = 0)return false; BufferedImage Lastimage=NewBufferedImage (Cutwidth * countofline, Cutheight * (int) (Math.floor (Imgsrclist.size ()/Countofline))) , BUFFEREDIMAGE.TYPE_INT_RGB); String prevsrc= ""; BufferedImage Previmage=NULL; Try {             for(inti = 0; I < imgsrclist.size (); i++) {String src=Imgsrclist.get (i);                BufferedImage image; if(Src.equals (PREVSRC)) image =Previmage; Else {                    if(Src.trim (). toLowerCase (). StartsWith ("http")) Image= Imageio.read (NewURL (SRC)); ElseImage= Imageio.read (NewFile (SRC)); PREVSRC=src; Previmage=image; }                if(Image = =NULL)Continue; String[] Topleftpoint=Topleftpointlist.get (i); int[] Pixarray = Image.getrgb (0-integer.parseint (Topleftpoint[0].trim ()), 0-integer.parseint (TopLeftPoint[1].trim ()), Cutwidth, Cutheight,NULL, 0, Cutwidth); intStartX = ((i)% countofline) *Cutwidth; intStarty = ((i)/countofline) *Cutheight; Lastimage.setrgb (StartX, Starty, Cutwidth, Cutheight, Pixarray,0, Cutwidth); } File File=NewFile (Savepath); returnImageio.write (lastimage, subfix, file); } Catch(Exception ex) {ex.printstacktrace (); return false; }    }

The background map with the hole is the same deal, now look at the two background images we restored:

Second, solve the sliding block moving target position

With the result of the first step, we only need to compare the pixels of the two background graphs, scan from left to right to find the target position of the slider, or see the code:

 Public Static intfindxdiffrectangeoftwoimage (String imgSrc1, String imgSrc2) {Try{bufferedimage Image1= Imageio.read (NewFile (IMGSRC1)); BufferedImage Image2= Imageio.read (NewFile (IMGSRC2)); intWidth1 =image1.getwidth (); intHEIGHT1 =image1.getheight (); intWidth2 =image2.getwidth (); intHeight2 =image2.getheight (); if(width1! = width2)return-1; if(height1! = height2)return-1; intleft = 0; /*** Scan from left to right*/            BooleanFlag =false;  for(inti = 0; i < width1; i++) {                 for(intj = 0; J < height1; J + +)                    if(Ispixelnotequal (Image1, Image2, I, J)) { left=i; Flag=true;  Break; }                if(flag) Break; }            returnLeft ; } Catch(Exception ex) {ex.printstacktrace (); return-1; }    }    Private Static BooleanIspixelnotequal (BufferedImage image1, BufferedImage image2,intIintj) {intPixel1 =Image1.getrgb (i, j); intPixel2 =Image2.getrgb (i, j); int[] Rgb1 =New int[3]; rgb1[0] = (pixel1 & 0xff0000) >> 16; rgb1[1] = (Pixel1 & 0xff00) >> 8; rgb1[2] = (Pixel1 & 0xff); int[] Rgb2 =New int[3]; rgb2[0] = (Pixel2 & 0xff0000) >> 16; rgb2[1] = (Pixel2 & 0xff00) >> 8; rgb2[2] = (Pixel2 & 0xff);  for(intk = 0; K < 3; k++)            if(Math.Abs (Rgb1[k]-rgb2[k]) > 50)//because the background map will have some pixel differences                return true; return false; }

It is worth noting that when comparing pixels to set a tolerance value, it is possible that the two background images have been processed several times there is a certain pixel difference, or there may be a watermark.

After solving the target position of the slider, are we just going to follow the displacement to drag the slider? The answer is no, look:

You can see that there is a distance between the slider and the background image before sliding, it is necessary to make a displacement adjustment, after observation, this value is about 7 pixels, so: the final sliding displacement = the number of left pixels of the solved slider-7.

In the next chapter I'll show you how to load and render a page using a mock browser.

The crack of the Verification code 2-image Restore and slider position solver

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.