派森(西南科大) #C.摩斯密码解密

morse = [".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."]
digit = ['-----', '.----', '..---', '...--', '....-', '.....', '-....', '--...', '---..', '----.']
punctuation = {'.': '.-.-.-', ':': '---...', ',': '--..--', ';': '-.-.-.', '?': '..- -..', '=': '-...-', "'": '.----.', '/': '-..-.', '!': '-.-.--', '-': '-....-', '_': '..--.-', '"': '.-..-.', '(': '-.--.', ')': '-.--.-', '$': '...-..-', '&': '·-···', '@': '.--.-.', ' ': ''}
re_punctuation = dict(zip(punctuation.values(), punctuation.keys()))  #键值对翻转
txt = input().split(' ')
for ch in txt:
    if ch in morse:
        new_ch = chr(morse.index(ch) + ord('a'))
        print(new_ch, end='')
    elif ch in digit:
        new_ch = chr(digit.index(ch) + ord('0'))
        print(new_ch, end='')
    elif ch in re_punctuation.keys():
        new_ch = re_punctuation[ch]
        print(new_ch, end='')
    else:
        print(ch, end='')

#与加密相比,会用到index函数取下标,都借用了ASCII进行转换字符
#该解密还有缺点:解密后的字母都是小写,问题不大

清晰,易懂

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
好的,以下是一个简单的微信机器人派森框架的代码示例,你可以根据需要进行修改和优化: ```python import itchat from threading import Thread from queue import Queue class WechatBot: def __init__(self): self.msg_queue = Queue() self.bot = itchat.new_instance() self.bot.auto_login(hotReload=True) self.bot.run(blockThread=False) self.friend_list = self.bot.get_friends() def send_msg(self, msg, to_user): self.bot.send(msg, toUserName=to_user) def handle_msg(self, msg): from_user = msg['FromUserName'] msg_type = msg['Type'] if msg_type == 'Text': content = msg['Text'] self.msg_queue.put((from_user, content)) def listen(self): @self.bot.msg_register(['Text', 'Picture', 'Recording', 'Attachment', 'Video']) def receive_msg(msg): self.handle_msg(msg) def run(self): listen_thread = Thread(target=self.listen) listen_thread.start() while True: if not self.msg_queue.empty(): from_user, content = self.msg_queue.get() # 处理消息并回复 reply = self.reply(content, from_user) self.send_msg(reply, from_user) def reply(self, msg, from_user): # 实现具体的自动回复逻辑 return "这是机器人自动回复的消息。" if __name__ == '__main__': bot = WechatBot() bot.run() ``` 以上代码实现了一个基本的微信机器人框架,它能够监听用户发送的消息并将其加入消息队列,然后在主线程中不断从消息队列中读取消息并进行处理和回复。你可以根据需要修改 `reply` 函数来实现具体的自动回复逻辑。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值