Monday, October 19, 2015

Atbash Cipher

I think this is the easiest ciphers. In the plain text if we get 'A' then we replace it with 'Z' character. Similarly 'B' -> 'Y', 'C' -> 'X'.... I guess you get the idea, so each time you get a character you replace with the character from the end of English alphabet sequence. So here is the lookup table you can use to implement this cipher

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Z Y X W V U T S R Q P O N M L K J I H G F E D C B A

I used following code implement this cipher.

int AtbashCipher(char* strPlainText, int nSize, char* strCipherText)
{
int nReturnValue = 0;

if (nSize <= 0 || strPlainText == NULL || strCipherText == NULL)
{
return ERR_INVALIDINPUTPARAMETERS;
}


for (int i = 0; i < nSize; i++)
{
//Idea here is replace A->Z, B->Y, C->X .....
if (strPlainText[i] >= 65 && strPlainText[i] <= 90)
{
//Capital Letters
strCipherText[i] = 90 - (strPlainText[i] - 65);
}
else if (strPlainText[i] >= 97 && strPlainText[i] <= 122)
{
//small Letters
strCipherText[i] = 122 - (strPlainText[i] - 97);
}
}

return nReturnValue;
}

I guess same function can be used for decrypting the cipher text. Will be testing it soon and updating this blog.

Is it a strong cipher? Definitely not. This is even looks like a special case of caeser cipher with key value = 25.


To understand Atbash cipher I read website -> http://practicalcryptography.com/ciphers/classical-era/atbash-cipher/

Suppose plain text is "Harsha Kadekar" then cipher text would be "Szihsz Pzwvpzi"

No comments:

Post a Comment