MARS is another AES candidate, operating on block of 128 bits and supporting key raging from 128 to 400 bits. Offers high security and high data rates.

Work on 32 bit words, based on a type-3 Feistel network in which one word of data is used to update the other 3 during the rounds. Uses simple operations like additions, subtraction and xor. It also uses a lookup table of 512 entries of 32 bit words called S-box. Sometimes this table is seen a two tables of 256 entries.

S-box table is given in the source code as a single table even if in code I use operations virtually dividing it. Other operations include fix rotations and data-dependent rotations, also multiplication modulo 2 raised to 32.

I’m not gonna post source code – you can download it below. In order to keep this short I’ll briefly explain functions purpose in the code. For more details about the working of MARS algorithm, including some pseudo-code, check out this document.

Functions ecrypt/decrypt are called from outside by user, supplying an array of bytes of any length representing data, and a key of aforementioned length sizes. It will automatically add and subtract padding from the plain/cipher text.

The above methods call encryptBloc/decryptBloc for each data block. This is the actual encryption/decryption process. It follows the pseudo-code from the given document above so you shouldn’t have problems picking it up.

To see how it comes together, I invite you to download the entire source code below.

Download MARS.java source code file.

About these ads