From ec096034ca733251f5574996c8ed5fd11516a793 Mon Sep 17 00:00:00 2001 From: sangge <2251250136@qq.com> Date: Sun, 3 Sep 2023 20:01:42 +0800 Subject: [PATCH] =?UTF-8?q?easy=5Fmorse=E7=9A=84=E9=A2=98=E7=9B=AE?= =?UTF-8?q?=E5=8F=8A=E9=99=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crypto/easy_morse/cipher.txt | 1 + crypto/easy_morse/easy_morse.py | 23 +++++++++++++++++++++++ crypto/easy_morse/flag.txt | 1 + 3 files changed, 25 insertions(+) create mode 100644 crypto/easy_morse/cipher.txt create mode 100644 crypto/easy_morse/easy_morse.py create mode 100644 crypto/easy_morse/flag.txt diff --git a/crypto/easy_morse/cipher.txt b/crypto/easy_morse/cipher.txt new file mode 100644 index 0000000..dfec39a --- /dev/null +++ b/crypto/easy_morse/cipher.txt @@ -0,0 +1 @@ +./.-/...../-.--/.----/--/-----/.-./....././.----/-.-./-----/-.././ \ No newline at end of file diff --git a/crypto/easy_morse/easy_morse.py b/crypto/easy_morse/easy_morse.py new file mode 100644 index 0000000..8a379a7 --- /dev/null +++ b/crypto/easy_morse/easy_morse.py @@ -0,0 +1,23 @@ +# 莫斯电码映射 +MORSE_CODE_DICT = { + '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': '--..', + + '0': '-----', '1': '.----', '2': '..---', '3': '...--', '4': '....-', '5': '.....', + '6': '-....', '7': '--...', '8': '---..', '9': '----.', +} + +def text_to_morse(text): + morse = '' + for char in text.upper(): + morse += MORSE_CODE_DICT.get(char, '') + '/' # 如果字符不在字典中,就跳过 + return morse + +# 读取文件并进行莫斯编码 +with open('flag.txt', 'r') as file: + content = file.read() + morse_code = text_to_morse(content) + +with open('cipher.txt', 'w') as f: + f.write(morse_code) diff --git a/crypto/easy_morse/flag.txt b/crypto/easy_morse/flag.txt new file mode 100644 index 0000000..c8e774a --- /dev/null +++ b/crypto/easy_morse/flag.txt @@ -0,0 +1 @@ +EA5Y1M0R5E1C0DE \ No newline at end of file