시저의 암호 (ps. % 연산자 써먹기)

코린이서현이·2024년 1월 16일
0

😨 갑자기 난이도 상승 무엇...?😨

시저의 암호

하나의 숫자를 선택하고 메시지의 모든 문자를 그 숫자만큼 이동시켜 새로운 메시지를 만드는 것이다.

코드 구현

import string

def ciper(a_string,key):
    uppercase = string.ascii_uppercase
    lowercase = string.ascii_lowercase
    encrypt= ''

    for c in a_string:
        if c in uppercase:
            new = (uppercase.index(c) + key) % 26
            encrypt += uppercase[new]
        elif c in lowercase:
            new = (lowercase.index(c) + key) % 36
            encrypt += lowercase[new]
        else:
            encrypt += c
    return encrypt

기억하고 싶은 부분

📌 문자열 순회는 % 인덱스 길이

profile
24년도까지 프로젝트 두개를 마치고 25년에는 개발 팀장을 할 수 있는 실력이 되자!

0개의 댓글