吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 2619|回复: 24
收起左侧

[Python 原创] 文本加密解密工具,可自定义秘钥,附带源码

  [复制链接]
motuisuo 发表于 2023-3-2 08:44

下面附源码
[Asm] 纯文本查看 复制代码

from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QLineEdit, QTextEdit, QPushButton, QVBoxLayout, QHBoxLayout, QMessageBox from Crypto.Cipher import AES from Crypto.Util.Padding import pad, unpad import base64

class TextEncrypter(QWidget): def init(self): super().init() self.initUI() self.key = b'1234567890123456' self.iv = b'abcdefghijklmnop'

def initUI(self):
    self.resize(400, 300)
    self.setWindowTitle('文本加密or解密工具')

    self.input_label = QLabel('请输入要加密or解密的文本:')
    self.input_text = QTextEdit()
    self.key_label = QLabel('请输入秘钥:')
    self.key_input = QLineEdit()
    self.encrypt_button = QPushButton('加密')
    self.decrypt_button = QPushButton('解密')
    self.output_label = QLabel('加密or解密后的文本:')
    self.output_text = QTextEdit()
    self.output_text.setReadOnly(True)

    input_layout = QVBoxLayout()
    input_layout.addWidget(self.input_label)
    input_layout.addWidget(self.input_text)

    key_layout = QHBoxLayout()
    key_layout.addWidget(self.key_label)
    key_layout.addWidget(self.key_input)

    button_layout = QHBoxLayout()
    button_layout.addWidget(self.encrypt_button)
    button_layout.addWidget(self.decrypt_button)

    output_layout = QVBoxLayout()
    output_layout.addWidget(self.output_label)
    output_layout.addWidget(self.output_text)

    main_layout = QVBoxLayout()
    main_layout.addLayout(input_layout)
    main_layout.addLayout(key_layout)
    main_layout.addLayout(button_layout)
    main_layout.addLayout(output_layout)
    self.setLayout(main_layout)

    self.encrypt_button.clicked.connect(self.encrypt_text)
    self.decrypt_button.clicked.connect(self.decrypt_text)

def encrypt_text(self):
    text = self.input_text.toPlainText()
    key_text = self.key_input.text()
    self.key = self.handle_key(key_text)
    cipher = AES.new(self.key, AES.MODE_CBC, self.iv)
    ciphertext = cipher.encrypt(pad(text.encode('utf-8'), AES.block_size))
    encrypted_text = base64.b64encode(ciphertext).decode('utf-8')
    self.output_text.setPlainText(encrypted_text)

def decrypt_text(self):
    text = self.input_text.toPlainText()
    key_text = self.key_input.text()
    self.key = self.handle_key(key_text)
    try:
        ciphertext = base64.b64decode(text.encode('utf-8'))
        cipher = AES.new(self.key, AES.MODE_CBC, self.iv)
        decrypted_text = unpad(cipher.decrypt(ciphertext), AES.block_size).decode('utf-8')
        self.output_text.setPlainText(decrypted_text)
    except ValueError:
        QMessageBox.warning(self, '错误', '解密失败,请检查输入的文本及秘钥是否正确!')

def handle_key(self, key_text):
    key = key_text.encode('utf-8')
    if len(key) > 16:
        key = key[:16]
    elif len(key) < 16:
        key = key.ljust(16, b'0')
    return key

if name == 'main': app = QApplication([]) window = TextEncrypter() window.show() app.exec_()

if name == 'main': app = QApplication([]) window = TextEncrypter() window.show() app.exec_()

Quicker_20230302_084349.png

免费评分

参与人数 3吾爱币 +2 热心值 +2 收起 理由
Rick_Nikita + 1 + 1 谢谢@Thanks!
saint80 + 1 谢谢@Thanks!
zshuim + 1 <font style="vertical-align: inherit;"><font style=

查看全部评分

本帖被以下淘专辑推荐:

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

mine4ever001 发表于 2023-3-2 12:03
学一学吧
ycyanwen 发表于 2023-3-2 12:08
dell2000 发表于 2023-3-2 12:58
netpeng 发表于 2023-3-2 13:13
没有成品的分享链接吗?
ArthurXDDD 发表于 2023-3-2 20:03
见过一个跑字典破wifi的 思路有点相似
weihongli 发表于 2023-3-3 09:02
谢谢了很有帮助!
ljwwwcr 发表于 2023-3-3 21:34
感谢大佬分享,十分有用
DLYR3021 发表于 2023-3-11 16:57
麻烦分享一下成品链接吗谢谢
baiyunyun 发表于 2023-3-12 09:57
谢谢楼主分享
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-29 10:38

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表