Compare commits
No commits in common. "da9bdcadcf6bf3707c95b981ffddca30951ed8d6" and "171d7550a0c87d62e0f2d7b244dd36897620d8ce" have entirely different histories.
da9bdcadcf
...
171d7550a0
2 changed files with 0 additions and 25 deletions
|
@ -1,2 +0,0 @@
|
|||
def caesar(k : int, plain : str) -> str:
|
||||
return str([chr(ord(c) + k) for c in plain])
|
23
masc.py
23
masc.py
|
@ -1,23 +0,0 @@
|
|||
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
|
Loading…
Reference in a new issue