Created
September 30, 2015 13:41
-
-
Save aabouzaid/90d4cb4df376d3389709 to your computer and use it in GitHub Desktop.
My solution for "Caesar Cipher" challenge on HackerRank.com - https://www.hackerrank.com/challenges/caesar-cipher-1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# Python 2.7.6 | |
# | |
# My solution for "Caesar Cipher" challenge on HackerRank.com | |
# https://www.hackerrank.com/challenges/caesar-cipher-1 | |
# | |
k = 2 | |
k = k%26 | |
n = 11 | |
s = "middle-Outz" | |
#Generate alphabetical list without using "string" module. | |
#And without duplicate the whole list. | |
chars_list = map(chr, range(65, 91)) + map(chr, range(65, 91))[0:k] + map(chr, range(97, 123)) + map(chr, range(97, 123))[0:k] | |
for char in s.replace("-",""): | |
s = s.replace(char, chars_list[chars_list.index(char) + 2], 1) | |
print s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's Unicode code for characters.
For example
chr(97)
isa
.Read more about Python built-in function
chr
:https://docs.python.org/3/library/functions.html#chr