Skip to content

Instantly share code, notes, and snippets.

@kentatogashi
Created September 5, 2018 23:36
Show Gist options
  • Save kentatogashi/c2723b6ca42999e3a7e93740e76d9b4a to your computer and use it in GitHub Desktop.
Save kentatogashi/c2723b6ca42999e3a7e93740e76d9b4a to your computer and use it in GitHub Desktop.
文字列をrot13変換する
_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