viva
viva
a) tkinter:
This is the standard Python library used to create graphical user interfaces (GUIs). It provides tools to build windows, buttons,
labels, text fields, and more. In this code, tkinter is used to create the interface for selecting files, entering data, and triggering
encryption/decryption actions.
• tk.Label(): This creates text labels for displaying information to the user.
• tk.Entry(): This is a widget for user input, like text boxes for entering file paths and keys.
• tk.Button(): This creates buttons that users can click to perform actions like file browsing or encryption/decryption.
• tk.OptionMenu(): This widget is used to create a drop-down menu for selecting file types.
• filedialog.askopenfilename(): A dialog box that allows the user to select a file from their computer.
• filedialog.askdirectory(): A dialog box that allows the user to choose a folder (used for selecting output location).
• messagebox.showinfo(): Displays a pop-up message box with information (used to show success messages).
b) filedialog:
This is part of tkinter and is used for file and folder selection dialogs.
c) string:
This module contains common string operations. It is used here to get a list of characters (like punctuation, digits, and letters) that
can be used for encryption.
• string.whitespace: This contains all whitespace characters like spaces, tabs, newlines, etc.
d) random:
This module is used to generate random values. It helps to add randomness to encryption, such as shuffling characters or adding
noise to the encrypted file.
• random.shuffle(): This shuffles the elements of a list in place (e.g., randomizing the order of characters).
a) select_source():
This function is called when the user clicks the "Browse" button next to the source file field. It opens a file picker dialog to let the
user choose a file. The path of the chosen file is then inserted into the source_entry text field.
b) select_output():
This function is called when the user clicks the "Browse" button next to the output folder field. It opens a folder picker dialog,
allowing the user to choose where to save the output (encrypted or decrypted file). The chosen folder path is inserted into the
output_entry text field.
c) encrypt():
This function is executed when the user clicks the "Encrypt" button. It handles the file encryption process.
• Key Creation: It creates a randomized encryption key by shuffling the chars list and adding a random step (fk_step).
• File Reading: It opens the selected source file in binary mode, reads its content, and prepares to encrypt it.
• Encryption: It replaces each character from the original file with the corresponding character in the shuffled key.
Random noise is also added to further secure the encryption.
• Saving Encrypted File: The encrypted content is saved as a new file, and the encryption key is saved to a text file.
• Error Handling: If any error occurs (e.g., invalid file paths), an error message is shown using messagebox.showerror().
d) decrypt():
This function is executed when the user clicks the "Decrypt" button. It handles the decryption process.
• Key Processing: The user provides the encryption key (through key_entry). The function converts it into a list and
extracts the step size (fk_step).
• File Reading: It opens the selected encrypted file, reads its content, and prepares to decrypt it.
• Decryption: It uses the key to reverse the encryption and removes the noise added during encryption.
• Saving Decrypted File: The original content is restored and saved as a new file.
• Error Handling: If any error occurs (e.g., invalid file or key), an error message is shown using messagebox.showerror().
• source_entry: A text entry field where the user can type or see the selected source file's path.
• output_entry: A text entry field where the user can type or see the selected output folder's path.
• key_entry: A text entry field where the user can enter the encryption key for decryption (with masking using show="*").
• file_type: A drop-down menu that allows the user to select the file type (e.g., .txt or .bin).
• Buttons:
o Encrypt Button: When clicked, it calls the encrypt() function to encrypt the file.
o Decrypt Button: When clicked, it calls the decrypt() function to decrypt the file.
The random.shuffle() function is used to create a random key by shuffling a predefined list of characters. The random step
(fk_step) adds another level of unpredictability, ensuring that the same file encrypted multiple times results in different outputs