Skip to content

Instantly share code, notes, and snippets.

@codertimo
Created June 7, 2017 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codertimo/979c9cffac259e028914f3478d0a4b81 to your computer and use it in GitHub Desktop.
Save codertimo/979c9cffac259e028914f3478d0a4b81 to your computer and use it in GitHub Desktop.
[KMU_SW_17] 시저 암호 알고리즘
def is_small(n):
if 97 <= n <= 122:
return True
else:
return False
def shift(c, shift_count):
if not (65 <= ord(c) <= 90 or 97 <= ord(c) <= 122):
return c
if is_small(ord(c)):
if ord(c) + shift_count > 122:
tmp = ord(c) + shift_count - 122 - 1
return chr(97 + tmp)
else:
return chr(ord(c) + shift_count)
else:
if ord(c) + shift_count > 90:
tmp = ord(c) + shift_count - 90 - 1
return chr(65 + tmp)
else:
return chr(ord(c) + shift_count)
n = int(input())
for i in range(n):
shift_count = int(input())
text = list(input())
result_text = ""
for c in text:
result_text += shift(c, shift_count)
print(result_text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment