Document the project structure and setup while excluding local dependencies and IDE settings. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
26 lines
771 B
Python
26 lines
771 B
Python
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)))
|