@YatinBayya/

Encryption/Decryption

Tkinter

No description

fork
loading
Files
  • main.py
  • nohup.out
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#works only in IDLE
from tkinter import messagebox, simpledialog,Tk

def is_even(number):
  return number%2 == 0

def get_even_letters(message):
  even_letters = []
  for counter in range(0,len(message)):
    if is_even(counter):
      even_letters.append(message[counter])
  return even_letters

def get_odd_letters(message):
  odd_letters = []
  for counter in range(0,len(message)):
    if not is_even(counter):
      odd_letters.append(message[counter])
  return odd_letters

def swap_letters(message):
  letter_list = []
  if not is_even(len(message)):
    message = message + "$%^@"
  even_letters = get_even_letters(message)
  odd_letters = get_odd_letters(message)

  for counter in range(0,int(len(message)/2)):
    letter_list.append(odd_letters[counter])
    letter_list.append(even_letters[counter])

  new_message = ' '.join(letter_list)
  return new_message

def get_task():
  task= simpledialog.askstring("Task","Do you want to encrypt or decrypt? [E/D]")
  return task

def get_message():
  message = simpledialog.askstring("message","Enter your secret message.")
  return message

root = Tk()
while True:
  task = get_task()
  if task == "E":
    message = get_message()
    encrypted = swap_letters(message)
    messagebox.showinfo("D MESSAGE =", encrypted)
  elif task == "D":
    message = get_message()
    decrypted = swap_letters(message)
    messagebox.showinfo("D MESSAGE =", decrypted)
  else:
    break