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.
defgetEncryptedLetter(s,k,isUpper=True):startChar="A"ifisUpperelse"a"endChar="Z"ifisUpperelse"z"num=ord(s)k=k%26ifnum+k>ord(endChar):diff=(num+k)-ord(endChar)new_num=ord(startChar)+diff-1else:new_num=num+kreturnchr(new_num)defcaesarCipher(s,k):# Write your code hereexcrypted_str=""foriins:if("A"<=i<="Z")or("a"<=i<="z"):excrypted_str+=getEncryptedLetter(i,k,"A"<=i<="Z")continueexcrypted_str+=ireturnexcrypted_str
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 →