File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ import base64
2+ import json
3+ import sys
4+ from pathlib import Path
5+
6+ encrypted_filename = Path ("./assets/plz.json" )
7+ decrypted_filename = Path ("./assets/plz-plain.json" )
8+
9+
10+ def decrypt ():
11+ with open (encrypted_filename ) as f :
12+ data = json .load (f )
13+ data = [
14+ {** x , ** {"E-Mail" : base64 .b64decode (x ["E-Mail" ]).decode ("utf-8" )}} for x in data
15+ ]
16+ with open (decrypted_filename , "w" ) as f :
17+ json .dump (data , f , ensure_ascii = False , indent = 2 )
18+
19+
20+ def encrypt ():
21+ with open (decrypted_filename ) as f :
22+ data = json .load (f )
23+ data = [
24+ {
25+ ** x ,
26+ ** {"E-Mail" : base64 .b64encode (x ["E-Mail" ].encode ("utf-8" )).decode ("utf-8" )},
27+ }
28+ for x in data
29+ ]
30+ with open (encrypted_filename , "w" ) as f :
31+ json .dump (data , f , ensure_ascii = False , indent = 2 )
32+
33+
34+ if __name__ == "__main__" :
35+ arg = sys .argv [1 ]
36+ if arg == "decrypt" :
37+ decrypt ()
38+ elif arg == "encrypt" :
39+ encrypt ()
40+ else :
41+ print ("Bad argument" )
You can’t perform that action at this time.
0 commit comments