OxypherText Python GUI
👤 Sharing: AI
import tkinter as tk
from tkinter import ttk
import random
import string
import pyperclip
def caesar_cipher(text, shift):
result = ''
for char in text:
if char.isalpha():
start = ord('a') if char.islower() else ord('A')
shifted_char = chr((ord(char) - start + shift) % 26 + start)
elif char.isdigit():
shifted_char = str((int(char) + shift) % 10)
else:
shifted_char = char
result += shifted_char
return result
def encrypt_text():
try:
text = input_text.get('1.0', tk.END).strip()
shift = int(shift_entry.get())
encrypted_text = caesar_cipher(text, shift)
output_text.delete('1.0', tk.END)
output_text.insert(tk.END, encrypted_text)
except ValueError:
output_text.delete('1.0', tk.END)
output_text.insert(tk.END, "Invalid shift value. Please enter an integer.")
def decrypt_text():
try:
text = input_text.get('1.0', tk.END).strip()
shift = int(shift_entry.get())
decrypted_text = caesar_cipher(text, -shift)
output_text.delete('1.0', tk.END)
output_text.insert(tk.END, decrypted_text)
except ValueError:
output_text.delete('1.0', tk.END)
output_text.insert(tk.END, "Invalid shift value. Please enter an integer.")
def copy_to_clipboard():
text_to_copy = output_text.get('1.0', tk.END).strip()
pyperclip.copy(text_to_copy)
def show_details():
details_window = tk.Toplevel(root)
details_window.title("Program Details")
details_text = tk.Text(details_window, wrap=tk.WORD, height=15, width=60)
details_text.pack(padx=10, pady=10)
details_text.insert(tk.END, "OxypherText is a versatile text encryption/decryption tool using the Caesar cipher. It allows users to encrypt and decrypt text by shifting characters based on a user-defined key. \n\nKey Features:\n- Caesar Cipher Encryption/Decryption: Encrypts and decrypts text using the Caesar cipher, which shifts each character by a specified number of positions down the alphabet.\n- User-Friendly Interface: Simple and intuitive GUI for easy text input, shift value adjustment, and output display.\n- Real-Time Encryption/Decryption: Provides instant encryption and decryption feedback as the user interacts with the application.\n- Copy to Clipboard: Allows users to quickly copy the encrypted or decrypted text to the clipboard for easy sharing or storage.\n- Error Handling: Implements error handling to gracefully manage invalid input, such as non-integer shift values.\n\nThis program is designed for those who need a basic yet effective way to secure their text messages or data, especially in environments where complex encryption methods are not required.")
details_text.config(state=tk.DISABLED) # Make it read-only
root = tk.Tk()
root.title("OxypherText")
mainframe = ttk.Frame(root, padding="12 12 12 12")
mainframe.grid(column=0, row=0, sticky=(tk.N, tk.W, tk.E, tk.S))
root.columnconfigure(0, weight=1)
root.rowconfigure(0, weight=1)
input_label = ttk.Label(mainframe, text="Enter Text:")
input_label.grid(column=1, row=1, sticky=tk.W)
input_text = tk.Text(mainframe, width=40, height=5)
input_text.grid(column=1, row=2, columnspan=2, sticky=(tk.W, tk.E))
shift_label = ttk.Label(mainframe, text="Shift Value:")
shift_label.grid(column=1, row=3, sticky=tk.W)
shift_entry = ttk.Entry(mainframe, width=10)
shift_entry.grid(column=2, row=3, sticky=(tk.W, tk.E))
shift_entry.insert(0, "3") # Default shift value
encrypt_button = ttk.Button(mainframe, text="Encrypt", command=encrypt_text)
encrypt_button.grid(column=1, row=4, sticky=tk.W)
decrypt_button = ttk.Button(mainframe, text="Decrypt", command=decrypt_text)
decrypt_button.grid(column=2, row=4, sticky=tk.E)
output_label = ttk.Label(mainframe, text="Result:")
output_label.grid(column=1, row=5, sticky=tk.W)
output_text = tk.Text(mainframe, width=40, height=5)
output_text.grid(column=1, row=6, columnspan=2, sticky=(tk.W, tk.E))
copy_button = ttk.Button(mainframe, text="Copy to Clipboard", command=copy_to_clipboard)
copy_button.grid(column=1, row=7, columnspan=2, sticky=tk.S)
# Details Button
details_button = ttk.Button(mainframe, text="Details", command=show_details)
details_button.grid(column=1, row=8, columnspan=2, sticky=tk.S)
for child in mainframe.winfo_children():
child.grid_configure(padx=5, pady=5)
root.mainloop()
👁️ Viewed: 7
Comments