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.
functioncaesarCipher(s,k){// Write your code herek=k%26letencrypted=""for(leti=0;i<s.length;i++){letchar=s[i]// Check if the character is a letterif(char>='a'&&char<='z'){// Shift lowercase lettersletnewChar=String.fromCharCode(((char.charCodeAt(0)-97+k)%26)+97)encrypted+=newChar}elseif(char>='A'&&char<='Z'){letnewChar=String.fromCharCode(((char.charCodeAt(0)-65+k)%26)+65)encrypted+=newChar}else{encrypted+=char}}returnencrypted}
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 →
Here is a Javascript solution