forked from metafy-social/python-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
86 lines (56 loc) · 1.4 KB
/
main.py
File metadata and controls
86 lines (56 loc) · 1.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
Pwd_Key = 4 #modify to set personalised Key
#Function to Encode the user given data
def Cipher(Text) :
Cipher_Text = ''
for i in Text:
a = chr(ord(i) + Pwd_Key )
Cipher_Text += a
T = Cipher_Text + '\n'
return T
#Function to store the encrypted data.
def Entry(Data):
file = open('Data.txt', 'a')
file.write(Data)
print('\nEntered data has been successfully encrypted and recorded..!!!\n')
file.close()
'''
print(En_Data)
'''
#Function to display the encrypted data.
def Extract():
En_Records,De_Records = [],[]
file = open('Data.txt', 'r')
x = file.readlines()
for i in x:
En_Records.append(i)
for i in range(0,len(En_Records)):
En_Text = En_Records[i]
De_Text = ""
for j in range(0, len(En_Text)):
De_Text += (chr(ord(En_Text[j]) - Pwd_Key))
De_Records.append(De_Text)
file.close()
return De_Records
while(True):
print(" 1 -> Enter Data ")
print(" 2 -> Display Stored Data ")
print(" 0 -> Exit \n")
opt = int(input("Enter the option : "))
print("\n")
if opt == 1 :
Data = input("Enter your data :\n")
En_Data = Cipher(Data)
Entry(En_Data)
elif opt == 2 :
user_key = int(input("Enter the Key to decrypt : "))
if user_key == Pwd_Key :
L = Extract()
for i in range(0,len(L)):
print(L[i][:-1])
print("\n")
else :
print("Wrong key !! ")
elif opt == 0 :
exit()
else :
print("Enter valid option !!")