What is cveinnt
?
When I was 8, I was fascinated with cryptopgraphy and loved playing with ciphers.
cveinnt
is the result of passing vincent
to the Enigma machine under a simple setting, illustrated here:
As shown, each character is shifted by its one-based index in the word, i.e.:
def encrypt(text = "vincent"):
# encryption only works when len is odd, can you think of why?
l = len(text) if len(text) % 2 == 1 else len(text) + 1
# shifted index is (1th_index + 1th_index) % 7
# for example, v's shifted index is (1 + 1) % 7 = 2
shifted_index = [2 * (i + 1) % l for i in range(len(text))]
# return a new string based on shifted index
return "".join([text[shifted_index.index((i + 1) % l)] for i in range(len(text))])
encrypt() # returns 'cveinnt'