anon.util.captcha
Class ZipBinaryImageCaptchaClient

java.lang.Object
  extended by anon.util.captcha.ZipBinaryImageCaptchaClient
All Implemented Interfaces:
IImageEncodedCaptcha

public class ZipBinaryImageCaptchaClient
extends java.lang.Object
implements IImageEncodedCaptcha

This is the client implementation for all captchas of the "ZIP_BINARY_IMAGE" format.


Field Summary
static java.lang.String CAPTCHA_DATA_FORMAT
          This is the captcha format identifier for the class of captchas, which can be handled by this class implementation.
private  java.awt.Image m_captchaImage
          Stores the captcha image.
private  int m_captchaKeyBits
          Stores the number of captcha key bits.
private  int m_characterNumber
          Stores the number of characters, which are embedded in the captcha image.
private  java.lang.String m_characterSet
          Stores the character set, which was used when the captcha was created.
private  byte[] m_encodedData
          Stores the encoded information.
private  int m_extraKeyBits
          Stores the number of extra key bits (bits of the key, which we have to guess with brute force).
 
Constructor Summary
ZipBinaryImageCaptchaClient(org.w3c.dom.Element a_captchaEncodedNode)
          Creates a new instance of ZipBinaryImageClient, which handles all captchas of the "ZIP_BINARY_IMAGE" format.
 
Method Summary
private  byte[] generateNextKey(byte[] a_currentKey, int a_mod8KeyBits)
          Generates the next key, which is equal to the current key + 1.
 int getCharacterNumber()
          Returns the number of characters which are included in the captcha.
 java.lang.String getCharacterSet()
          Returns the character set which was used when the captcha was created.
 java.awt.Image getImage()
          Returns the image with the captcha data.
 byte[] solveCaptcha(java.lang.String a_key, byte[] a_startsWith)
          Solves the captcha and returns the encoded information.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CAPTCHA_DATA_FORMAT

public static final java.lang.String CAPTCHA_DATA_FORMAT
This is the captcha format identifier for the class of captchas, which can be handled by this class implementation. We are handling the "ZIP_BINARY_IMAGE" format.

See Also:
Constant Field Values

m_captchaImage

private java.awt.Image m_captchaImage
Stores the captcha image.


m_captchaKeyBits

private int m_captchaKeyBits
Stores the number of captcha key bits. This is the number of bits, we shall obtain via solving the captcha image. If there are not enough characters in the captcha, we pad the difference between this number and the real captcha information with 0.


m_extraKeyBits

private int m_extraKeyBits
Stores the number of extra key bits (bits of the key, which we have to guess with brute force).


m_characterSet

private java.lang.String m_characterSet
Stores the character set, which was used when the captcha was created.


m_characterNumber

private int m_characterNumber
Stores the number of characters, which are embedded in the captcha image.


m_encodedData

private byte[] m_encodedData
Stores the encoded information.

Constructor Detail

ZipBinaryImageCaptchaClient

public ZipBinaryImageCaptchaClient(org.w3c.dom.Element a_captchaEncodedNode)
                            throws java.lang.Exception
Creates a new instance of ZipBinaryImageClient, which handles all captchas of the "ZIP_BINARY_IMAGE" format. If something is wrong with the specified XML captcha data (e.g. data with the wrong captcha format or invalid data), an Exception is thrown.

Parameters:
a_captchaEncodedNode - The CaptchaEncoded node with the data of a "ZIP_BINARY_IMAGE" captcha.
Throws:
java.lang.Exception
Method Detail

getImage

public java.awt.Image getImage()
Returns the image with the captcha data.

Specified by:
getImage in interface IImageEncodedCaptcha

getCharacterSet

public java.lang.String getCharacterSet()
Returns the character set which was used when the captcha was created. Only characters from this set are in the captcha image.

Specified by:
getCharacterSet in interface IImageEncodedCaptcha

getCharacterNumber

public int getCharacterNumber()
Returns the number of characters which are included in the captcha.

Specified by:
getCharacterNumber in interface IImageEncodedCaptcha

solveCaptcha

public byte[] solveCaptcha(java.lang.String a_key,
                           byte[] a_startsWith)
                    throws java.lang.Exception
Solves the captcha and returns the encoded information. The key is the character string visible in the captcha image. If the wrong key is specified, an Exception is thrown.

Specified by:
solveCaptcha in interface IImageEncodedCaptcha
Parameters:
a_key - The key for solving the captcha (it's the string which is shown in the captcha image).
a_startsWith - byte[]
Returns:
The encoded data
Throws:
java.lang.Exception

generateNextKey

private byte[] generateNextKey(byte[] a_currentKey,
                               int a_mod8KeyBits)
                        throws java.lang.Exception
Generates the next key, which is equal to the current key + 1. If that next key is 000...000 (overflow), an Exception is thrown. So if you start with the 000...000 key, you will know when you have tried all keys.

Parameters:
a_currentKey - The current key, you should start with 000...000.
a_mod8KeyBits - This is the number of key bits mod 8 in the current key. This value describes how many bits of the highest order byte are used (attention: a value of 0 means, that all bits are used).
Returns:
The key following to the a_currentKey (a_currentKey + 1).
Throws:
java.lang.Exception