Cryptography | Caesar | Vigenere | Vernam | Columnar

0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5

Always remember that the character A-Z starts from 0 and ends at 25 and not from 1 to 26!

Caesar cipher

Alright i am pretty sure we all know that we move it forward by 3 characters. So to encrypt the character A (or numeric 0) + 3 would be D (or numeric 3).  Caesar cipher reference.

Look into some Caesar and Rot13 source codes (C language) here.

Vernam cipher

Basically this is simple, it is taught to convert that character A-Z into numeric 0-25 and add them with a random number and mod it into 26 and we get it right? So the formula should be something like the code below for encryption process.

Ci = Pi + Ri (mod 26)

C = Cipher Text
P = Plain Text
R = Random

Note that what was taught in the class was not complete. A vernam cipher generally requires the length of the original data and the length of the key to be the same. We were given an example of an image below.

Generally the example is not wrong but there would be no decryption process possible here. As we have only 26 characters in the alphabetical table and the key 105 appeared, the encryption process made decryption impossible. However as the lecturer has mentioned we are only concerned about encrypting the plain text only, so remember the encryption algorithm.

Vigenere cipher

Vigenere cipher is not that hard to encrypt and decrypt. For your information, looking into alphabetic table is not a necessary tool. A cipher always exists with an algorithm (as far as i’m concerned, i might not be right). Be amazed with vigenere cipher’s algorithm.

Ci = Pi + Ki (mod 26)
Pi = Ci - Ki (mod 26)

P = Plain Text
K = Key
C = Cipher Text

If you’re having calculation problem with this, please do post it as a comment so i could help. It’s quite a hassle to do all of them in an example. However you can see that to encrypt the character A with the key L it would be A + L = 0 + 11 = 11 (L).  You may also see that Vigenere cipher and Vernam cipher is pretty much the same thing, only that the reason they were made for was different.

Columnar cipher

T h i s i
s a m e s
s a g e

From the above, “This is a message” was written in a 5 x 3 block. All you have to do in order to encrypt using columnar cipher is to place them in x * y block whereby x is 5 and y would end when the message to encrypt ends. After that read the text from top to bottom, left to right to get the cipher text. The message encrypted would be “tssha aimgs eeis”.

This post was made to aid those that have cryptography problem which was related to an exam for my subject.

Caesar and Rot Cipher Source Code

Ever wanted a portable caesar cipher and decipher at one go? At the end of this post you will find the binary as well as the source code (built in C) for the application. Below is an image of the application testing on “abcdefgh” text.  At [+13] you can see that it is equivalent to ROT13 cipher.  For those that are familiar with command line, use application.exe “text here”.

 * url:
 * email:
 * This source code is free to be used by any programmers
 * Source code converts all uppercase to lowercase during decryption
 * Supports command line usage, use text as argument eg. crack.exe "abcdef"

#include <stdio.h>
#include <string.h>
//#include <stdlib.h> /*include if using system()*/

void DecryptCaesar(char *Encrypted)
	char i;
	int j;

	Encrypted = strlwr(Encrypted); /*supports only lowercase*/
	//system("REM"); /*use this to copy paste in windows*/

	printf(" Caesar Cipher\n\n");
	for(i = 0 ; i < 27 ; i++)
		printf(" [+%d]\t", i);
		for(j = 0 ; j < (signed)strlen(Encrypted) ; j++)
			if(Encrypted[j] == ' ')
				printf(""); /*replace "" with " " if you prefer to preserve spacing*/
			else if(Encrypted[j] < 'a' || Encrypted[j] > 'z')
				printf("%c", Encrypted[j]); /*preserved non-alphabets*/
			else if(Encrypted[j] + i > 'z')
				printf("%c", Encrypted[j] + i - 26);
				printf("%c", Encrypted[j] + i);

		if(i == 13)
			printf(" (ROT)");

		if(i == 25)
			printf(" ");
			for(j = 0 ; j < (signed)strlen(Encrypted) + 8 ; j++)


int main(int argc, char **argv)
	char string[64 +1] = {'\0'};

	if(argc == 2)
		strncpy(string, argv[1], 64);
		return 0;

	for( ; ; )
		printf("\n Enter a text to encrypt/decrypt (EXIT to quit): ");

		fflush(stdin);		/*windows*/
		//fpurge(stdin);	/*linux*/

		scanf("%64[^\n]", string);

		if(string[0] == 'E' && string[1] == 'X' && string[2] == 'I' && string[3] == 'T' && string[4] == '\0')


	printf("\n Thanks for using...\n");
	return 0;

Download Binary
Download Source Code

Have you ever cracked Caesar Cipher

Last week… or two, my class lecturer asked us to decipher a caesar manually.  Since i had my laptop with me i just made a quick Caesar decipher application in 5 minutes to show it to her, the lecturer the answer.

Sucks… totally! I wish there was something more to it…