Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- from tkinter import scrolledtext
- from Crypto.Cipher import AES
- from Crypto.Util.Padding import pad, unpad
- # Custom Base58 character set (Bitcoin Base58 alphabet)
- BASE58_ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
- def base58_encode(data):
- """Encodes bytes to Base58."""
- num = int.from_bytes(data, "big")
- if num == 0:
- return BASE58_ALPHABET[0]
- encoded = []
- base = len(BASE58_ALPHABET)
- while num:
- num, rem = divmod(num, base)
- encoded.append(BASE58_ALPHABET[rem])
- return ''.join(reversed(encoded))
- def base58_decode(data):
- """Decodes Base58 string to bytes."""
- base = len(BASE58_ALPHABET)
- num = 0
- for char in data:
- num = num * base + BASE58_ALPHABET.index(char)
- return num.to_bytes((num.bit_length() + 7) // 8, 'big') or b'\0'
- def encrypt():
- # Get the input text
- input_text = input_text_box.get("1.0", tk.END).strip()
- # Define the predefined key and IV as bytes
- key = bytes.fromhex("0000000000000000000000000000000000000000000000000000000000000000") # 32 bytes for AES-256
- iv = bytes.fromhex("00000000000000000000000000000000") # 16 bytes for 128-bit IV
- # Create AES cipher in CBC mode with AES-256
- cipher = AES.new(key, AES.MODE_CBC, iv)
- # Encrypt the input text, ensuring it's padded to the block size
- encrypted_bytes = cipher.encrypt(pad(input_text.encode(), AES.block_size))
- # Convert encrypted bytes to Base58
- encrypted_base58 = base58_encode(encrypted_bytes)
- # Display the result
- output_text_box.delete("1.0", tk.END)
- output_text_box.insert(tk.END, encrypted_base58)
- def decrypt():
- # Get the encrypted Base58 text
- encrypted_base58 = input_text_box.get("1.0", tk.END).strip()
- # Define the predefined key and IV as bytes
- key = bytes.fromhex("0000000000000000000000000000000000000000000000000000000000000000") # 32 bytes for AES-256
- iv = bytes.fromhex("00000000000000000000000000000000") # 16 bytes for 128-bit IV
- # Decode Base58 to get the encrypted bytes
- encrypted_bytes = base58_decode(encrypted_base58)
- # Create AES cipher in CBC mode with AES-256
- cipher = AES.new(key, AES.MODE_CBC, iv)
- # Decrypt the text and remove padding
- decrypted_bytes = unpad(cipher.decrypt(encrypted_bytes), AES.block_size)
- # Convert decrypted bytes to a string
- decrypted_text = decrypted_bytes.decode("utf-8")
- # Display the result
- output_text_box.delete("1.0", tk.END)
- output_text_box.insert(tk.END, decrypted_text)
- # Create the main window
- window = tk.Tk()
- window.title("AES-256 Encryption/Decryption Tool with Predefined Key and IV (Base58)")
- # Create input text box for plain text or encrypted Base58
- input_label = tk.Label(window, text="Input Text (or Encrypted Base58):")
- input_label.pack()
- input_text_box = scrolledtext.ScrolledText(window, width=50, height=10)
- input_text_box.pack()
- # Create Encrypt button
- encrypt_button = tk.Button(window, text="Encrypt", command=encrypt)
- encrypt_button.pack()
- # Create Decrypt button
- decrypt_button = tk.Button(window, text="Decrypt", command=decrypt)
- decrypt_button.pack()
- # Create output text box for result
- output_label = tk.Label(window, text="Output Text:")
- output_label.pack()
- output_text_box = scrolledtext.ScrolledText(window, width=50, height=10)
- output_text_box.pack()
- # Start the Tkinter event loop
- window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement