From 03e9c40e54e1c5ef22910310461937f512ce680a Mon Sep 17 00:00:00 2001 From: Nitkarsh Chourasia Date: Mon, 8 Jan 2024 17:16:55 +0530 Subject: [PATCH 1/5] update: Add support for Upper case encrypt and decrypt updated the dictionary of encryption and changed the way the function takes in the string. --- encrypter-decrypter-gui.py | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/encrypter-decrypter-gui.py b/encrypter-decrypter-gui.py index ea46ea95bb9..75d10d37839 100644 --- a/encrypter-decrypter-gui.py +++ b/encrypter-decrypter-gui.py @@ -34,6 +34,32 @@ def __init__(self, parent): self.parent = parent # ========== Data Key ========== self.data_dic = { + "A": "Q", + "B": "W", + "C": "E", + "D": "R", + "E": "T", + "F": "Y", + "G": "U", + "H": "I", + "I": "O", + "J": "P", + "K": "A", + "L": "S", + "M": "D", + "N": "F", + "O": "G", + "P": "H", + "Q": "J", + "R": "K", + "S": "L", + "T": "Z", + "U": "X", + "V": "C", + "W": "V", + "X": "B", + "Y": "N", + "Z": "M", "a": "q", "b": "w", "c": "e", @@ -199,7 +225,7 @@ def backend_work(self, todo, text_coming): try: text_coming = str( text_coming - ).lower() # <----- Lowering the letters as dic in lower letter + ) # <----- Lowering the letters as dic in lower letter for word in text_coming: for key, value in self.data_dic.items(): if word == key: @@ -212,7 +238,7 @@ def backend_work(self, todo, text_coming): return text_to_return elif todo == "Decrypt": try: - text_coming = str(text_coming).lower() + text_coming = str(text_coming) for word in text_coming: for key, value in self.data_dic.items(): if word == value: From 36a6de5874839ecc7448d79c564a3885b457c0b8 Mon Sep 17 00:00:00 2001 From: Nitkarsh Chourasia Date: Mon, 8 Jan 2024 17:18:13 +0530 Subject: [PATCH 2/5] rename: snake_case file name following standard python naming convention. --- encrypter_decrypter_gui.py | 263 +++++++++++++++++++++++++++++++++++++ 1 file changed, 263 insertions(+) create mode 100644 encrypter_decrypter_gui.py diff --git a/encrypter_decrypter_gui.py b/encrypter_decrypter_gui.py new file mode 100644 index 00000000000..75d10d37839 --- /dev/null +++ b/encrypter_decrypter_gui.py @@ -0,0 +1,263 @@ +# ==================== Importing Libraries ==================== +# ============================================================= +import tkinter as tk +from tkinter import ttk +from tkinter.messagebox import showerror +from tkinter.scrolledtext import ScrolledText + +# ============================================================= + + +class Main(tk.Tk): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.title("Alphacrypter") + # ----- Setting Geometry ----- + self.geometry_settings() + + def geometry_settings(self): + _com_scr_w = self.winfo_screenwidth() + _com_scr_h = self.winfo_screenheight() + _my_w = 300 + _my_h = 450 + # ----- Now Getting X and Y Coordinates + _x = int(_com_scr_w / 2 - _my_w / 2) + _y = int(_com_scr_h / 2 - _my_h / 2) + _geo_string = str(_my_w) + "x" + str(_my_h) + "+" + str(_x) + "+" + str(_y) + self.geometry(_geo_string) + # ----- Geometry Setting Completed Now Disabling Resize Screen Button ----- + self.resizable(width=False, height=False) + + +class Notebook: + def __init__(self, parent): + self.parent = parent + # ========== Data Key ========== + self.data_dic = { + "A": "Q", + "B": "W", + "C": "E", + "D": "R", + "E": "T", + "F": "Y", + "G": "U", + "H": "I", + "I": "O", + "J": "P", + "K": "A", + "L": "S", + "M": "D", + "N": "F", + "O": "G", + "P": "H", + "Q": "J", + "R": "K", + "S": "L", + "T": "Z", + "U": "X", + "V": "C", + "W": "V", + "X": "B", + "Y": "N", + "Z": "M", + "a": "q", + "b": "w", + "c": "e", + "d": "r", + "e": "t", + "f": "y", + "g": "u", + "h": "i", + "i": "o", + "j": "p", + "k": "a", + "l": "s", + "m": "d", + "n": "f", + "o": "g", + "p": "h", + "q": "j", + "r": "k", + "s": "l", + "t": "z", + "u": "x", + "v": "c", + "w": "v", + "x": "b", + "y": "n", + "z": "m", + "1": "_", + "2": "-", + "3": "|", + "4": "?", + "5": "*", + "6": "!", + "7": "@", + "8": "#", + "9": "$", + "0": "~", + ".": "/", + ",": "+", + " ": "&", + } + # ============================== + # ----- Notebook With Two Pages ----- + self.nb = ttk.Notebook(self.parent) + self.page1 = ttk.Frame(self.nb) + self.page2 = ttk.Frame(self.nb) + self.nb.add(self.page1, text="Encrypt The Words") + self.nb.add(self.page2, text="Decrypt The Words") + self.nb.pack(expand=True, fill="both") + # ----- LabelFrames ----- + self.page1_main_label = ttk.LabelFrame( + self.page1, text="Encrypt Any Text" + ) # <----- Page1 LabelFrame1 + self.page1_main_label.grid(row=0, column=0, pady=20, padx=2, ipadx=20) + self.page1_output_label = ttk.LabelFrame(self.page1, text="Decrypted Text") + self.page1_output_label.grid(row=1, column=0, pady=10, padx=2) + + self.page2_main_label = ttk.LabelFrame( + self.page2, text="Decrypt Any Text" + ) # <----- Page1 LabelFrame1 + self.page2_main_label.grid(row=0, column=0, pady=20, padx=2, ipadx=20) + self.page2_output_label = ttk.LabelFrame(self.page2, text="Real Text") + self.page2_output_label.grid(row=1, column=0, pady=10, padx=2) + # <---Scrolled Text Global + self.decrypted_text_box = ScrolledText( + self.page1_output_label, width=30, height=5, state="normal" + ) + self.decrypted_text_box.grid(row=1, column=0, padx=2, pady=10) + + self.text_box = ScrolledText( + self.page2_output_label, width=30, height=5, state="normal" + ) + self.text_box.grid(row=1, column=0, padx=2, pady=10) + # ----- Variables ----- + self.user_text = tk.StringVar() + self.decrypted_user_text = tk.StringVar() + + self.user_text2 = tk.StringVar() + self.real_text = tk.StringVar() + # ----- Getting Inside Page1 ----- + self.page1_inside() + self.page2_inside() + + def page1_inside(self): + style = ttk.Style() + user_text_label = ttk.Label( + self.page1_main_label, text="Enter Your Text Here : ", font=("", 14) + ) + user_text_label.grid(row=0, column=0, pady=10) + user_entry_box = ttk.Entry( + self.page1_main_label, width=35, textvariable=self.user_text + ) + user_entry_box.grid(row=1, column=0) + style.configure( + "TButton", + foreground="black", + background="white", + relief="groove", + font=("", 12), + ) + encrypt_btn = ttk.Button( + self.page1_main_label, + text="Encrypt Text", + style="TButton", + command=self.encrypt_now, + ) + encrypt_btn.grid(row=2, column=0, pady=15) + + # ---------- Page1 Button Binding Function ---------- + + def encrypt_now(self): + user_text = self.user_text.get() + if user_text == "": + showerror( + "Nothing Found", "Please Enter Something In Entry Box To Encrypt...!" + ) + return + else: + self.decrypted_user_text = self.backend_work("Encrypt", user_text) + self.decrypted_text_box.insert(tk.INSERT, self.decrypted_user_text, tk.END) + + # --------------------------------------------------Binding Functions of Page1 End Here + # Page2 ------------------> + def page2_inside(self): + style = ttk.Style() + user_text_label = ttk.Label( + self.page2_main_label, text="Enter Decrypted Text Here : ", font=("", 14) + ) + user_text_label.grid(row=0, column=0, pady=10) + user_entry_box = ttk.Entry( + self.page2_main_label, width=35, textvariable=self.user_text2 + ) + user_entry_box.grid(row=1, column=0) + style.configure( + "TButton", + foreground="black", + background="white", + relief="groove", + font=("", 12), + ) + encrypt_btn = ttk.Button( + self.page2_main_label, + text="Decrypt Text", + style="TButton", + command=self.decrypt_now, + ) + encrypt_btn.grid(row=2, column=0, pady=15) + # ---------- Page1 Button Binding Function ---------- + + def decrypt_now(self): + user_text = self.user_text2.get() + if user_text == "": + showerror( + "Nothing Found", "Please Enter Something In Entry Box To Encrypt...!" + ) + return + else: + self.real_text = self.backend_work("Decrypt", user_text) + self.text_box.insert(tk.INSERT, self.real_text, tk.END) + + def backend_work(self, todo, text_coming): + text_to_return = "" + if todo == "Encrypt": + try: + text_coming = str( + text_coming + ) # <----- Lowering the letters as dic in lower letter + for word in text_coming: + for key, value in self.data_dic.items(): + if word == key: + # print(word, " : ", key) + text_to_return += value + + except ValueError: + showerror("Unknown", "Something Went Wrong, Please Restart Application") + + return text_to_return + elif todo == "Decrypt": + try: + text_coming = str(text_coming) + for word in text_coming: + for key, value in self.data_dic.items(): + if word == value: + text_to_return += key + + except ValueError: + showerror("Unknown", "Something Went Wrong, Please Restart Application") + + return text_to_return + + else: + showerror("No Function", "Function Could not get what to do...!") + + +# ============================================================= +# ==================== Classes End Here ... ! ================= + + +if __name__ == "__main__": + run = Main() + Notebook(run) + run.mainloop() From f44219564f6bcdd9af91d1029453820875fb00a6 Mon Sep 17 00:00:00 2001 From: Nitkarsh Chourasia Date: Mon, 8 Jan 2024 17:22:30 +0530 Subject: [PATCH 3/5] sort: duplicate programs redundant programs available. --- 12.py | 5 ----- 56 | 3 --- factor.py | 9 --------- 3 files changed, 17 deletions(-) delete mode 100644 12.py delete mode 100644 56 delete mode 100644 factor.py diff --git a/12.py b/12.py deleted file mode 100644 index 4d84bb24359..00000000000 --- a/12.py +++ /dev/null @@ -1,5 +0,0 @@ -import turtle -t = turtle.Turtle() -t.circle(20) -t1=turtle.Turtle() -t1.circle(25) diff --git a/56 b/56 deleted file mode 100644 index 2f93feb9918..00000000000 --- a/56 +++ /dev/null @@ -1,3 +0,0 @@ -import turtle -t = turtle.Turtle() -t.circle(50) diff --git a/factor.py b/factor.py deleted file mode 100644 index 2e17bec367f..00000000000 --- a/factor.py +++ /dev/null @@ -1,9 +0,0 @@ -def factorial(n): - if n == 0: - return 1 - else: - return n * factorial(n - 1) - - -n = int(input("Input a number to compute the factiorial : ")) -print(factorial(n)) From dd0534c6ac0385cf5f019da1c81d262b752359cb Mon Sep 17 00:00:00 2001 From: Nitkarsh Chourasia Date: Mon, 8 Jan 2024 20:24:07 +0530 Subject: [PATCH 4/5] sort: remove plagarise and duplicates. --- Count the Number of Each Vowel | 9 --------- addition.py | 35 ---------------------------------- even and odd.py | 9 --------- even.py | 5 ----- main.py | 17 ----------------- 5 files changed, 75 deletions(-) delete mode 100644 Count the Number of Each Vowel delete mode 100644 addition.py delete mode 100644 even and odd.py delete mode 100644 even.py delete mode 100644 main.py diff --git a/Count the Number of Each Vowel b/Count the Number of Each Vowel deleted file mode 100644 index eaca619f7a4..00000000000 --- a/Count the Number of Each Vowel +++ /dev/null @@ -1,9 +0,0 @@ -vowels = 'aeiou' -ip_str = 'Hello, have you tried our tutorial section yet?' -count = 0 - -for char in ip_str: - if char in vowels: - count += 1 - -print(count) diff --git a/addition.py b/addition.py deleted file mode 100644 index 2a90bae31fb..00000000000 --- a/addition.py +++ /dev/null @@ -1,35 +0,0 @@ -print() -print() - -a = True - -while a == True: - - number1 = int(input("enter first number:")) - number2 = int(input("enter second number:")) - number3 = int(input("enter third number:")) - sum = number1 + number2 + number3 - - print() - print("\t\t======================================") - print() - - print("Addition of three numbers is", " :-- ", sum) - - print() - print("\t\t======================================") - print() - - d = input("Do tou want to do it again ?? Y / N -- ").lower() - - if d == "y": - - print() - print("\t\t======================================") - print() - - continue - - else: - - exit() diff --git a/even and odd.py b/even and odd.py deleted file mode 100644 index 7ac6bae114b..00000000000 --- a/even and odd.py +++ /dev/null @@ -1,9 +0,0 @@ -# Python program to check if the input number is odd or even. -# A number is even if division by 2 gives a remainder of 0. -# If the remainder is 1, it is an odd number. - -num = int(input("Enter a number: ")) -if (num % 2) == 0: - print("{0} is Even".format(num)) -else: - print("{0} is Odd".format(num)) diff --git a/even.py b/even.py deleted file mode 100644 index 2faafbc3818..00000000000 --- a/even.py +++ /dev/null @@ -1,5 +0,0 @@ -num = int(input("Enter a number: ")) -if (num % 2) == 0: - print("{0} is Even".format(num)) -else: - print("{0} is Odd".format(num)) diff --git a/main.py b/main.py deleted file mode 100644 index 7eeb1845114..00000000000 --- a/main.py +++ /dev/null @@ -1,17 +0,0 @@ -""" patient_name = "john smith" -age = 20 -is_patient_name = True -print(patient_name) """ - -""" word = input("Why are you unemployed") -print("Due to lack of " +word) """ - -"""a = input("Enter 1st Number:") -b = input("Enter 2nd Number:") -sum = float (a) + int (b) -print(sum) -""" -student = "ANKITASDFAHBVGASDNDSDNBFCZCXCNIGL" -print(student.lower()) - -print(student.find("ASDF")) From 641e756bd9e26e7583c595a7696d4e9ae7e08021 Mon Sep 17 00:00:00 2001 From: Nitkarsh Chourasia Date: Mon, 8 Jan 2024 20:29:26 +0530 Subject: [PATCH 5/5] update: add good features More good features were added. --- love_turtle.py | 44 +++++++++++++++++++------------- magic8ball.py | 68 +++++++++++++++++++++++++++++-------------------- magic_8_ball.py | 63 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 130 insertions(+), 45 deletions(-) create mode 100644 magic_8_ball.py diff --git a/love_turtle.py b/love_turtle.py index 82e0217205b..238b3eebf80 100644 --- a/love_turtle.py +++ b/love_turtle.py @@ -1,20 +1,28 @@ import turtle -t = turtle.Turtle() -turtle.title("I Love You") -screen = turtle.Screen() -screen.bgcolor("white") -t.color("red") -t.begin_fill() -t.fillcolor("black") - -t.left(140) -t.forward(180) -t.circle(-90, 200) - -t.setheading(60) # t.left -t.circle(-90, 200) -t.forward(180) - -t.end_fill() -t.hideturtle() + +def heart_red(): + t = turtle.Turtle() + turtle.title("I Love You") + screen = turtle.Screen() + screen.bgcolor("white") + t.color("red") + t.begin_fill() + t.fillcolor("red") + + t.left(140) + t.forward(180) + t.circle(-90, 200) + + t.setheading(60) # t.left + t.circle(-90, 200) + t.forward(180) + + t.end_fill() + t.hideturtle() + + turtle.done() + + +if __name__ == "__main__": + heart_red() diff --git a/magic8ball.py b/magic8ball.py index 1ce9dc39a69..816705b8e21 100644 --- a/magic8ball.py +++ b/magic8ball.py @@ -1,49 +1,63 @@ import random +from colorama import Fore, Style +import inquirer responses = [ "It is certain", "It is decidedly so", "Without a doubt", - "Yes definitely ", + "Yes definitely", "You may rely on it", "As I see it, yes", - "Most likely ", + "Most likely", "Outlook good", "Yes", "Signs point to yes", "Do not count on it", "My reply is no", - " My sources say no", - " Outlook not so good", + "My sources say no", + "Outlook not so good", "Very doubtful", "Reply hazy try again", "Ask again later", - "Better not tell you now ", - "Cannot predict now ", + "Better not tell you now", + "Cannot predict now", "Concentrate and ask again", ] -print("Hi! I am the magic 8 ball, what's your name?") -name = input() -print("Hello!" + name) - - -def magic8Ball(): - print("Whay's your question? ") - question = input() - answer = responses[random.randint(0, len(responses) - 1)] - print(answer) - tryAgain() - - -def tryAgain(): - print( - "Do you wanna ask any more questions? press Y for yes and any other key to exit " - ) - x = input() - if x in ["Y", "y"]: - magic8Ball() + + +# Will use a class on it. +# Will try to make it much more better. +def get_user_name(): + return inquirer.text( + message="Hi! I am the magic 8 ball, what's your name?" + ).execute() + + +def display_greeting(name): + print(f"Hello, {name}!") + + +def magic_8_ball(): + question = inquirer.text(message="What's your question?").execute() + answer = random.choice(responses) + print(Fore.BLUE + Style.BRIGHT + answer + Style.RESET_ALL) + try_again() + + +def try_again(): + response = inquirer.list_input( + message="Do you want to ask more questions?", + choices=["Yes", "No"], + ).execute() + + if response.lower() == "yes": + magic_8_ball() else: exit() -magic8Ball() +if __name__ == "__main__": + user_name = get_user_name() + display_greeting(user_name) + magic_8_ball() diff --git a/magic_8_ball.py b/magic_8_ball.py new file mode 100644 index 00000000000..816705b8e21 --- /dev/null +++ b/magic_8_ball.py @@ -0,0 +1,63 @@ +import random +from colorama import Fore, Style +import inquirer + +responses = [ + "It is certain", + "It is decidedly so", + "Without a doubt", + "Yes definitely", + "You may rely on it", + "As I see it, yes", + "Most likely", + "Outlook good", + "Yes", + "Signs point to yes", + "Do not count on it", + "My reply is no", + "My sources say no", + "Outlook not so good", + "Very doubtful", + "Reply hazy try again", + "Ask again later", + "Better not tell you now", + "Cannot predict now", + "Concentrate and ask again", +] + + +# Will use a class on it. +# Will try to make it much more better. +def get_user_name(): + return inquirer.text( + message="Hi! I am the magic 8 ball, what's your name?" + ).execute() + + +def display_greeting(name): + print(f"Hello, {name}!") + + +def magic_8_ball(): + question = inquirer.text(message="What's your question?").execute() + answer = random.choice(responses) + print(Fore.BLUE + Style.BRIGHT + answer + Style.RESET_ALL) + try_again() + + +def try_again(): + response = inquirer.list_input( + message="Do you want to ask more questions?", + choices=["Yes", "No"], + ).execute() + + if response.lower() == "yes": + magic_8_ball() + else: + exit() + + +if __name__ == "__main__": + user_name = get_user_name() + display_greeting(user_name) + magic_8_ball()