Source

kennyspeak.py / README

.. -*- restructuredtext -*-

===============
 kennyspeak.py
===============

:author: Marc 'BlackJack' Rintsch
:date: 2010-07-23

.. image:: http://api.flattr.com/button/button-static-50x60.png
    :alt: Flattr this
    :align: right
    :target: http://flattr.com/thing/43705/kennyspeak-py


Why another Python solution
===========================

There already was a Python version of this program on the website of Kohan Ikin but it looked to "unpythonic" to me.  It uses tabs for indentation and a completely unneccesary, bogus class which is nothing more than a namespace for functions.  It is instanciated in the code several times just to call a function on it an then throw the instance right away.  Furthermore it uses the anti-idiom of ``for i in range(len(text)):`` without the actual need of `i` other than using it as index into the text.

Last but not least I disliked the user interface.  En- and decrypting text given on the command line is not as flexible as using files as input and output with `stdin` und `stdout` as default.  This allows using the program with file redirections and as filter in pipes.

Usage
=====

By default the program reads data from standard input, encodes it as "kennyspeak" and writes it to standard output.  There are options to tell the program to decypher "kennyspeak" back to normal ASCII characters and to use named files as source or destination instead of the standard IO channels.

Options
-------

  --version        show program's version number and exit
  -h, --help       show this help message and exit
  -k, --kennify    kennify text (default)
  -u, --unkennify  unkennify text
  -i FILENAME      read from file (default: stdin)
  -o FILENAME      write to file (default: stdout)

Examples
--------

::

    $ echo 'Hello, World!' | python kennyspeak.py
    Mfpmpppmfpmfppf, Fppppfpffpmfmpm!

The Code
========

The code itself is quite simple.  It's a replacement code which replaces just the letters ``a`` to ``z`` with triplets made of Kenny's very restricted alphabet consisting just of the letters ``m``, ``p``, and ``f``.  The mapping is made by numbering the letters ``a`` to ``z`` from 0 to 25 and take the base 3 representation of that values left filled with zeros to three digits.  The three possible digits 0-2 are then mapped to the three letters from Kenny's alphabet.

======  ======  ======  ======= =========
Letter  Value   Base 3  Triplet Uppercase
======  ======  ======  ======= =========
a        0      000     mmm     Mmm
------  ------  ------  ------- ---------
b        1      001     mmp     Mmp
------  ------  ------  ------- ---------
c        2      002     mmf     Mmf
------  ------  ------  ------- ---------
d        3      010     mpm     Mpm
------  ------  ------  ------- ---------
e        4      011     mpp     Mpp
------  ------  ------  ------- ---------
f        5      012     mpf     Mpf
------  ------  ------  ------- ---------
g        6      020     mfm     Mfm
------  ------  ------  ------- ---------
h        7      021     mfp     Mfp
------  ------  ------  ------- ---------
i        8      022     mff     Mff
------  ------  ------  ------- ---------
j        9      100     pmm     Pmm
------  ------  ------  ------- ---------
k       10      101     pmp     Pmp
------  ------  ------  ------- ---------
l       11      102     pmf     Pmf
------  ------  ------  ------- ---------
m       12      110     ppm     Ppm
------  ------  ------  ------- ---------
n       13      111     ppp     Ppp
------  ------  ------  ------- ---------
o       14      112     ppf     Ppf
------  ------  ------  ------- ---------
p       15      120     pfm     Pfm
------  ------  ------  ------- ---------
q       16      121     pfp     Pfp
------  ------  ------  ------- ---------
r       17      122     pff     Pff
------  ------  ------  ------- ---------
s       18      200     fmm     Fmm
------  ------  ------  ------- ---------
t       19      201     fmp     Fmp
------  ------  ------  ------- ---------
u       20      202     fmf     Fmf
------  ------  ------  ------- ---------
v       21      210     fpm     Fpm
------  ------  ------  ------- ---------
w       22      211     fpp     Fpp
------  ------  ------  ------- ---------
x       23      212     fpf     Fpf
------  ------  ------  ------- ---------
y       24      220     ffm     Ffm
------  ------  ------  ------- ---------
z       25      221     ffp     Ffp
======  ======  ======  ======= =========