Skip to content

Instantly share code, notes, and snippets.

@shoark7
Last active April 21, 2021 02:38
Show Gist options
  • Save shoark7/49717a2ba422cceb9498fdabf1257e56 to your computer and use it in GitHub Desktop.
Save shoark7/49717a2ba422cceb9498fdabf1257e56 to your computer and use it in GitHub Desktop.
소문자 문자열 카이사르 암호 만들기
"""문자열을 입력받아 카이사르 암호를 만들어라.
:입력: str | 영어 소문자 문자열. 크기는 0 이상. (ex: `word`)
:출력: str | 각 글자를 오른쪽으로 3씩 옮긴 암호. (ex: `zrug`)
:조건:
1. 입력에는 영어 소문자 이외의 글자는 들어오지 않는다. 예를 들어 대문자, 한글, 공백문자 등.
"""
def caesar_cipher(word):
UNICODE_BASE = ord('a')
ALPHA_LENGTH = 26
ret = '' # ret은 'return'의 줄임말로 개인적인 선택입니당! 큰 의미 ㄴㄴ입니다.
for c in word:
ret += chr(UNICODE_BASE + (ord(c) - UNICODE_BASE + 3) % ALPHA_LENGTH)
return ret
###############################################################################
########################## 그게 최선입니까? 확실해요? ############################
###############################################################################
def caesar_cipher(word, moves):
UNICODE_BASE = ord('a')
ALPHA_LENGTH = 26
ret = '' # ret은 'return'의 줄임말로 개인적인 선택입니당! 큰 의미 ㄴㄴ입니다.
for c in word:
ret += chr(UNICODE_BASE + (ord(c) - UNICODE_BASE + moves) % ALPHA_LENGTH)
return ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment