[Tutor] Porta cipher in python [ot?]

Tesla Coil tescoil@irtc.net
Thu, 15 Mar 2001 10:29:51 -0500


> I posted a question about a Porta cipher 
> algorithm to sci.crypt, but I thought I'd 
> ask the cryptographically-minded Python 
> gurus here: all I'm after is the basic 
> algorithm, I can do the rest :)  Believe
> me, I've searched the net, and I haven't
> found a single clue to it.

You can think of a Porta Tableau as an extended
case of ROT13--if keyletter in ['A', 'B']: it's
ordinary ROT13--and it remains essentially ROT13
for any other keyletter, but ROT13 on a different
construction of the alphabet.

Those alphabets differ only in that (hold on...) 

>>> alphabet = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
>>> porta = [alphabet[0:13], alphabet[13:26]]

porta[0] remains fixed, and porta[1] is rotated
conditionally upon the key:

>>> keypair = []
>>> for x in range(0,26,2):
...     keypair.append([alphabet[x], alphabet[x+1]])
...
>>> for x in range(len(keypair)):
...     if x == 0:
...         pass
...     else: 
...         rot = porta[1].pop(12)
...         porta[1].insert(0, rot)
...     print keypair[x], porta[1]

Perhaps load a dictionary on a similar basis.

Hopefully this assists you with your question, 
and other tutor participants with understanding
whatever it was you were asking... ;)