Python密码学

文件解密

文件解密详细操作教程
在本章中,让我们讨论使用Python进行加密的文件解密。请注意,在解密过程中,我们将遵循相同的过程,但是,我们将重点放在输入路径或已加密的必需文件上,而不是指定输出路径。

代码

以下是使用Python解密加密文件的示例代码-
# Filename : example.py
# Copyright : 2020 By Lidihuo
# Author by : www.lidihuo.com
# Date : 2020-08-28
#!/usr/bin/python
# ---------------- READ ME ---------------------------------------------
# This Script is Created Only for Practise and Educational Purpose Only
# This cript is Created for http://bitforestinfo.blogspot.in
# This Script is Written By
#
#
##################################################
######## Please Don't Remove Author Name #########
############### Thanks ###########################
##################################################
#
#
# =================Other Configuration================
# Usages :
usage = "usage: %prog [options] "
# Version
Version="%prog 0.0.1"
# ====================================================
# import Modules
import optparse, sys,os
from toolkit import processor as ps
def main():
   parser = optparse.OptionParser(usage = usage,version = Version)
   parser.add_option(
      '-i','--input',type = 'string',dest = 'inputfile',
      help = "File Input Path for Encryption", default = None)
   parser.add_option(
      '-o','--output',type = "string",dest = 'outputfile',
      help = "File Output Path for Saving Encrypter Cipher",default = ".")
   parser.add_option(
      '-p','--password',type = "string",dest = 'password',
      help = "Provide Password for Encrypting File",default = None)
      (options, args) = parser.parse_args()
      # Input Conditions Checkings
      if not options.inputfile or not os.path.isfile(options.inputfile):
         print " [Error] Please Specify Input File Path"
         exit(0)
      if not options.outputfile or not os.path.isdir(options.outputfile):
         print " [Error] Please Specify Output Path"
         exit(0)
      if not options.password:
         print " [Error] No
         exit(0)
      inputfile = options.inputfile
      outputfile = options.outputfile
      password = options.password
      work = "D"
      ps.FileCipher(inputfile,outputfile,password,work)
      return
if __name__ == '__main__':
   main()
您可以使用以下命令来执行以上代码-
# Filename : example.py
# Copyright : 2020 By Lidihuo
# Author by : www.lidihuo.com
# Date : 2020-08-28
python pyfilecipher-decrypt.py -i encrypted_file_path -p password

输出

执行上面显示的命令时,您可以观察以下代码-
解密
注意-输出指定加密之前和解密之后的哈希值,这提醒您,同一文件已加密并且处理成功。
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4