티스토리 뷰
alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
import art #from art import logo
print(art.logo)
def caesar(text,shift,direction):
output_text=''
if direction == "encode":
for char in text:
if char in alphabet and ((alphabet.index(char))+shift) <= 25:
output_text += alphabet[(alphabet.index(char))+shift]
elif char in alphabet and ((alphabet.index(char))+shift) > 25:
output_text += alphabet[((alphabet.index(char))+shift)%26]
else:
output_text += char
#print(f"The {direction}ed text is \'{''.join(input_txt)}\'.")
print(f"The {direction}ed text is \'{output_text}\'.")
elif direction == "decode":
for char in text:
if char in alphabet and ((alphabet.index(char))-shift) >= 0:
output_text += alphabet[(alphabet.index(char))-shift]
elif char in alphabet and ((alphabet.index(char))-shift) < 0:
output_text += alphabet[((alphabet.index(char))-shift)%26]
else:
output_text += char
print(f"The {direction}ed text is \'{output_text}\'.")
else :
print("Error! Type 'encode' to encrypt, type 'decode' to decrypt.")
repeat = True
while repeat:
direction = input("Type 'encode' to encrypt, type 'decode' to decrypt:\n")
text = input("Type your message:\n").lower()
shift = int(input("Type the shift number:\n"))
caesar(text,shift,direction)
restart = input("Type 'yes if you want to go again. Otherwise type 'no'.\n")
if restart == "no":
repeat = False
print("Goodbye")
'Test > Python(20220101~)' 카테고리의 다른 글
Day9_Dictionary, 점수를 가지고 등급 매기는 프로그램 (0) | 2022.01.12 |
---|---|
Day9_Dictionaries, Nesting (0) | 2022.01.11 |
Day8_Caesar 암호 2단계, decode (0) | 2022.01.10 |
Day8_Caesar 암호 1단계, encoding (0) | 2022.01.09 |
Day8_Prime Number(소수) 감별 (0) | 2022.01.09 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- dp-1
- 변수화
- storage
- LIST
- 정렬
- 중복제거
- insert
- dp-2
- virt-sysprep
- 3par
- vmware.powercli
- dezoomify
- Join
- cloud-init
- EXA
- 대소문자
- artandculture
- 부동없이
- set()
- 배열
- 읽어오기
- 스토리지
- powercli
- 차집합
- exadata
- oracle
- vmware
- sysprep
- powershell
- fromkeys
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
글 보관함