After watching this tutorial about the Vigenere Cipher, I (hopefully) understand its basic concepts. We want to assign a key to a string, and then shift each letter in the string by the (0-based) alphabet-position value of each letter in the key. So when using bacon as the key,
Meet me in the park at eleven am
baco nb ac onb acon ba conbac on
becomes
Negh zf av huf pcfx bt gzrwep oz
As I'm writing a Vigenere Cipher from scratch, I only know that the first step is to assign the key to a string. And while I'm doing this, I want to recognize whether or not each of the characters is alpha so that I can preserve any special characters in the string (!, @, #, etc.) if there are any.
text = input("Enter some text:")
def encrypt(text):
#key = bacon
encrypted = []
baconvalue = {'A':0, 'a':0, 'B':1, 'b':1, 'C':2, 'c':2, 'D':3, 'd':3, 'E':4, 'e':4, 'F':5, 'f':5, 'G':6, 'g':6, 'H':7, 'h':7, 'I':8, 'i':8, 'J':9, 'j':9, 'K':10, 'k':10, 'L':11, 'l':11, 'M':12, 'm':12, 'N': 13, 'n':13, 'O':14, 'o':14, 'P':15, 'p':15, 'Q':16, 'q':16, 'R':17, 'r':17, 'S':18, 's':18, 'T':19, 't':19, 'U':20, 'u':20, 'V':21, 'v':21, 'W':22, 'w':22, 'X':23, 'x':23, 'Y':24, 'y':24, 'Z':25, 'z':25 }
for letter in text:
#assign 'bacon' to text to get rotation value for each character
#preserve alpha characters
if letter.isalpha():
#character in string rotates x amount according to the corresponding value of char in bacon
encrypted.append(letter, baconvalue)
else:
encrypted.append(letter)
return ''.join(encrypted)
print(encrypt(text,))
But as you can see, I don't know where to start as far as how to assign bacon to the string. Am I at least on the right track?