Decrypting the Caesar cipher using shell

By Chris Lamb

In cryptography, a Caesar cipher, also known as Caesar's cipher, the shift cipher, Caesar's code or Caesar shift, is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet. [...]
#!/bin/sh

IN="MJHVIZN ZPIO YJHPN"

for I in $(seq 25); do
    echo $I $IN | tr $(printf %${I}s | tr ' ' '.')\A-Z A-ZA-Z
done

This outputs:

1 NKIWJAO AQJP ZKIQO
2 OLJXKBP BRKQ ALJRP
3 PMKYLCQ CSLR BMKSQ
4 QNLZMDR DTMS CNLTR
5 ROMANES EUNT DOMUS
6 SPNBOFT FVOU EPNVT
7 TQOCPGU GWPV FQOWU
8 URPDQHV HXQW GRPXV
9 VSQERIW IYRX HSQYW
10 WTRFSJX JZSY ITRZX
11 XUSGTKY KATZ JUSAY
12 YVTHULZ LBUA KVTBZ
13 ZWUIVMA MCVB LWUCA
14 AXVJWNB NDWC MXVDB
15 BYWKXOC OEXD NYWEC
16 CZXLYPD PFYE OZXFD
17 DAYMZQE QGZF PAYGE
18 EBZNARF RHAG QBZHF
19 FCAOBSG SIBH RCAIG
20 GDBPCTH TJCI SDBJH
21 HECQDUI UKDJ TECKI
22 IFDREVJ VLEK UFDLJ
23 JGESFWK WMFL VGEMK
24 KHFTGXL XNGM WHFNL
25 LIGUHYM YOHN XIGOM

The only line which makes sense is 5 ROMANES EUNT DOMUS, giving us our solution.


Chris Lamb is a freelance software developer and the current Debian Project Leader. You can read other posts by me, see software I have written or read more about me. You can also follow me @lolamby.


Tags: Hacks

Planets: ALUG UWCS WUGLUG Debian

Saturday 31st August 2013


Four comments