We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
def caesarCipher(s, k):
alphabet = "abcdefghijklmnopqrstuvwxyz"
res = ""
for c in s:
is_upper = c.isupper()
idx = alphabet.find(c.lower())
if idx != -1:
new_idx = (idx + k) % 26
res += alphabet[new_idx].upper() if is_upper else alphabet[new_idx]
else:
res += c
return res
Cookie support is required to access HackerRank
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 →