January 2010

You are currently browsing the monthly archive for January 2010.

You might be familiar with ROT13 – it’s an example of the classic Caesar Cipher used by the Romans. This type of cipher was quite common during Ancient Rome and was used extensively to encode sensitive communication.

Even though it was a basic substitution cipher, it was quite effective back in the day.

The following is a basic clone of ROT13:

/*-----Greymask.com--------*/

#include <iostream>
#define SHIFT 13

// shift each character
char encode(char c)
{

if (c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z')
{
 if (c < 'A')
        return c;
        else if (c < 'A' + SHIFT)
            c += SHIFT;
            else if (c <= 'Z')
                c -= SHIFT;
                else if (c < 'a' + SHIFT)
                    c += SHIFT;
                    else if (c >= 'a' + SHIFT)
                        c -= SHIFT;
                        return c;
} else
{
    return c;
}
}
// main
int main()
{
    char c;
    // get input
    while (std::cin.get(c))
        std::cout << encode(c);
}

How to use

Input: 

hello world

Output: 

uryyb jbeyq

As you can see, the initial phrase is shifted by 13 characters to encode it using the classic Caesar cipher.

Here is another example:

Input: 

the quick fox jumps over the lazy dog

Output:

gur dhvpx sbk whzcf bire gur ynml qbt

You can take the output and decode it easily by plugging it back in as input:

Input: 

gur dhvpx sbk whzcf bire gur ynml qbt

Output:

the quick fox jumps over the lazy dog

As you can see, this obviously does not provide any protection, but it’s still quite neat to know that young Julius used this type of encryption back in Ancient Rome to encrypt his dirty secrets 😉