Skip to content

Instantly share code, notes, and snippets.

@aabouzaid
Created September 30, 2015 13:41
Show Gist options
  • Save aabouzaid/90d4cb4df376d3389709 to your computer and use it in GitHub Desktop.
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
#!/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
@sultanarif-p
Copy link

what is 97 , 123 , 65

@aabouzaid
Copy link
Author

what is 97 , 123 , 65

It's Unicode code for characters.
For example chr(97) is a.

Read more about Python built-in function chr:
https://docs.python.org/3/library/functions.html#chr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment