-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
166 lines (116 loc) · 3.72 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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import pandas as pd
import onetimepad
class Encore:
# the Values to be passed here is the file data format
def __init__(self, fname):
ftype = ['csv', 'excel', 'txt']
if fname in ftype:
self.fname = fname
pass
else:
raise AttributeError('The file type must be either csv, excel, txt')
def dataframe(self, file):
self.file = file
df = pd.read_csv(file)
self.df = df
print(type(self.file))
def lock_allAph(self, key):
def bill(x, p=key):
x = str(x)
x = onetimepad.encrypt(x, p)
return x
for col in self.df.columns:
self.df[col] = self.df[col].apply(bill)
print(self.df)
def unlock_allAph(self, key):
def bill(x, p=key):
x = str(x)
x = onetimepad.decrypt(x, p)
return x
for col in self.df.columns:
self.df[col] = self.df[col].apply(bill)
print(self.df)
def lockcol(self, key, col_name='Surname'):
self.colname = col_name
#print(self.df[self.colname])
def bill(x, p=key):
x = str(x)
x = onetimepad.encrypt(x, p)
return x
self.df[self.colname] = self.df[self.colname].apply(bill)
print(self.df[self.colname])
def Unlockcol(self, key, col_name='Surname'):
self.colname = col_name
#print(self.df[self.colname])
def bill(x, p=key):
x = str(x)
x = onetimepad.decrypt(x, p)
return x
self.df[self.colname] = self.df[self.colname].apply(bill)
print(self.df[self.colname])
def lock_row(self, key, row_num=1):
self.row_num = row_num
def bill(x, p=key):
x = str(x)
x = onetimepad.encrypt(x, p)
return x
self.df.iloc[self.row_num] = self.df.iloc[self.row_num].apply(bill)
print(self.df)
def unlock_row(self, key, row_num=1):
self.row_num = row_num
def bill(x, p=key):
x = str(x)
x = onetimepad.decrypt(x, p)
return x
self.df.iloc[self.row_num] = self.df.iloc[self.row_num].apply(bill)
print(self.df)
def lockrows(self, key, *args):
self.args = args
def bill(x, p=key):
x = str(x)
x = onetimepad.encrypt(x, p)
return x
for i in args:
self.df.iloc[i] = self.df.iloc[i].apply(bill)
print(self.df)
def Unlockrows(self, key, *args):
self.args = args
def bill(x, p=key):
x = str(x)
x = onetimepad.decrypt(x, p)
return x
for i in args:
self.df.iloc[i] = self.df.iloc[i].apply(bill)
print(self.df)
def lockcols(self, key, *args):
self.args = args
def bill(x, p=key):
x = str(x)
x = onetimepad.encrypt(x, p)
return x
for i in args:
self.df.iloc[:,i] = self.df.iloc[:,i].apply(bill)
print(self.df)
def Unlockcols(self, key, *args):
self.args = args
def bill(x, p=key):
x = str(x)
x = onetimepad.decrypt(x, p)
return x
for i in args:
self.df.iloc[:,i] = self.df.iloc[:,i].apply(bill)
def __str__(self):
return f'{self.df}'
def save(self):
if self.fname == 'csv':
self.df.to_csv(self.file, index=False)
elif self.fname == 'excel':
self.df.to_excel(self.file, index=False)
else:
self.df.to_csv(self.file, index=False)
#ecd = Encore('csv')
#
#ecd.dataframe('data.csv')
#ecd.lock_allAph('key')
#ecd.unlock_allAph()
#ecd.save()