Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shift from Console-Based to GUI-Based Application #1

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 32 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,48 @@
# Caesar Cipher :lock::key:
# Caesar Cipher with GUI :lock::key:

This project implements a simple Caesar Cipher for encoding and decoding messages. The Caesar Cipher is a type of substitution cipher in which each letter in the plaintext is shifted a certain number of places down or up the alphabet.
This is a graphical user interface (GUI) application for encoding and decoding text using the Caesar Cipher technique. The application is built using Python and the Tkinter library, with additional dependencies on the art and Pillow libraries.

## Features

- Encrypts text by shifting letters by a given number.
- Decrypts text by reversing the shift.
- **Encrypt Text:** Encode your message using a shift value.
- **Decrypt Text:** Decode your encrypted message using the same shift value.
- **Dynamic Alphabet Extension:** Automatically extends the alphabet if certain letters are present in the text.

## Usage
- **Direction**: Type `encode` to encrypt or `decode` to decrypt.
- **Message**: The text you want to encode or decode.
- **Shift Number**: The number of positions by which you want to shift the letters.

## Example
1. Run the application:
```sh
Type 'encode' to encrypt, type 'decode' to decrypt:
encode
Type your message:
hello
Type the shift number:
5
The encoded text is mjqqt

Type 'yes' to want to go again, type 'no' to want to quit.
no
Thanks for using Caesar Cipher!
python encrypt-decrypt.py
```
2. Using the GUI:
- **Type your message:** Enter the text you want to encrypt or decrypt in the provided input field.
- **Type the shift number:** Enter the numerical shift value for the Caesar Cipher.
- **Encrypt or Decrypt:** Click the "ENCRYPT" button to encode the message or the "DECRYPT" button to decode the message.
- The result will be displayed in the text area below the buttons.

## Installation

Clone the repository to your local machine:
  ![](https://github.com/emrenos/encrypt-decrypt/blob/main/crpyt-gif.gif)

## Installation
1. Clone the repository:
```sh
git clone https://github.com/emrenos/encrypt-decrypt.git
cd encrypt-decrypt
```
2. Install the required libraries:
```sh
pip install Pillow
```
3. Ensure Tkinter is installed:
Tkinter is usually included with Python, but if you need to install it manually, you can do so with your package manager. For example:
-   **On Ubuntu:**
```sh
sudo apt-get install python3-tk
```
-   **On macOS with Homebrew:**
```sh
git clone https://github.com/yourusername/caesar-cipher.git
cd caesar-cipher
brew install python-tk
```

## Upcoming Updates
1. **GUI Integration**: The next update will introduce an interface that allows users to perform encryption and decryption operations via GUI instead of terminal.
1. **GUI Integration** :white_check_mark:
2. **Advanced Encryption Method**: The encryption method will be upgraded from the Caesar Cipher to a more sophisticated algorithm to enhance security.

##
57 changes: 33 additions & 24 deletions README_tr.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,48 @@
# Caesar Cipher :lock::key:
Bu proje, mesajların kodlanması ve çözülmesi için basit bir Caesar Cipher metodunu uygular. Caesar Cipher, düz metindeki her harfin alfabede belirli sayıda aşağı veya yukarı kaydırıldığı bir tür yer değiştirme şifresidir.

Bu, Caesar Şifreleme tekniğini kullanarak metni kodlamak ve çözmek için bir grafiksel kullanıcı arayüzü (GUI) uygulamasıdır. Uygulama Python ve Tkinter kütüphanesi kullanılarak oluşturulmuştur ve ek olarak art ve Pillow kütüphanelerine bağımlıdır.

## Özellikler
- Harfleri belirli bir sayı kadar kaydırarak metni şifreler.
- Kaydırmayı tersine çevirerek metnin şifresini çözer.
- **Metni Şifrele:** Mesajınızı bir kaydırma değeri kullanarak kodlayın.
- **Metni Çöz:** Aynı kaydırma değerini kullanarak şifrelenmiş mesajınızı çözün.
- **Dinamik Alfabe Genişletme:** Metinde belirli harfler varsa otomatik olarak alfabeyi genişletir.

## Kullanım
- **Yön**: Şifrelemek için `encode` veya şifresini çözmek için `decode` yazın.
- **Mesaj**: Kodlamak veya kodunu çözmek istediğiniz metin.
- **Kaydırma Numarası**: Harfleri kaydırmak istediğiniz konum sayısı.

## Örnek Kullanım
1. Uygulamayı çalıştırın:
```sh
Type 'encode' to encrypt, type 'decode' to decrypt:
encode
Type your message:
hello
Type the shift number:
5
The encoded text is mjqqt

Type 'yes' to want to go again, type 'no' to want to quit.
no
Thanks for using Caesar Cipher!
python encrypt-decrypt.py
```
2. GUI Kullanımı:
- **Mesajınızı yazın:** Kodlamak veya çözmek istediğiniz metni sağlanan giriş alanına girin.
- **Kaydırma numarasını yazın:** Caesar Cipher için sayısal kaydırma değerini girin.
- **Encrypt ve Decrypt:** Mesajı kodlamak için "ENCRYPT" butonuna veya mesajı çözmek için "DECRYPT" butonuna tıklayın.
- Sonuç, butonların altındaki metin alanında görüntülenecektir.

  ![](https://github.com/emrenos/encrypt-decrypt/blob/main/crpyt-gif.gif)

## Kurulum
Repoyu yerel makinenize klonlayın:
1. Repoyu klonlayın:
```sh
git clone https://github.com/emrenos/encrypt-decrypt.git
cd encrypt-decrypt
```
2. Gerekli kütüphaneleri yükleyin:
```sh
pip install Pillow
```
3. Tkinter'in yüklü olduğundan emin olun:
Tkinter genellikle Python ile birlikte gelir, ancak manuel olarak yüklemeniz gerekirse, paket yöneticinizle bunu yapabilirsiniz. Örneğin:
-   **On Ubuntu:**
```sh
sudo apt-get install python3-tk
```
-   **On macOS with Homebrew:**
```sh
git clone https://github.com/yourusername/caesar-cipher.git
cd caesar-cipher
brew install python-tk
```

## Yapılacak Güncellemeler
1. **GUI Entegrasyonu**: Bir sonraki güncelleme, kullanıcıların şifreleme ve şifre çözme işlemlerini terminal yerine GUI üzerinden gerçekleştirmelerine olanak tanıyan bir arayüz sunacaktır.
## Gelecek Güncellemeler
1. **GUI Entegrasyonu** :white_check_mark:
2. **Gelişmiş Şifreleme Yöntemi**: Şifreleme yöntemi, güvenliği artırmak için Caesar Cipher metodundan daha üst bir algoritmaya yükseltilecektir.

##
130 changes: 99 additions & 31 deletions encrypt-decrypt.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,114 @@
import tkinter as tk
from art import logo
from PIL import Image, ImageTk
from a import alphabet

print(logo)

def extend_alphabet(text,shift):
last_letters = {'v','w','x','y','z'}
if any(letter in last_letters for letter in text):
def extend_alphabet(text, shift):
if any(letter in {'v', 'w', 'x', 'y', 'z'} for letter in text):
alphabet.extend(alphabet)

def encrypt(text, shift):
encrypted_text = ""
for letters in text:
if letters in alphabet:
position = alphabet.index(letters)+shift
encrypted_text += alphabet[position]
for letter in text:
if letter in alphabet:
position = alphabet.index(letter)
new_position = (position + shift) % len(alphabet)
encrypted_text += alphabet[new_position]
else:
encrypted_text += letters
print(f"The encoded text is {encrypted_text}")
encrypted_text += letter
return encrypted_text

def decrypt(text, shift):
decrypted_text = ""
for letters in text:
if letters in alphabet:
position = alphabet.index(letters)-shift
decrypted_text+=alphabet[position]
for letter in text:
if letter in alphabet:
position = alphabet.index(letter)
new_position = (position - shift) % len(alphabet)
decrypted_text += alphabet[new_position]
else:
decrypted_text+=letters
print(f"The decoded text is {decrypted_text}")
decrypted_text += letter
return decrypted_text

close_program = False
while not close_program:
direction = input("Type 'encode' to encrypt, type 'decode' to decrypt:\n")
text = input("Type your message:\n").lower()
shift = int(input("Type the shift number:\n"))
def on_encrypt():
text = input_text.get()
shift = int(shift_entry.get())
extend_alphabet(text, shift)
encrypted = encrypt(text, shift)
update_result_text(f"Encoded Text: {encrypted}")

def on_decrypt():
text = input_text.get()
shift = int(shift_entry.get())
extend_alphabet(text, shift)
if direction == "encode":
encrypt(text, shift)
elif direction == "decode":
decrypt(text, shift)

restart = input("Type 'yes' to want to go again, type 'no' to want to quit. \n").lower()
if restart == "no":
close_program= True
print("Thanks for using Caesar Cipher!")
decrypted = decrypt(text, shift)
update_result_text(f"Decoded Text: {decrypted}")

def update_result_text(message):
result_text.config(state=tk.NORMAL)
result_text.delete(1.0, tk.END)
result_text.insert(tk.END, message, "bold")
result_text.config(state=tk.DISABLED)

def validate_entry(action, value_if_allowed, text, prior_value, insertion_index, event_type, *args):
if action == '1' and not text.isdigit():
return False
return True

# GUI Setup
window = tk.Tk()
window.title("Caesar Cipher")
window.geometry("500x400")
window.resizable(False, False)

# Set window icon
icon_image = Image.open("caesar-cipher.png")
icon_photo = ImageTk.PhotoImage(icon_image)
window.iconphoto(False, icon_photo)

# Define custom fonts and colors
font_title = ("Helvetica", 12, "bold")
font_text = ("Helvetica", 10)
bg_color = "#1E1E1E"
fg_color = "#FFFFFF"
lg_color = "#A1BD2F"
lbl_color = "#D9D9D9"
en_btn_color = "#3E7EAC"

# Set background color for the window
window.configure(bg=bg_color)

# Display the logo
logo_label = tk.Label(window, text=logo, font=("Courier", 2), fg=lg_color, bg=bg_color)
logo_label.pack(pady=10)

# Input Text
input_label = tk.Label(window, text="Type your message:", font=font_text, bg=bg_color, fg=fg_color)
input_label.pack(pady=5)
input_text = tk.Entry(window, width=50, font=font_text, bg=lbl_color)
input_text.pack(pady=5)

# Shift Number
shift_label = tk.Label(window, text="Type the shift number:", font=font_text, bg=bg_color, fg=fg_color)
shift_label.pack(pady=5)

vcmd = (window.register(validate_entry), '%d', '%P', '%S', '%s', '%i', '%V')
shift_entry = tk.Entry(window, width=5, font=font_text, bg=lbl_color, validate='key', validatecommand=vcmd)
shift_entry.pack(pady=5)

# Result Text
result_text = tk.Text(window, height=5, width=50, font=font_text, bg=lbl_color)
result_text.pack(pady=20)
result_text.tag_configure("bold", font=("Helvetica", 10, "bold"))
result_text.config(state=tk.DISABLED)

# Encrypt and Decrypt Buttons
button_frame = tk.Frame(window, bg=bg_color)
button_frame.pack(pady=20)

encrypt_button = tk.Button(button_frame, text="ENCRYPT", command=on_encrypt, width=10, font=font_title, bg=en_btn_color, fg=bg_color)
encrypt_button.pack(side=tk.LEFT, padx=35)

decrypt_button = tk.Button(button_frame, text="DECRYPT", command=on_decrypt, width=10, font=font_title, bg=lg_color, fg=bg_color)
decrypt_button.pack(side=tk.RIGHT, padx=35)

window.mainloop()