CTF
  • Introduction
  • IDF 实验室
    • 牛刀小试
      • 被改错的密码
      • ASCII 码而已
      • 聪明的小羊
      • 摩斯密码
      • 啥?
    • CRYPTO 百密一疏
      • 笨笨的小猪
      • 凯撒加密
      • 孔子的学费
      • 特殊的日子
      • 伟人的名字
    • WEB天罗地网
      • COOKIE欺骗
      • 不难不易的js加密
      • 超简单的js题
      • 古老的邮件编码
      • 简单的js解密
      • 你关注最新的漏洞吗
      • 一种编码而已
    • STEGA万里寻踪
      • 图片里的秘密
      • 上帝也哭泣
      • 红与黑
    • PPC初探乾坤
      • 简单编程-字符统计
      • Fuck your brain
      • 谁是卧底
    • REVERSE倒行逆施
      • 简单的PE文件逆向
      • 简单的ELF逆向
      • python ByteCode
    • MISC包罗万象
      • 图片里的英语
      • 抓到一只苍蝇
  • 实验吧
    • WEB
      • 登陆一下好吗??
      • 注入
      • 简单的sql注入
      • Forms
Powered by GitBook
On this page
  • 题目描述
  • write up

Was this helpful?

  1. IDF 实验室
  2. 牛刀小试

摩斯密码

题目描述

嘀嗒嘀嗒嘀嗒嘀嗒 时针它不停在转动

-- --- .-. ... .

嘀嗒嘀嗒嘀嗒嘀嗒 小雨它拍打着水花

-.-. --- -.. .

PS:答案格式wctf{你所知道的}

write up

自己写个摩斯解码的就行了, 代码如下, 最终结果为 测试解码: MORSECODE:

from collections import ChainMap

__author__ = '__L1n__w@tch'


class Morse:
    """
    摩尔斯电码的类, 包括了映射表, 编码函数与解码函数
    """
    upper_letters_map = {
        "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": "--.."}

    digits_map = {
        "0": "-----", "1": ".----", "2": "..---", "3": "...--",
        "4": "....-", "5": ".....", "6": "-....", "7": "--...",
        "8": "---..", "9": "----."
    }

    symbols_map = {
        ".": ".-.-.-", ":": "---...", ",": "--..--", ";": "-.-.-.",
        "?": "..--..", "=": "-...-", "'": ".----.", "/": "-..-.",
        "!": "-.-.--", "-": "-....-", "_": "..--.-", "\"": ".-..-.",
        "(": "-.--.", ")": "-.--.-", "$": "...-..-", "@": ".--.-."
        # 这个与 H 重复了: "&": "...."
    }

    # 合并多个字典, 这样不会产生新的字典, 而且这样的字典会随原字典的改变而改变
    all_map = ChainMap(upper_letters_map, digits_map, symbols_map)

    @staticmethod
    def reverse_map(a_map):
        """
        把映射表转换一下, 比如说原来映射关系是 "A":".-", 转换后变成 ".-":"A"
        :param a_map: {"A": ".-", "B": "-..."}
        :return: {".-": "A", "-...": "B"}
        """
        return dict(zip(a_map.values(), a_map.keys()))

    @staticmethod
    def decode_morse(cipher_text):
        """
        对摩尔斯电码进行解码操作
        :param cipher_text: "-- --- .-. ... . 你好"
        :return: "MORSE你好"
        """
        groups = cipher_text.split(" ")
        all_map = Morse.reverse_map(Morse.all_map)
        morse_decoded = str()
        for each in groups:
            try:
                morse_decoded += all_map[each]
            except KeyError:
                morse_decoded += each

        return morse_decoded

    @staticmethod
    def encode_morse(plain_text):
        """
        对明文进行摩尔斯电码编码操作
        :param plain_text: "你好12345678"
        :return: "你好.---- ..--- ...-- ....- ..... -.... --... ---.."
        """
        morse_encoded = str()
        for char in plain_text.upper():
            try:
                morse_encoded += Morse.all_map[char] + " "
            except KeyError:
                morse_encoded += char
        return morse_encoded[:-1]


if __name__ == "__main__":
    print("测试解码: {}".format(Morse.decode_morse("--  ---  .-.  ...  . -.-.  ---  -..  .")))
Previous聪明的小羊Next啥?

Last updated 5 years ago

Was this helpful?