Files
Mysteryhelfer/EinzelfunktionenExperimentierbereich/kenny/unkennify.py

32 lines
831 B
Python

from re import match
def unkennify(text):
# Funktion hier entnommen und angepasst: https://www.namesuppressed.com/software/kenny.py
decoded = ''
codemap = str.maketrans('MmPpFf', '001122')
print(codemap)
n_len = len(text)
i = 0
while i + 3 <= n_len:
if match('[MmPpFf]{3,}', text[i:i + 3]):
# 'mpf' -> '012' -> 5
num = int(text[i:i + 3].translate(codemap), 3)
# 5 -> 'f'
cypher = chr(num + ord('a'))
if text[i].isupper():
cypher = cypher.upper()
decoded = decoded + cypher
i = i + 3
else:
decoded = decoded + text[i]
i = i + 1
if i < n_len:
decoded = decoded + text[i:]
return decoded
print(unkennify("Fmpmppfmmfmp ppmmffmmfmfp ppmmmmpmf"))