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):
alp ="abcdefghijklmnopqrstuvwxyz"
if k>2:
if k>26:
k= k%26
ro = alp[k:]+alp[:k]
j= list(s)
lt = []
for i in j:
if i.lower() not in alp:
lt.append(i)
elif i.isupper():
k= alp.index(i.lower())
lt.append((ro[k]).upper())
else:
k= alp.index(i)
lt.append(ro[k])
fin = ''.join(lt)
return fin
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 →
def caesarCipher(s, k): alp ="abcdefghijklmnopqrstuvwxyz" if k>2: if k>26: k= k%26 ro = alp[k:]+alp[:k] j= list(s) lt = []