There was an error while loading. Please reload this page.
1 parent 327554e commit 35e7241Copy full SHA for 35e7241
HackerRank/Caesar-Cipher-1.py
@@ -0,0 +1,19 @@
1
+# Ceasar Cipher 1
2
+# https://www.hackerrank.com/challenges/caesar-cipher-1/problem
3
+
4
+def caesarCipher(s, k):
5
+ alphabet = "abcdefghijklmnopqrstuvwxyz".upper()
6
+ ans = ""
7
+ for char in s:
8
+ if char.upper() in alphabet:
9
+ rotated = alphabet[(alphabet.index(char.upper())+k)%26]
10
+ ans += rotated if char.isupper() else rotated.lower()
11
+ else:
12
+ ans += char
13
+ return ans
14
15
+# Testcases
16
+# "middle-Outz" 2 -> "okffng-Qwvb"
17
+# "Always-Look-on-the-Bright-Side-of-Life" 5 -> "Fqbfdx-Qttp-ts-ymj-Gwnlmy-Xnij-tk-Qnkj"
18
19
+# Status - Accepted
0 commit comments