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.

Thanks for code! MARS seems to be rather slow compared to RC6, AES, Twofish and even Serpent (Bouncycastle implementation)…
Thanks for the comment! Indeed, although I didn’t see a comparison regarding speed between them, those enumerated by you seem to be faster. AES won against Serpent in AES contest, one of the reason being speed. Twofish, in software might be faster even than AES, but for key lengths of 256.
hey thanks for the code, i’m on working my project, implementating MARS algorithm for encryption in java. Do you have the sample program/application ?
For a complete working example of all the algorithms, check the eclipse project containing all code plus test cases. You can download it from the AES post.
Best regards!
wonderful!!!
thanks a lot for the code
can we keep this code as a final project for mca?
Don’t know what mca stands for. But you can use this code in whatever project you like.
Thanks for appreciation!
pls say weather it is applicable for the java code files for projects