def e_vigenere1(plaintext, key): # your code here square = utilities_A2.get_vigenereSquare() ciphertext = '' for char in plaintext: if char.lower() in square[0]: plainIndx = square[0].index(char.lower()) keyIndx = square[0].index(key) cipherChar = square[keyIndx][plainIndx] ciphertext += cipherChar.upper() if char.isupper() else cipherChar else: ciphertext += char return ciphertext
def e_vigenere2(plaintext, key): square = utilities_A2.get_vigenereSquare() ciphertext = '' counter = 0 for char in plaintext: if char.lower() in square[0]: plainIndex = square[0].index(char.lower()) keyIndex = square[0].index(key[counter % len(key)]) cipherChar = square[keyIndex][plainIndex] ciphertext += cipherChar.upper() if char.isupper() else cipherChar counter += 1 else: ciphertext += char return ciphertext
def d_vigenere1(ciphertext, key): square = utilities_A2.get_vigenereSquare() plaintext = '' for char in ciphertext: if char.lower() in square[0]: keyIndex = square[0].index(key) plainIndex = 0 for i in range(26): if square[i][keyIndex] == char.lower(): plainIndex = i break plainChar = square[0][plainIndex] key = plainChar plaintext += plainChar.upper() if char.isupper() else plainChar else: plaintext += char return plaintext
def d_vigenere2(ciphertext, key): # your code here square = utilities_A2.get_vigenereSquare() plaintext = '' count = 0 for char in ciphertext: if char.lower() in square[0]: keyIndx = square[0].index(key[count % len(key)]) count += 1 plainIndx = 0 for i in range(26): if square[i][keyIndx] == char.lower(): plainIndx = i break plainChar = square[0][plainIndx] plaintext += plainChar.upper() if char.isupper() else plainChar else: plaintext += char return plaintext