You are viewing a single comment's thread. Return to all comments →
JS Solution
const isCharUpperCase = (char) => char === char.toUpperCase(); const isFound = (char, s) => s.includes(char.toLowerCase()); function caesarCipher(s, k) { k = k > 26 ? k % 26 : k; const alphabet = 'abcdefghijklmnopqrstuvwxyz'; const ns = alphabet.substring(k, alphabet.length) + alphabet.substring(0, k); let z = ''; for (let i = 0; i < s.length; i++) { let isUp = isCharUpperCase(s[i]); let isFd = isFound(s[i], ns); if (!isUp && isFd) { z += ns.charAt(alphabet.indexOf(s[i])); } else if (isUp && isFd) { z += ns.charAt(alphabet.indexOf(s[i].toLowerCase())).toUpperCase(); } else if (!isFd) { z += s[i]; } } console.log(z); return z; }
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 →
JS Solution