Tag: print path based on comparison runtime Val turn data input
We know that JSON is an encrypted format for data transfer
This is a TXT-formatted text encryption (purely boring)
Write a messy, look for the two folders you entered below all TXT files (including the next level of files);
Be careful when running, don't encrypt important files.
1 ImportOs.path, time2 ImportJSON3 ImportGlob4 ImportOS5 Import Time6 7 8 defWenjian ():#find the files below each folder9wen=[]Ten One forIinchRootDir: A - forParent,dirnames,filenamesinchOs.walk (i): - the #Case 2 - forFileNameinchFilenames: - - wen.append (Os.path.join (parent,filename)) + - returnWen + A at defTXT ():#find the TXT file based on the following -A=[] - - forfile_nameinchWen: - iffile_name[-4:]=='. txt': - a.append (file_name) in - returna to + - the defJiami (): * $ forIinchA:#encrypt all txt filesPanax Notoginseng -f=Open (i) theContent=F.read () +Content2=json.dumps (content) A f.close () the +With open (I,'W') as F: - $ f.write (Content2) $ - Print('Encryption Successful') - the -Password=input ('Enter the administrator password:')Wuyi ifPassword = =' 123456': the -Rootdir=[] WuVal=input ('Enter the critical path:') -Num=input ('Enter the number of encryption:') About Rootdir.append (val) $ forXinchrange (int (num)): -wen=Wenjian () -A=txt () - Jiami () A + Else: the Print("password error 5 seconds after exit") -Time.sleep (5) $Exit ()
Decrypt:
1 ImportOs.path, time2 ImportJSON3 ImportOS4 Import Time5 6 7 defWenjian ():#find the files below each folder8wen=[]9 Ten forIinchRootDir: One A forParent,dirnames,filenamesinchOs.walk (i): - - #Case 2 the forFileNameinchFilenames: - - wen.append (Os.path.join (parent,filename)) - + returnWen - + A defTXT ():#find the TXT file based on the following atA=[] - - forfile_nameinchWen: - iffile_name[-4:]=='. txt': - a.append (file_name) - in returna - to + - defJiemi (): the * forIinchA:#decrypt all txt files $ Panax NotoginsengWith open (I,'R') as F: -Content2=json.load (f) theF=open (I,'W') + f.write (Content2) A f.close () the Print('Decryption succeeded') + -Password=input ('Enter the administrator password:') $ ifPassword = =' 123456': $ -Rootdir=[] -Val=input ('Enter the critical path:') theNum=input ('number of input decryption:') - Rootdir.append (val)Wuyi forXinchrange (int (num)): thewen=Wenjian () -A=txt () Wu Jiemi () - About Else: $ Print("password error 5 seconds after exit") -Time.sleep (5) - exit () -
JSON for TXT text encryption