CTF

[써니나타스_암호학] Basic_Crypto1

코딩 못하는 공대생 2024. 1. 16. 13:20
728x90

문제 : https://dreamhack.io/wargame/challenges/517

 

Basic_Crypto1

This Problem Basic_Crpyto(Roman emperor's cipher) FLAG FORMAT(A~Z) and empty is "_" DH{decode_Text}

dreamhack.io


문제 설명

This Problem Basic_Crpyto(Roman emperor’s cipher)

FLAG FORMAT(A~Z) and empty is “_”

DH{decode_Text}


문제 해결

Roman emperor's cipher

= 카이사르 암호 or 시저 암호

= 치환암호

= 암호화하고자 하는 내용을 알파벳별로 일정한 거리만큼 이동시켜 다른 알파벳으로 치환

 

c = E(k,p) = (p+k) mod 26
p = D(k,c) = (c-k) mod 26
( c = 암호문, p = 평문, k = 키 값, E = 암호화 함수, D = 복호화 함수)

 

풀이 1) 파이썬을 통한 방법

def decrypt_caesar_cipher(ciphertext, shift):
    decrypted_text = ""

    for char in ciphertext:
        # 알파벳인 경우만 해독 진행
        if char.isalpha():
            # 대문자인 경우
            if char.isupper():
                decrypted_char = chr((ord(char) - shift - ord('A')) % 26 + ord('A'))
            # 소문자인 경우
            else:
                decrypted_char = chr((ord(char) - shift - ord('a')) % 26 + ord('a'))
        else:
            decrypted_char = char

        decrypted_text += decrypted_char

    return decrypted_text

# 암호화된 문자열과 시프트 값을 입력하세요
ciphertext = input("암호화된 문자열을 입력하세요: ")
shift = int(input("사용된 시프트 값을 입력하세요: "))

# 시저 암호 해독
decrypted_text = decrypt_caesar_cipher(ciphertext, shift)

# 결과 출력
print("해독된 문자열:", decrypted_text)

 

풀이 2) 복호화 사이트 이용

링크 : https://jo-gunhee.github.io/website1/dcode/dcodewebsite.html

 

카이사르 암호 암호화/복호화

ex) I love cookie I love cookie START -------------

jo-gunhee.github.io

728x90