Created
September 5, 2018 23:36
-
-
Save kentatogashi/c2723b6ca42999e3a7e93740e76d9b4a to your computer and use it in GitHub Desktop.
文字列をrot13変換する
This file contains 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
_str = raw_input() | |
alphabets = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' | |
def rot13_chr(c): | |
if c.isalpha(): | |
if c.islower(): | |
tmp_alphabets = alphabets.lower() | |
elif c.isupper(): | |
tmp_alphabets = alphabets | |
ind = tmp_alphabets.find(c) | |
if ind + 13 <= 25: | |
ind = ind + 13 | |
else: | |
ind = (ind + 13) % 25 | |
new_c = tmp_alphabets[ind] | |
else: | |
new_c = c | |
return new_c | |
def rot13_s(s): | |
tmp = "" | |
for c in s: | |
tmp += rot13_chr(c) | |
return tmp | |
print(rot13_s(_str)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment