当前位置: 首页 > news >正文

埃特巴什码加解密小程序

埃特巴什码加解密小程序

这几天在看CTF相关的课程,涉及到古典密码学和近代密码学还有现代密码学。

简单替换密码

Atbash Cipher

埃特巴什码(Atbash Cipher)其实可以视为下面要介绍的简单替换密码的特例,它使用字母表中的最后 一个字母代表第一个字母,倒数第二个字母代表第二个字母。在罗马字母表中,它是这样出现的:

ABCDEFGHIJKLMNOPQRSTUVWXYZ 明码表 
ZYXWVUTSRQPONMLKJIHGFEDCBA 密码表

比如埃 码

明文:the quick brown fox jumps over the lazy dog 
密文:gsv jfrxp yildm ulc qfnkh levi gsv ozab wlt

按照上面的规则,我编了一个小工具。源码如下:

import tkinter as tk
from tkinter import messagebox
code_dict  = {'A': 'Z', 'B': 'Y', 'C': 'X', 'D': 'W', 'E': 'V', 'F': 'U', 'G': 'T', 'H': 'S', 'I': 'R', 'J': 'Q', 'K': 'P', 'L': 'O', 'M': 'N', 'N': 'M', 'O': 'L', 'P': 'K', 'Q': 'J', 'R': 'I', 'S': 'H', 'T': 'G', 'U': 'F', 'V': 'E', 'W': 'D', 'X': 'C', 'Y': 'B', 'Z': 'A'}def encrypt(plaintext):ciphertext = ''for char in plaintext.upper():if char.isalpha():ciphertext += code_dict.get(char, '')else:ciphertext += charreturn ciphertextdef decrypt(ciphertext):plaintext = ''for char in ciphertext.upper():if char.isalpha():for k, v in code_dict.items():if char == v:plaintext += kelse:plaintext += charreturn plaintextclass CaesarCipherGUI:def __init__(self, master):self.master = mastermaster.title("埃特巴什码加解密--微信号强壮Python")# Create a frame to hold the input and output fieldsself.frame = tk.Frame(master)self.frame.pack(fill=tk.BOTH, expand=1)# Create the input fieldself.input_label = tk.Label(self.frame, text="输入信息", anchor='w', justify='left')self.input_label.pack()self.input_entry = tk.Entry(self.frame, width=40, justify='left')self.input_entry.pack()# Create the buttonsself.button_frame = tk.Frame(self.frame)self.button_frame.pack(fill=tk.X)self.encrypt_button = tk.Button(self.button_frame, text="加 密", command=self.encrypt_message)self.encrypt_button.pack(side='left', padx=5)self.decrypt_button = tk.Button(self.button_frame, text="解 密", command=self.decrypt_message)self.decrypt_button.pack(side='left', padx=25)# Create the output fieldself.output_label = tk.Label(self.frame, text="输 出", anchor='w')self.output_label.pack()self.output_text = tk.Text(self.frame, width=52, height=10, wrap='word')self.output_text.pack()def encrypt_message(self):plaintext = self.input_entry.get()ciphertext = encrypt(plaintext).lower()self.output_text.delete('1.0', tk.END)self.output_text.insert('1.0', ciphertext)def decrypt_message(self):ciphertext = self.input_entry.get()plaintext = decrypt(ciphertext).lower()self.output_text.delete('1.0', tk.END)self.output_text.insert('1.0', plaintext)root = tk.Tk()
my_gui = CaesarCipherGUI(root)
root.mainloop()

备注:界面是用AI生成,稍加修改。

运行结果如下图:

Screenshot 2024-06-25 at 22.24.10

http://www.lryc.cn/news/383239.html

相关文章:

  • Golang笔记:使用serial包进行串口通讯
  • EasyExcel 导出批注信息
  • HttpServletRequest・getContentLeng・getContentType区别
  • Matlab|【防骗帖】考虑时空相关性的风电功率预测误差建模与分析
  • 【Android面试八股文】说一说ListView卡顿的原因以及相对应的优化策略
  • Kotlin 中的内联函数
  • KALI LINUX 开启ssh免登录服务及固定ip及
  • 亮数据,一款新的低代码爬虫利器!
  • 配置OSPF认证(华为)
  • 关于ip地址的网页无法访问navigator的gpu、媒体、蓝牙等设备的解决方法
  • 深入理解外观模式(Facade Pattern)及其实际应用
  • 为什么永远不会有语言取代 C/C++?
  • Python 全栈体系【四阶】(六十一)
  • 工控必备C#
  • 【设计模式之基于特性的动态路由映射模式】
  • GB 16807-2009 防火膨胀密封件
  • 从零开始做题:老照片中的密码
  • 考研数学|张宇和武忠祥,强化能不能同时跟?
  • 【机器学习】——【线性回归模型】——详细【学习路线】
  • 【mysql】常用操作:维护用户/开启远程/忘记密码/常用命令
  • 引领AI新时代:深度学习与大模型的关键技术
  • STL——常用算法(二)
  • MyCAT 2 底层原理
  • 操作系统实训复习笔记(第7关:生产者消费者问题实践)
  • 通过物联网管理多台MQTT设备-基于全志T527开发板
  • Python学习前简介
  • 【Text2SQL 论文】MAGIC:为 Text2SQL 任务自动生成 self-correction guideline
  • 2024 年 8 款最佳建筑 3D 渲染软件
  • MAB规范(3):Chapter6 Glossary 术语表
  • 40python数据分析numpy基础之diag处理矩阵对角线元素