-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcipher_vault.py
More file actions
133 lines (104 loc) · 3.87 KB
/
cipher_vault.py
File metadata and controls
133 lines (104 loc) · 3.87 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
131
132
133
import json
key=123
pin=6969
def helper(passwords):
with open("password_manager.txt","w") as file:
json.dump(passwords,file,indent=4)
def load_passwords():
try:
with open("password_manager.txt","r") as file:
return json.load(file)
except FileNotFoundError:
return []
def list_all_saved_websites(passwords):
for index,value in enumerate(passwords,start=1):
print(f"{index}. Website : {value['website']} , Username : {value['username']} , Password : {value['password']}")
def add_new_password(passwords):
website= input("Enter new Website : ")
username= input("Enter new Username : ")
password= pass_to_cipher(input("Enter new Password : "))
passwords.append({"website":website,"username":username,"password":password})
helper(passwords)
def update_password(passwords):
list_all_saved_websites(passwords)
while True:
choice=int(input("Enter choice for updating Password :"))
if 1 <= choice <= len(passwords):
oldPass=pass_to_cipher(input("Enter Old Password : "))
if(passwords[choice-1]["password"]==oldPass):
newPass=pass_to_cipher(input("Enter new Password : "))
passwords[choice-1]["password"]=newPass
break
else :
print("Enter Correct Old Password ! ")
else :
print("Enter valid Choice ! ")
helper(passwords)
def delete_password(passwords):
list_all_saved_websites(passwords)
while True:
choice=int(input("Enter choice for Deleting Password : "))
if 1 <= choice <= len(passwords):
del passwords[choice-1]
break
else:
print("Enter valid Choice ! ")
helper(passwords)
def Access_password(passwords):
while True :
p = int(input("Enter correct Pin : "))
if p == pin:
list_all_saved_websites(passwords)
while True:
choice=int(input("Enter choice for Accessing Password : "))
if 1 <= choice <= len(passwords):
password=cipher_to_pass(passwords[choice-1]["password"],p)
print(f"Password for {passwords[choice-1]['username']} is {password} ")
return
else :
print("Enter valid Choice ! ")
else :
print("Enter a valid Pin ! ")
def pass_to_cipher(password):
arr=[]
for ch in password:
arr.append(ord(ch) ^ key)
return arr
def cipher_to_pass(cipher,p):
if p == pin:
arr=[]
for i in cipher:
arr.append(chr(i ^ key))
return ("".join(arr))
else:
print("Incorrect PIN!")
return None
def main():
passwords = load_passwords()
while True:
print("\n Cipher Vault | Select a Valid Option")
print("1. List All Saved Website Passwords")
print("2. Add a New Password")
print("3. Update an Existing Password")
print("4. Delete a Password")
print("5. Access (View) a Password")
print("6. Exit the Program")
print("\n")
ip=str(input("Enter your Choice : "))
match ip:
case '1':
list_all_saved_websites(passwords)
case '2':
add_new_password(passwords)
case '3':
update_password(passwords)
case '4':
delete_password(passwords)
case '5':
Access_password(passwords)
case '6':
break
case _:
print("Please Enter Valid Choice ! ")
if __name__ == "__main__":
main()