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.
defcaesarCipher(string:str,k:int)->str:ifk==0:returnstringvocab="abcdefghijklmnopqrstuvwxyz"cipher=[]forcharinstring:ifnotchar.isalpha():cipher.append(char)else:idx=vocab.index(char.lower())#indexofcharacternew_char=vocab[(idx+k)%len(vocab)]#shiftindex# capitalise if required:new_char=new_char.upper()ifchar.isupper()elsenew_charcipher.append(new_char)return"".join(cipher)
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 solution: