Porta Cipher

This Python function encrypt/decrypt a string with the Porta cipher:

In [1]:
def Porta(plain, key):
    alpha26 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' # standard alphabet
    numkey = [alpha26.index(c)//2 for c in key]
    crypto = ''
    keyidx = 0
    for c in plain:
        idx = alpha26.index(c)
        if idx < 13:       # c in the first half of alpha26
            crypto += alpha26[(idx + numkey[keyidx])%13 + 13]
        else:              # c in the second half of alpha26
            crypto += alpha26[(idx - numkey[keyidx])%13]
        keyidx = (keyidx+1)%len(key) # increment key index 
    return crypto

Encryption

In [2]:
Porta('PORTACIPHERWITHOUTATABLE', 'SECRET')
Out[2]:
'GMDLPYRAVZCAREVGFKWEOWNN'

Decryption

In [3]:
Porta('GMDLPYRAVZCAREVGFKWEOWNN', 'SECRET')
Out[3]:
'PORTACIPHERWITHOUTATABLE'

Le 27/12/2021 - Contact : Rossignol@bribes.org