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.
# https://www.hackerrank.com/challenges/caesar-cipher-1n,s,k=int(raw_input()),raw_input(),int(raw_input())defrotK(char):base="A"*char.isupper()+"a"*char.islower()# Char wasn't even alpha (not upper/lower)ifbase=="":returnchar# Convert the character to alphabet position.# ord() will give the ASCII number, so substract# the a/A (depending on case) ASCII value to get # absolute index in alphabet.pos=ord(char)-ord(base)# Advance the position by k, then do mod 26.pos=(pos+k)%26# Convert the new position back to character,# according to base (uppercase or lowercase).char=chr(pos+ord(base))returncharprint"".join(map(rotK,s))
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 →
Python with a custom mapping function.