• Cryptogram Engine

    From Mike Sanders@21:1/5 to All on Sat Mar 18 19:47:11 2017
    #!/bin/sh

    <<DOC

    Cryptogram Engine: v0.2 - Michael Sanders 2017

    about...

    . simple cryptogram creation using awk

    . logic & data embedded within a single container

    . example limited to three cryptograms for brevity

    . for an archive containing 500+ cryptograms visit:

    http://busybox.hypermart.net/cryptogram.html

    tips...

    . no letter represents itself (X never equals X)

    . multiple instances of a letter always have the
    same value (if B equals N, then all B's equal N)

    . decipher smaller words first (thereby quickly
    exposing letters for reuse)

    . only two single-letter words exist in the
    english language: A & I

    . relax - its just a fun script because that's all
    it has to be =)

    letter frequency by usage...

    e: 12.702% m: 02.406%
    t: 09.056% w: 02.360%
    a: 08.167% f: 02.228%
    o: 07.507% g: 02.015%
    i: 06.966% y: 01.974%
    n: 06.749% p: 01.929%
    s: 06.327% b: 01.492%
    h: 06.094% v: 00.978%
    r: 05.987% k: 00.772%
    d: 04.253% j: 00.153%
    l: 04.025% x: 00.150%
    c: 02.782% q: 00.095%
    u: 02.758% z: 00.074%

    further reading...

    https://en.wikipedia.org/wiki/Cryptogram

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

    https://www.rosettacode.org/wiki/Caesar_cipher#AWK

    https://en.wikipedia.org/wiki/Letter_frequency

    DOC

    #e=$(dd if=/dev/urandom bs=9 count=1)
    e=$RANDOM

    awk -v e=$e '

    /^exit/{q=1}

    {if (q && $0 !~ /exit/ && length($0) > 0) d[++j] = $0}

    END{

    srand(e)

    p = toupper(d[rndnum(1, j)])
    m = mask(p)

    do {
    c = caesarshift(rndnum(1, 26), p)
    } while (substr(p, 1, 1) == substr(c, 1, 1))

    print "cryptogram..."
    print "encoded: " c
    print "decoded: " m
    print "solution: " p

    }

    function caesarshift(k, m, p, c, x, y, z, s) {

    p = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    c = substr(p, k + 1) substr(p, 1, k)
    x = length(m)

    for (y = 1; y <= x; y++) {
    z = index(p, substr(m, y, 1))
    s = (z) ? s substr(c, z, 1) : s substr(m, y, 1)
    }

    return s

    }

    function mask(m, x,y,z,r,s) {

    x = length(m)
    y = int(x / 2) + 1

    for (z = 1; z <= y; z++) {
    do {
    r = rndnum(1, x)
    } while (r in a || substr(m, r, 1) !~ /[A-Z]/)
    a[r] = r
    }

    for (z = 1; z <= x; z++) s = (a[z]) ? s "_" : s substr(m, z, 1)

    return s

    }

    function rndnum(lo, hi) {return int(lo + rand() * (hi - lo + 1))}

    ' < $0

    exit

    hunky-dory
    say goodnight gracie
    willy nilly


    --
    later on,
    Mike

    http://busybox.hypermart.net

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)