JSON for TXT text encryption

Source: Internet
Author: User
Tags administrator password

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.