THE

SPRAWL

projectscaesar cipher

Version0.1
Size 2.1 KB
Download caesar-cipher.pl

An exercise in decrypting of shift-based ciphers. The script supports frequency analysis and brute force cryptanalysis techniques for automatic decoding.

Usage

Caesar Cipher Encoder/Decoder
=============================
Usage:
 -e encode_message shift
    no spaces are allowed in plaintext message.
 -d decode_message shift
 -d1 decode_message
    try simple frequency analysis to determine the shift
 -d2 decode_message
    brute force method relying on users to find plaintext

Sample session

Let's encode a sample string using a shift of 53:

$ perl caesar-cipher.pl -e asamplestringtoencodeanddecode 53
Ciphertext:
BTBNQMFTUSJOHUPFODPEFBOEEFDPEF

Now you can take the output ciphertext and attempt to decode it back to the original:

$ perl caesar-cipher.pl -d BTBNQMFTUSJOHUPFODPEFBOEEFDPEF 53
Plaintext:
asamplestringtoencodeanddecode

You can attempt to automatically guess the shift by performing a frequency analysis on the string:

$ perl caesar-cipher.pl -d1 BTBNQMFTUSJOHUPFODPEFBOEEFDPEF
Trying to count letter frequencies...guessing a shift of 1
Plaintext:
asamplestringtoencodeanddecode

In the ouput above, the script has determined a shift of 1 (53 is really two 26 full loops around the alphabet and a single shift forward). It determined the shift by counting the number of times each letter occurs in the ciphertext and guessing that the most frequent letter F is likely to be E in accordance with a typical letter frequency in English language.

At last, when all else fails you can try to brute-force the shift:

$ perl caesar-cipher.pl -d2 BTBNQMFTUSJOHUPFODPEFBOEEFDPEF
Brute Forcing...
[1] asamplestringtoencodeanddecode
[2] zrzlokdrsqhmfsndmbncdzmccdbncd
[3] yqyknjcqrpglermclambcylbbcambc
[4] xpxjmibpqofkdqlbkzlabxkaabzlab
[5] wowilhaopnejcpkajykzawjzzaykza
[6] vnvhkgznomdibojzixjyzviyyzxjyz
[7] umugjfymnlchaniyhwixyuhxxywixy
[8] tltfiexlmkbgzmhxgvhwxtgwwxvhwx
[9] sksehdwkljafylgwfugvwsfvvwugvw
[10] rjrdgcvjkizexkfvetfuvreuuvtfuv
[11] qiqcfbuijhydwjeudsetuqdttusetu
[12] phpbeathigxcvidtcrdstpcsstrdst
[13] ogoadzsghfwbuhcsbqcrsobrrsqcrs
[14] nfnzcyrfgevatgbrapbqrnaqqrpbqr
[15] memybxqefduzsfaqzoapqmzppqoapq
[16] ldlxawpdectyrezpynzoplyoopnzop
[17] kckwzvocdbsxqdyoxmynokxnnomyno
[18] jbjvyunbcarwpcxnwlxmnjwmmnlxmn
[19] iaiuxtmabzqvobwmvkwlmivllmkwlm
[20] hzhtwslzaypunavlujvklhukkljvkl
[21] gygsvrkyzxotmzuktiujkgtjjkiujk
[22] fxfruqjxywnslytjshtijfsiijhtij
[23] eweqtpiwxvmrkxsirgshierhhigshi
[24] dvdpsohvwulqjwrhqfrghdqgghfrgh
[25] cucornguvtkpivqgpeqfgcpffgeqfg
[26] btbnqmftusjohupfodpefboeefdpef

sprawlcomments