Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Caesar's Revenge (hybrid cipher: ceasar shift/homophonic)

39 views
Skip to first unread message

Mike Sanders

unread,
Apr 9, 2017, 1:58:38 PM4/9/17
to

A nifty little awk script for the puzzle minded...


Caesar's Revenge (hybrid cipher: ceasar shift/homophonic)


Caesar's Revenge is pencil & paper cipher combining the classic Ceasar shift
cipher[i] & the concept of homophones[ii]. A homophone is defined as
groupings of things that resemble one another but are in reality different.

Example homophones: heir/hair, oar/or, sum/some, 4/for...

A limitation of the classical ceasar cipher is that its prone to attack by
frequency analysis[iii] due in part to the fact that characters can often
repeat themselves in a predictable manner. This is especially true for
certain letters in the English alphabet (listed here by usage): ETAOIN[iv].

One way to lessen the frequency of character reuse is to map an often used
character to a range of unique characters. Letter 'E' for example, could in
one instance be written as 'K' & in another instance written as '8'. By
diffusing commonly used letters, we can greatly reduce the surface area of
attack & that's where homophones can help.


Usage


No key is required to use Caesar's Revenge & the script (written in awk[v] &
shown further below), produces a randomized table[vi] ready for use. But
note, both sender & receiver need to be working from the same table in order
to encode/decode messages.

Encoding: Locate each character of your message in the top row & then using
a character from the same column found in the lower rows (rows 2 to 5),
rewrite the plain text as cipher text:

plain text: SEND MORE PIZZA

random table:

row1 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
row2 G H I J K L M N O P Q R S T U V W X Y Z A B C D E F
row3 6 1 3 0 4 9 7
row4 8 2
row5 5

cipher text: 950J S4XK V3FF6

Decoding: Reading from the bottom rows up, locate each character of the
cipher text in rows 2 to 5, then convert the cipher text back into plain
text using the top row.


AWK Script


#!/bin/sh

<<DOC

Caesar's Revenge - Michael Sanders 2017
Hybrid cipher (ceasar shift/homophonic)
https://busybox.hypermart.net

DOC

awk -v e=$RANDOM '

function caesar(k, p) {return substr(p, k + 1) substr(p, 1, k)}
function rndnum(b, t) {return int(b + rand() * (t - b + 1))}
function pad(w) {return sprintf("%" w "s", " ")}

BEGIN {

srand(e)

alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

do {
cipher = caesar(rndnum(1, 26), alphabet)
} while (substr(cipher, 1, 1) ~ substr(alphabet, 1, 1))

for (n = 1 ;n <= 26; n++) row1 = row1 substr(alphabet, n, 1) " "

for (n = 1; n <= 26; n++) row2 = row2 substr(cipher, n, 1) " "

for (n = 0; n <= 9; n++) {
do {
r = rndnum(0, 9)
} while (r in map)
map[r] = n
}

row3 = map[0] pad(7) \
map[1] pad(7) \
map[2] pad(9) \
map[3] pad(1) \
map[4] pad(7) \
map[5] pad(1) \
map[6];

row4 = pad(8) map[7] \
pad(29) map[8];

row5 = pad(8) map[9];

print row1 "\n" row2 "\n" row3 "\n" row4 "\n" row5

}'

# eof


Notes


i. https://en.wikipedia.org/wiki/Caesar_cipher

ii. https://en.wikipedia.org/wiki/Homophone

iii. https://en.wikipedia.org/wiki/Frequency_analysis

iv. http://letterfrequency.org/

v. https://en.wikipedia.org/wiki/AWK

vi. https://en.wikipedia.org/wiki/Tabula_recta


License


[c]2017 Michael Sanders <https://busybox.hypermart.net>

Reprint freely so long as nothing is modified.


--
later on,
Mike

https://busybox.hypermart.net
0 new messages