23 lines
691 B
Python
23 lines
691 B
Python
default_alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
|
|
def masc(k : str, plain : str, alphabet : str = default_alphabet):
|
|
# make sure that k only contains characters from alphabet
|
|
for c in k:
|
|
if c not in alphabet:
|
|
raise ValueError("key contains character thats not in alphabet, namely: " + c)
|
|
|
|
# build key
|
|
## make unique
|
|
k_unique = []
|
|
for c in k:
|
|
if not (c in k_unique):
|
|
k_unique.append(c)
|
|
|
|
## append alphabet
|
|
last = k_unique[len(k_unique) - 1]
|
|
alphabet_pos = alphabet.index(last)
|
|
for i in list(range(alphabet_pos + 1, len(alphabet))) + list(range(0, alphabet_pos)):
|
|
if alphabet[i] not in k_unique:
|
|
k_unique.append(alphabet[i])
|
|
|
|
return k_unique
|