You are viewing a single comment's thread. Return to all comments →
def caesarCipher(s, k): # Write your code here encrypted_word = "" alph = list(map(chr, range(97,123))) alph_copy = alph.copy() for i in range(k): alph.append(alph[0]) alph.pop(0) alph_map = dict(map(lambda i,j : (i,j), alph_copy, alph)) for letter in s: if letter == " ": continue elif letter in alph_copy or letter.isupper(): if letter.isupper(): corresponding_letter = alph_map[letter.lower()] corresponding_letter = corresponding_letter.capitalize() else: corresponding_letter =alph_map[letter] encrypted_word = encrypted_word + corresponding_letter + "" else: encrypted_word = encrypted_word + letter + "" return encrypted_word
Seems like cookies are disabled on this browser, please enable them to open this website
Caesar Cipher
You are viewing a single comment's thread. Return to all comments →
Python