This is an exercise to create functions which will encrypt and decrypt strings using Trithemius cipher.

Trithemius cipher is a simple encrypting method making use of a "tabula recta", as the one below:

1  - 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 |0 |1 |2 |3 |4 |5 |6 |7 |8 |9 |
2  - 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 |0 |1 |2 |3 |4 |5 |6 |7 |8 |9 |a |
3  - c |d |e |f |g |h |i |j |k |l |m |n |o |p |q |r |s |t |u |v |w |x |y |z |0 |1 |2 |3 |4 |5 |6 |7 |8 |9 |a |b |
4  - d |e |f |g |h |i |j |k |l |m |n |o |p |q |r |s |t |u |v |w |x |y |z |0 |1 |2 |3 |4 |5 |6 |7 |8 |9 |a |b |c |
5  - e |f |g |h |i |j |k |l |m |n |o |p |q |r |s |t |u |v |w |x |y |z |0 |1 |2 |3 |4 |5 |6 |7 |8 |9 |a |b |c |d |
6  - f |g |h |i |j |k |l |m |n |o |p |q |r |s |t |u |v |w |x |y |z |0 |1 |2 |3 |4 |5 |6 |7 |8 |9 |a |b |c |d |e |
7  - g |h |i |j |k |l |m |n |o |p |q |r |s |t |u |v |w |x |y |z |0 |1 |2 |3 |4 |5 |6 |7 |8 |9 |a |b |c |d |e |f |
8  - h |i |j |k |l |m |n |o |p |q |r |s |t |u |v |w |x |y |z |0 |1 |2 |3 |4 |5 |6 |7 |8 |9 |a |b |c |d |e |f |g |
9  - i |j |k |l |m |n |o |p |q |r |s |t |u |v |w |x |y |z |0 |1 |2 |3 |4 |5 |6 |7 |8 |9 |a |b |c |d |e |f |g |h |
10 - j |k |l |m |n |o |p |q |r |s |t |u |v |w |x |y |z |0 |1 |2 |3 |4 |5 |6 |7 |8 |9 |a |b |c |d |e |f |g |h |i |
11 - k |l |m |n |o |p |q |r |s |t |u |v |w |x |y |z |0 |1 |2 |3 |4 |5 |6 |7 |8 |9 |a |b |c |d |e |f |g |h |i |j |
12 - l |m |n |o |p |q |r |s |t |u |v |w |x |y |z |0 |1 |2 |3 |4 |5 |6 |7 |8 |9 |a |b |c |d |e |f |g |h |i |j |k |
13 - m |n |o |p |q |r |s |t |u |v |w |x |y |z |0 |1 |2 |3 |4 |5 |6 |7 |8 |9 |a |b |c |d |e |f |g |h |i |j |k |l |
14 - n |o |p |q |r |s |t |u |v |w |x |y |z |0 |1 |2 |3 |4 |5 |6 |7 |8 |9 |a |b |c |d |e |f |g |h |i |j |k |l |m |
15 - o |p |q |r |s |t |u |v |w |x |y |z |0 |1 |2 |3 |4 |5 |6 |7 |8 |9 |a |b |c |d |e |f |g |h |i |j |k |l |m |n |
16 - p |q |r |s |t |u |v |w |x |y |z |0 |1 |2 |3 |4 |5 |6 |7 |8 |9 |a |b |c |d |e |f |g |h |i |j |k |l |m |n |o |
17 - q |r |s |t |u |v |w |x |y |z |0 |1 |2 |3 |4 |5 |6 |7 |8 |9 |a |b |c |d |e |f |g |h |i |j |k |l |m |n |o |p |
18 - r |s |t |u |v |w |x |y |z |0 |1 |2 |3 |4 |5 |6 |7 |8 |9 |a |b |c |d |e |f |g |h |i |j |k |l |m |n |o |p |q |
19 - s |t |u |v |w |x |y |z |0 |1 |2 |3 |4 |5 |6 |7 |8 |9 |a |b |c |d |e |f |g |h |i |j |k |l |m |n |o |p |q |r |
20 - t |u |v |w |x |y |z |0 |1 |2 |3 |4 |5 |6 |7 |8 |9 |a |b |c |d |e |f |g |h |i |j |k |l |m |n |o |p |q |r |s |
21 - u |v |w |x |y |z |0 |1 |2 |3 |4 |5 |6 |7 |8 |9 |a |b |c |d |e |f |g |h |i |j |k |l |m |n |o |p |q |r |s |t |
22 - v |w |x |y |z |0 |1 |2 |3 |4 |5 |6 |7 |8 |9 |a |b |c |d |e |f |g |h |i |j |k |l |m |n |o |p |q |r |s |t |u |
23 - w |x |y |z |0 |1 |2 |3 |4 |5 |6 |7 |8 |9 |a |b |c |d |e |f |g |h |i |j |k |l |m |n |o |p |q |r |s |t |u |v |
24 - x |y |z |0 |1 |2 |3 |4 |5 |6 |7 |8 |9 |a |b |c |d |e |f |g |h |i |j |k |l |m |n |o |p |q |r |s |t |u |v |w |
25 - y |z |0 |1 |2 |3 |4 |5 |6 |7 |8 |9 |a |b |c |d |e |f |g |h |i |j |k |l |m |n |o |p |q |r |s |t |u |v |w |x |
26 - z |0 |1 |2 |3 |4 |5 |6 |7 |8 |9 |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 |
27 - 0 |1 |2 |3 |4 |5 |6 |7 |8 |9 |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 |
28 - 1 |2 |3 |4 |5 |6 |7 |8 |9 |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 |0 |
29 - 2 |3 |4 |5 |6 |7 |8 |9 |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 |0 |1 |
30 - 3 |4 |5 |6 |7 |8 |9 |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 |0 |1 |2 |
31 - 4 |5 |6 |7 |8 |9 |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 |0 |1 |2 |3 |
32 - 5 |6 |7 |8 |9 |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 |0 |1 |2 |3 |4 |
33 - 6 |7 |8 |9 |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 |0 |1 |2 |3 |4 |5 |
34 - 7 |8 |9 |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 |0 |1 |2 |3 |4 |5 |6 |
35 - 8 |9 |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 |0 |1 |2 |3 |4 |5 |6 |7 |
36 - 9 |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 |0 |1 |2 |3 |4 |5 |6 |7 |8 |

The encryption is done as follows:

The first character in the string to be encrypted corresponds to the letter in the first row (i.e., itself). The Second character in the string corresponds to the character 1 row below itself. The third character in the string corresponds to the letter 2 rows below itself.

So if "a" is the first character, it remains as "a". If "a" is the second character, it converts to the character 1 row below "a", which is "b". If "a" is the third character in the string, it converts to the letter 2 rows below "a", which is "c". And so on. So, the string "hello" would be encrypted to "hfnos".

This code is very easily cracked, being based on a very predictable n+1, n+2, n=3,... pattern. Trithemius cipher has no key to randomize it. I once wrote a message encrypted this way on my Facebook page as a joke, throwing a good-natured taunt at the NSA. I didn't expect a reply (contrary to what Hollywood would have one think) but within minutes, a Facebook friend of mine who was working at the NSA responded to my post in plain English -- "Same to you, buddy!" So to the people who make a living cracking secret code, this is essentially kindergarten level encryption. But a key is easily created, as a string of random numbers, so that the number of rows to traverse down for each character corresponds to the random sequence of key numbers, rather than n+1, n+2, n=3,...and this is much more difficult to crack. For example -- if my key were "5,21,6,14,7" then "hello" would encrypt to "mzrzv":

5 rows down from h = "m"
21 rows down from e = "z"
6 rows down from l = "r"
14 rows down from l = "z"
7 rows down from 0 = "v"

With a key thousands or millions of integers long, it would theoretically take centuries or longer for the fastest computers today to crack. And, you can always put the message through multiple rounds of encrypting...

The text areas below will encrypt/decrypt to Trithemius cipher using the key entered (or a default key, if none). I modified the coding scheme to include numbers on 6/3/2010. Ideally, the coding scheme would include all characters, including blank spaces (so individual words can't be indentified), capital letters, and special characters.
Key (comma-delimited list of positive whole numbers):  
Text:

CipherText: