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.
base is ascii code for 'a' in lowercase and 'A' in uppercase, used to switch between ASCII code and letter sequence number (calculate things like "z+4" is much easier using letter sequence numbers than ASCII codes, because there are other characters in ASCII, while only letters in alphabet)
e.g.
you have string "C" and K=100
ascii code for 'C' is 67, it's uppercase, so your base is 'A' or 65
substract the base to convert ASCII code to letter sequence number in English alphabet (starting from zero) 67-65=2
add the K, 2+100=102
102nd letter does not make any sense, since there are only 26 letters in English alphabet, so we use modulus %26 to remove "full circles", 102%26=24
24th (starting from zero) letter makes sense, but we have to calculate ASCII code for it by adding base 24+65 = 89
89 is 'Y'
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 →
base is ascii code for 'a' in lowercase and 'A' in uppercase, used to switch between ASCII code and letter sequence number (calculate things like "z+4" is much easier using letter sequence numbers than ASCII codes, because there are other characters in ASCII, while only letters in alphabet)
e.g. you have string "C" and K=100 ascii code for 'C' is 67, it's uppercase, so your base is 'A' or 65