diff --git a/Archive-Mains/converted_image.png b/Archive-Mains/converted_image.png deleted file mode 100644 index 43b88d9..0000000 Binary files a/Archive-Mains/converted_image.png and /dev/null differ diff --git a/Archive-Mains/main-1.0.py b/Archive-Mains/main-1.0.py deleted file mode 100644 index 8535b6f..0000000 --- a/Archive-Mains/main-1.0.py +++ /dev/null @@ -1,195 +0,0 @@ -from PIL import Image -from math import ceil -from Dicts import MORSE_DICT, ALPH_DICT -import os - -print(MORSE_DICT["A"]) - -class Func: - - def __init__(self,): - if os.path.exists("error.txt"): - os.remove("error.txt") - self.errortext = open('error.txt', 'a') - self.errortext.writelines("INITIATING\n") - - def output(self, string, mode): - string = str(string) - if mode == "T" or mode == "B": print(string) - self.errortext = open('error.txt', 'a') - if mode == "F" or mode == "B": self.errortext.writelines(string + "\n") -iof = Func() - -class Main: - - def __init__(self): - self.intro() - - def intro(self): - self.choice_loop() - - def choice_loop(self): - print("Choose operation:\nTitle: input\nConvert Image: convert\nRead Encrypted Image: read\nExit Program: exit\n") - match input(): - case "convert": - print("Welcome to the Shush Converter\nPlease enter the name of your image, including the extension") - self.path_img = "./input/" + input() - print("Please enter the name of text file, including the extension") - self.path_txt = "./input/" + input() - print("Current path is: " + self.path_img + " and: " + self.path_txt) - self.converter = Converter(self.path_img, self.path_txt) - self.converter.run() - case "read": - print("Welcome to the Shush Reader\nPlease enter the name of your image, including the extension") - self.path_img = "./input/" + input() - self.reader = Reader(self.path_img) - self.reader.run() - case "exit": - exit() - case _: - print("Invalid Input. Please make sure you spelled correctly, and used lower case letters thoughout.") - - - -class Converter: - - def run(self): - self.loadObjects() - self.convertFunction() - - def __init__(self, image_path, text_path): - self.img_path = image_path - self.txt_path = text_path - self.morse_text = "" - self.img = Image.open(self.img_path).convert("RGB") - - def loadObjects(self): - self.imagewidth, self.imageheight = self.img.size - with open(self.txt_path) as x: - self.raw_text = x.readlines() - iof.output(self.raw_text, "B") - for line in self.raw_text: - for letter in line: - self.morse_text += (MORSE_DICT[letter.upper()] + " ") - iof.output(self.morse_text, "B") - - def convertFunction(self): - incrementer,x,y = 0,0,0 - for letter in self.morse_text: - incrementer += 1 - if x < self.imagewidth - 1: - x += 1 - else: - y += 1 - x = 0 - match letter: - case ".": - self.img.putpixel((x,y), (0, 0, 0)) - case "-": - self.img.putpixel((x,y), (255, 255, 255)) - case " ": - continue - case "|": - continue - iof.output(str(incrementer/len(self.morse_text)*100) + "%", "F") - self.img.save("converted_image.png") - -class Reader: - def run(self): - self.loadObjects() - self.readFunction() - self.out = open('output/text.txt', 'a') - self.out.writelines(self.normal_text) - - def __init__(self, image_path): - self.img_path = image_path - self.normal_text = "" - self.morse_text = "" - - def loadObjects(self): - self.img = Image.open(self.img_path).convert("RGB") - self.imagewidth, self.imageheight = self.img.size - - def readFunction(self): - escaperange = 0 - ended = False - for y in range(self.imageheight): - for x in range(self.imagewidth): - if not ended == True: - iof.output(f"At pixel: {x},{y}\nWith color: {self.img.getpixel((x,y))}", "F") - - match self.img.getpixel((x,y)): - case (0,0,0): - iof.output("Found black", "B") - self.morse_text += "." - case (255,255,255): - iof.output("Found white", "B") - self.morse_text += "-" - case _: - if escaperange == 0: - ii = self.futurecheck(x,y) - if ii == 2: - escaperange = 2 - self.morse_text += " | " - elif ii == 1: - self.morse_text += " " - else: - ended = True - iof.output("Ended at: " + str(x) + "," + str(y), "B") - else: - escaperange -= 1 - iof.output(self.morse_text, "B") - sequence = "" - for letter in self.morse_text: - if letter != " ": - sequence += letter - else: - if letter == "|": - self.normal_text += " " - elif letter == " " and sequence != "": - self.normal_text += ALPH_DICT[sequence] - sequence = "" - iof.output(self.normal_text, "F") - - - def futurecheck(self,x,y): - endchecker = 0 - a = 0 - b = 0 - while a + b <= 10: - if x + a < self.imagewidth: - if self.img.getpixel((x + a, y)) != (0,0,0) and self.img.getpixel((x + a, y)) != (255,255,255): - endchecker += 1 - iof.output("Endchecker at: " + str(endchecker) + "\nUsing pixel: " + str(self.img.getpixel((x + a, y))) + "\nAt position: " + str(x+a) + "," + str(y), "F") - a += 1 - else: - a = 11 - else: - if self.img.getpixel((b, y + 1)) != (0,0,0) and self.img.getpixel((b, y + 1)) != (255,255,255): - endchecker += 1 - iof.output(f"Endchecker at: {str(endchecker)}\nUsing pixel: {str(self.img.getpixel((b, y + 1)))}\nAt position: {str(b)},{str(y+1)}", "F") - b += 1 - else: - b = 11 - - if endchecker > 9: - return 10 - if x + 2 <= self.imagewidth: - iof.output("Using one-line space checking method", "F") - if self.img.getpixel((x + 1, y)) != (0,0,0) and self.img.getpixel((x + 1, y)) != (255,255,255): - iof.output("Adding space", "F") - return 2 - else: - iof.output("Adding letter separation", "F") - return 1 - else: - if self.img.getpixel((0, y+1)) != (0,0,0) and self.img.getpixel((0, y+1)) != (255,255,255): - iof.output("Adding space", "F") - return 2 - else: - iof.output("Adding letter separation", "F") - return 1 - - -Starter = Main() -Starter.intro() \ No newline at end of file diff --git a/Main/Dicts.py b/Main/Dicts.py deleted file mode 100644 index c0646f0..0000000 --- a/Main/Dicts.py +++ /dev/null @@ -1,17 +0,0 @@ -MORSE_DICT = { 'A':'.-', 'B':'-...', - 'C':'-.-.', 'D':'-..', 'E':'.', - 'F':'..-.', 'G':'--.', 'H':'....', - 'I':'..', 'J':'.---', 'K':'-.-', - 'L':'.-..', 'M':'--', 'N':'-.', - 'O':'---', 'P':'.--.', 'Q':'--.-', - 'R':'.-.', 'S':'...', 'T':'-', - 'U':'..-', 'V':'...-', 'W':'.--', - 'X':'-..-', 'Y':'-.--', 'Z':'--..', - '1':'.----', '2':'..---', '3':'...--', - '4':'....-', '5':'.....', '6':'-....', - '7':'--...', '8':'---..', '9':'----.', - '0':'-----', ',':'--..--', '.':'.-.-.-', - '?':'..--..', '/':'-..-.', '-':'-....-', - '(':'-.--.', ')':'-.--.-', ' ': '|', - '\n': '.-.-.-.'} -ALPH_DICT = {v: k for k, v in MORSE_DICT.items()} \ No newline at end of file diff --git a/Main/input/hi_100.txt b/Main/input/hi_100.txt deleted file mode 100644 index c9ff991..0000000 --- a/Main/input/hi_100.txt +++ /dev/null @@ -1 +0,0 @@ -Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam sollicitudin fringilla sapien ac hendrerit. Suspendisse vitae velit eu dui facilisis malesuada et dignissim mi. Donec at ante eget libero convallis lacinia. Cras ut bibendum mauris. Nulla mattis, ante non tempor tempor, mauris elit volutpat ligula, a volutpat diam tortor quis diam. Nam condimentum sed felis at finibus. Donec id ligula pellentesque, dignissim turpis laoreet, egestas ante. Maecenas tempus vel lacus id finibus. Proin in felis lectus. Sed volutpat dictum purus a ullamcorper. Vestibulum sit amet purus facilisis, ullamcorper ex sit amet, suscipit massa. Pellentesque sed nibh sed lectus dignissim laoreet. \ No newline at end of file diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..ed05a3e --- /dev/null +++ b/README.txt @@ -0,0 +1,6 @@ +## This is the Shush Image - Text Encryption Tool + +## Given an image (jpg or png) and a text file (.txt) it can create a new image (png) which will contain the text of the .txt file inside of it. +## This process can then be reversed using the Decrypt function and a png image which has text encrypted into it. + +## Github: \ No newline at end of file diff --git a/Main/__pycache__/Dicts.cpython-312.pyc b/__pycache__/Dicts.cpython-312.pyc similarity index 100% rename from Main/__pycache__/Dicts.cpython-312.pyc rename to __pycache__/Dicts.cpython-312.pyc diff --git a/Main/main.py b/main.py similarity index 51% rename from Main/main.py rename to main.py index 3b06b46..57f6eed 100644 --- a/Main/main.py +++ b/main.py @@ -1,8 +1,43 @@ from PIL import Image -from dicts import MORSE_DICT, ALPH_DICT +import tkinter as tk +from tkinter import filedialog +from tkinter import ttk +import sv_ttk import os -print(MORSE_DICT["A"]) +MORSE_DICT = { 'A':'.-', 'B':'-...', + 'C':'-.-.', 'D':'-..', 'E':'.', + 'F':'..-.', 'G':'--.', 'H':'....', + 'I':'..', 'J':'.---', 'K':'-.-', + 'L':'.-..', 'M':'--', 'N':'-.', + 'O':'---', 'P':'.--.', 'Q':'--.-', + 'R':'.-.', 'S':'...', 'T':'-', + 'U':'..-', 'V':'...-', 'W':'.--', + 'X':'-..-', 'Y':'-.--', 'Z':'--..', + '1':'.----', '2':'..---', '3':'...--', + '4':'....-', '5':'.....', '6':'-....', + '7':'--...', '8':'---..', '9':'----.', + '0':'-----', ',':'--..--', '.':'.-.-.-', + '?':'..--..', '/':'-..-.', '-':'-....-', + '(':'-.--.', ')':'-.--.-', ' ': '|', + '\n': '.-.-.-.'} +ALPH_DICT = {v: k for k, v in MORSE_DICT.items()} + +#window +window = tk.Tk() +window.title('Shush') +window.geometry('700x400') +#window.configure(background='gray60') + +entryImg = tk.StringVar() +entryImg.set("Path/To/Image") +entryTxt = tk.StringVar() +entryTxt.set("Path/To/Text/file") + + +readImg = tk.StringVar() +readImg.set("Path/To/Image") +errorTxt = tk.StringVar() class Func: @@ -25,10 +60,11 @@ iof = Func() class Main: def __init__(self): - self.choice_loop() + #self.choice_loop() + self.something = 0 def choice_loop(self): - match input("Choose operation:\nTitle: input\nConvert Image: convert\nRead Encrypted Image: read\nExit Program: exit\n"): + match input("Choose operation:\n\"Title\": \"input\"\nConvert Image: convert\nRead Encrypted Image: read\nExit Program: exit\n"): case "convert": print("Welcome to the Shush Converter\nPlease enter the name of your image, including the extension") self.path_img = "./input/" + input() @@ -46,15 +82,36 @@ class Main: exit() case _: print("Invalid Input. Please make sure you spelled correctly, and used lower case letters thoughout.") -class Converter: - - def __init__(self, image_path, text_path): - self.img_path = image_path - self.txt_path = text_path + +class Converter: + def __init__(self): self.morse_text = "" - self.img = Image.open(self.img_path).convert("RGBA") + + def add_img_path(self): + image_path = filedialog.askopenfilename(initialdir="..", title="Select Your Image File") + if str(image_path.split(".")[1]) == "png" or str(image_path.split(".")[1]) == "jpg" or str(image_path.split(".")[1]) == "jpeg": + self.img_path = image_path + entryImg.set(str(image_path)) + if errorTxt.get() == "Error loading Image file path": + errorTxt.set("") + else: + errorTxt.set("Error loading Image file path") + + def add_text_path(self): + text_path = filedialog.askopenfilename(initialdir="..", title="Select Your Text File") + if str(text_path.split(".")[1]) == "txt": + self.txt_path = text_path + entryTxt.set(str(text_path)) + if errorTxt.get() == "Error loading Text file path": + errorTxt.set("") + else: + errorTxt.set("Error loading Text file path") + + def add_output_path(self): + woo = 0 def run(self): + self.img = Image.open(self.img_path).convert("RGBA") self.load_objects() self.convert_function() @@ -66,7 +123,6 @@ class Converter: for line in self.raw_text: self.morse_text += " ".join(MORSE_DICT[letter.upper()] for letter in line) + " " iof.output(self.morse_text, "B") - def convert_function(self): x, y = 0, 0 for incrementer, letter in enumerate(self.morse_text): @@ -87,21 +143,36 @@ class Converter: continue iof.output(f"{self.img.getpixel((x,y))}", "F") iof.output(f"{incrementer/len(self.morse_text)*100}%", "F") - self.img.save(f"output/{input('Please put your Image\'s output name: ')}.png") + filename = "" + while filename == "": + filename = filedialog.asksaveasfilename(filetypes = (('JPEG', ('*.jpg','*.jpeg','*.jpe','*.jfif')),('PNG', '*.png'),('BMP', ('*.bmp','*.jdib')),('GIF', '*.gif')), defaultextension=".png") + if filename.split('.')[1] != "png": + filename = "" + errorTxt.set("Wrong filetype! Needs to be .png") + print(filename) + self.img.save(filename) + errorTxt.set("") class Reader: - def __init__(self, image_path): - self.img_path = image_path + def __init__(self): self.normal_text = "" self.morse_text = "" + def add_img_path(self): + image_path = filedialog.askopenfilename(initialdir="..", title="Select Your Image File") + if str(image_path.split(".")[1]) == "png": + self.img_path = image_path + readImg.set(str(image_path)) + if errorTxt.get() == "Error loading Image file path": + errorTxt.set("") + else: + errorTxt.set("Error loading Image file path") + def run(self): self.load_objects() self.read_function() self.ender_function() - self.out = open('output/text.txt', 'a') - self.out.writelines(self.normal_text) def load_objects(self): self.img = Image.open(self.img_path).convert("RGBA") @@ -146,6 +217,19 @@ class Reader: self.normal_text += ALPH_DICT[sequence] sequence = "" iof.output(self.normal_text, "B") + + filename = "" + while filename == "": + filename = filedialog.asksaveasfilename(filetypes = (('text files', '*.txt'),), defaultextension=".txt") + if filename.split('.')[1] != "txt": + filename = "" + errorTxt.set("Wrong filetype! Needs to be .txt") + print(filename) + errorTxt.set("") + + self.out = open(str(filename), 'w') + self.out.writelines(self.normal_text) + self.out.close() def future_check(self,x,y): @@ -185,7 +269,65 @@ class Reader: else: iof.output("Adding letter separation", "F") return 1 - -if __name__ == "__main__": - Starter = Main() - iof.close() \ No newline at end of file + +starter = Main() +convert = Converter() +read = Reader() + + + +#title +title_label = ttk.Label(master = window, text = "Shush, The Text-Image encryption tool", font = 'Times_New_Roman 24 italic') +error_label = ttk.Label(master=window, text="yea", font="Times_New_Roman 18 bold", textvariable = errorTxt) +title_label.pack() + +#style + +#style = ttk.Style() + +#style.configure('BW.TLabel', foreground="gray90", background="gray50") + +#input field + +main_frame = ttk.Frame(master = window) +top_frame = ttk.Frame(master=main_frame) +read_frame = ttk.Frame(master = main_frame) +read_img_frame = ttk.Frame(master = read_frame) +convert_frame = ttk.Frame(master = main_frame) +img_frame = ttk.Frame(master = convert_frame) +txt_frame = ttk.Frame(master = convert_frame) + +convertButton = ttk.Button(master = top_frame, text = "Encrypt Text Into Image", command = convert.run) +convertButtonImg = ttk.Button(master = img_frame, text = "Add Image Path", command = convert.add_img_path) +convertButtonTxt = ttk.Button(master = txt_frame, text = "Add Text Path", command = convert.add_text_path) +convertImgLabel = ttk.Label(master = img_frame, text = "Image Filepath", font = "Times_New_Roman 8", textvariable = entryImg) +convertTxtLabel = ttk.Label(master = txt_frame, text = "Text Filepath", font = "Times_New_Roman 8", textvariable = entryTxt) + +readButton = ttk.Button(master = top_frame, text = "Decrypt Text From Image", command = read.run) +readButtonImg = ttk.Button(master = read_img_frame, text = "Add Image Path", command = read.add_img_path) +readImgLabel = ttk.Label(master = read_img_frame, text = "Image Filepath", font = "Times_New_Roman 8", textvariable = readImg) + +error_label.pack() + +convertButton.pack(side = "left", padx=30) +convertButtonImg.pack(side = "left") +convertImgLabel.pack(side = "right") +convertButtonTxt.pack(side = "left") +convertTxtLabel.pack(side = "right") + +readButton.pack(side = "right") +readButtonImg.pack(side = "left") +readImgLabel.pack(side = "right") + +main_frame.pack(pady = 10) +top_frame.pack() +read_frame.pack(side = "right") +read_img_frame.pack() +convert_frame.pack(side = "left") +img_frame.pack() +txt_frame.pack() + +sv_ttk.set_theme("dark") + +#run +window.mainloop() \ No newline at end of file diff --git a/Main/input/hi_1000.txt b/tests/Lorem_1000.txt similarity index 100% rename from Main/input/hi_1000.txt rename to tests/Lorem_1000.txt diff --git a/Main/input/car.jpg b/tests/car.jpg similarity index 100% rename from Main/input/car.jpg rename to tests/car.jpg diff --git a/tests/newCar.png b/tests/newCar.png new file mode 100644 index 0000000..62eb159 Binary files /dev/null and b/tests/newCar.png differ