Initialize encryption and JavaScript reverse-engineering study repository
Document the project structure and setup while excluding local dependencies and IDE settings. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
25
对称加密-2026-08-21/2. python实现des加解密.py
Normal file
25
对称加密-2026-08-21/2. python实现des加解密.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import base64
|
||||
from Crypto.Cipher import DES
|
||||
from Crypto.Util.Padding import pad, unpad
|
||||
|
||||
|
||||
def des_encrypt(plain_text):
|
||||
cipher = DES.new(des_key, DES.MODE_CBC, iv)
|
||||
encrypted = cipher.encrypt(pad(plain_text.encode("utf-8"), DES.block_size))
|
||||
return base64.b64encode(encrypted)
|
||||
|
||||
|
||||
def des_decrypt(cipher_text):
|
||||
cipher = DES.new(des_key, DES.MODE_CBC, iv)
|
||||
decrypt_byte_data = base64.b64decode(cipher_text)
|
||||
decrypted = unpad(cipher.decrypt(decrypt_byte_data), DES.block_size)
|
||||
return decrypted.decode("utf-8")
|
||||
|
||||
|
||||
source_data = "你好,世界!"
|
||||
des_key = "12345678".encode("utf-8")
|
||||
iv = "12345678".encode("utf-8")
|
||||
if __name__ == "__main__":
|
||||
enc_data = des_encrypt(source_data)
|
||||
print(enc_data)
|
||||
print(des_decrypt(des_encrypt(source_data)))
|
||||
Reference in New Issue
Block a user