Created
June 7, 2017 14:05
-
-
Save codertimo/979c9cffac259e028914f3478d0a4b81 to your computer and use it in GitHub Desktop.
[KMU_SW_17] 시저 암호 알고리즘
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
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