-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSaiferCLI.py
More file actions
130 lines (105 loc) · 4 KB
/
SaiferCLI.py
File metadata and controls
130 lines (105 loc) · 4 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import random
import string
import sys
import os
import tkinter as tk
from tkinter import filedialog
import saifer
sai = saifer
def makeKey_CLI():
# Define the folder path
folder_path = "Keys"
# Create the folder if it doesn't exist
if not os.path.exists(folder_path):
os.makedirs(folder_path)
# Define the file path
filename = input("Enter a name for your key: ")
if(filename is None or len(filename.strip()) == 0):
print("Filename cannot be empty, returning to main menu")
return
print("Creating key...")
path = sai.makeKey(filename)
print(f"Key created at {path}!")
def encrypt_CLI():
#GET KEY
print("Please select a .saiferkey file to be used in encryption...")
# Create a Tkinter root window
window = tk.Tk()
window.withdraw() # Hide the root window
# Open a file dialog for selecting a key file
key_file_path = filedialog.askopenfilename(initialdir=os.getcwd()+"/Keys", title="Select Key",
filetypes=[("Saifer Keys", "*.saiferkey")])
# Check if a file was selected
if key_file_path:
print("Selected file:", key_file_path)
else:
print("No file selected. Returning to main menu.")
return
#GET PLAINTEXT
print("Please select a .txt file to encrypt...")
# Open a file dialog for selecting a key file
txt_file_path = filedialog.askopenfilename(initialdir=os.getcwd(), title="Select File",
filetypes=[("Text Files", "*.txt")])
# Check if a file was selected
if txt_file_path:
print("Selected file:", txt_file_path)
else:
print("No file selected. Returning to main menu.")
return
filename = input("Enter a name for the encrypted file: ")
print("Encrypting...")
sai.encrypt(key_file_path, txt_file_path, filename)
print("Encryption Complete!")
def decrypt_CLI():
#KEYS
print("Please select a .saiferkey file to be used in decryption...")
# Create a Tkinter root window
window = tk.Tk()
window.withdraw() # Hide the root window
# Open a file dialog for selecting a key file
key_file_path = filedialog.askopenfilename(initialdir=os.getcwd()+"/Keys", title="Select Key",
filetypes=[("Saifer Keys", "*.saiferkey")])
# Check if a file was selected
if key_file_path:
print("Selected file:", key_file_path)
else:
print("No file selected. Returning to main menu.")
return
#SAIFERTEXT
print("Please select a .saifertxt file to decrypt...")
# Open a file dialog for selecting a saifertxt file
saifertxt_file_path = filedialog.askopenfilename(initialdir=os.getcwd()+"/SaiferTexts", title="Select Saifer",
filetypes=[("Saifer Text", "*.saifertxt")])
# Check if a file was selected
if saifertxt_file_path:
print("Selected file:", saifertxt_file_path)
else:
print("No file selected. Returning to main menu.")
return
filename = input("Enter a name for the decrypted file: ")
print("Decrypting...")
sai.decrypt(key_file_path, saifertxt_file_path, filename)
print("Decryption Complete!")
#Main menu functions#
def display_options():
print("1. Make a Saifer Key")
print("2. Encrypt a message")
print("3. Decrypt a message")
print("4. Exit")
def main():
print("Saifer main menu: ")
while True:
display_options()
choice = input("Enter your choice: ")
if choice == '1':
makeKey_CLI()
elif choice == '2':
encrypt_CLI()
elif choice == '3':
decrypt_CLI()
elif choice == '4':
print("Exiting...")
break
else:
print("Invalid choice. Please enter a number between 1 and 4.")
main()