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.
- Caesar Cipher
- Discussions
Caesar Cipher
Caesar Cipher
Sort by
recency
|
587 Discussions
|
Please Login in order to post a comment
I solved it slightly differently using Typescript. I created a dictionary that will have the original letter as the key and then the rotated letter as the value. I then iterate over the string and map that char to the dictionary and check for special chars or uppercase (regex) into a new string
` function caesarCipher(s: string, k: number): string { // Write your code here const alph = 'abcdefghijklmnopqrstuvwxyz' const dic: Dictionary = {} for (let i = 0; i < alph.length; i++) { const rotated = (i + k) % 26 dic[alph[i]] = alph[rotated] }
}
single line python
js single line code solution: