← coderbyte_practice

does not work

9aa3194f99629a9f713fffd145cbc27ba655b43b · ovidiucs · May 9, 2015 21:42

+31 · 1 file changed

  • medium/11-caesar-cypher.py +31 −0
diff --git a/medium/11-caesar-cypher.py b/medium/11-caesar-cypher.py
new file mode 100644
index 0000000..84bf2bb
--- /dev/null
+++ b/medium/11-caesar-cypher.py
@@ -0,0 +1,31 @@
+__author__ = 'ovidiucs'
+
+"""
+Using the Python language, have the function CaesarCipher(str,num) take the str
+parameter and perform a Caesar Cipher shift on it using the num parameter as the
+shifting number. A Caesar Cipher works by shifting each letter in the string N
+ places down in the alphabet (in this case N will be num). Punctuation, spaces,
+  and capitalization should remain intact. For example if the string is "Caesar
+   Cipher" and num is 2 the output should be "Ecguct Ekrjgt".
+"""
+# Input = "Hello" & num = 4Output = "Lipps"
+# Input = "abc" & num = 0Output = "abc"
+
+
+def CaesarCipher(str, num):
+
+    ax = list("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
+    s = []
+    for i in str:
+        if i in ax:
+            # s.append(ax.index(i))
+            s.append(ax.index(i) % len(ax))
+        else:
+            s.append(i)
+
+    return s
+
+# keep this function call here
+# to see how to enter arguments in Python scroll down
+print CaesarCipher("zaAZ", -1)
+