-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
94 lines (87 loc) · 3.5 KB
/
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
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
# CMSC 334: Computer Security Final Project
# @authors: Sophie Zhao & Maggie Song
import hashlib
from passwd_check import load_passwords_from_txt, check_password
from text_ende import create_entry, append_entry, read_entry
from pdf_ende import pdf_encrypt, pdf_decrypt
from multimedia_ende import multimedia_encrypt, multimedia_decrypt
def main():
# Load passwords
passwords = load_passwords_from_txt('passwords.txt')
# Prompt user to enter password
while True:
user_input = input("Enter your password: ")
if len(user_input) <= 4:
print("Password is too short. The length of the password should be greater than 4.")
if check_password(user_input, passwords):
print("Password is commonly used. Please choose a stronger password.")
else:
print("Password is not commonly used. Good to go! \n")
break
# Derive the key for the text encryption & decryption from the user typed password
salt = b'totalrandomsalt'
key = hashlib.pbkdf2_hmac('sha256', user_input.encode(), salt, 100000)
key = key[:16]
print("Welcome to the File Management System!")
# While loop for operations
while True:
print("")
print("What type of file would you like to manage?")
print("1. Text file")
print("2. PDF file")
print("3. Image/Audio/Video file")
print("4. Exit")
filetype = input("Enter the number of the file type you would like to manage: ")
if filetype == "1":
print("\nChoose an operation:")
print("(x) : Return to main menu")
print("(n) : Create a new text file")
print("(r) : Read a text file")
print("(a) : Append to an existing text file")
choice = input()
while choice not in ['x', 'n', 'r', 'a']:
print("ERROR: Invalid input. Choose again.")
choice = input()
if choice == 'x':
continue
elif choice == 'n':
create_entry(key)
elif choice == 'r':
read_entry(key)
elif choice == 'a':
append_entry(key)
elif filetype == "2":
print("\nChoose an operation:")
print("(x) : Return to main menu")
print("(e) : Encrypt a PDF file")
print("(d) : Decrypt a PDF file")
choice = input()
while choice not in ['x', 'e', 'd']:
print("ERROR: Invalid input. Choose again.")
choice = input()
if choice == 'x':
continue
elif choice == 'e':
pdf_encrypt(user_input)
elif choice == 'd':
pdf_decrypt(user_input)
elif filetype == "3":
print("\nChoose an operation:")
print("(x) : Return to main menu")
print("(e) : Encrypt an image/audio/video file")
print("(d) : Decrypt an image/audio/video file")
choice = input()
while choice not in ['x', 'e', 'd']:
print("ERROR: Invalid input. Choose again.")
choice = input()
if choice == 'x':
continue
elif choice == 'e':
multimedia_encrypt(user_input)
elif choice == 'd':
multimedia_decrypt(user_input)
elif filetype == "4":
print("Exiting the File Management System. Goodbye!")
break
if __name__ == "__main__":
main()