zoukankan      html  css  js  c++  java
  • 第十七天

    今日内容

    一、hashlib模块

    1.1加密、验证完整性功能

      #hash算法:传入一段内容会的到一串hash值
      #hash值的三大特点
      #1、如果传入的内容与采用的算法一样,得到的hash值必然一样
      #2、只要采用的算法是固定的,hash值的长度就是固定的,不会随着内容的大小而变
      #3、hash值不可逆,不能通过hash值反解出内容是什么
    
      #1+2可以检验文件的完整性
      #1+3可以加密文件的内容
    
      # import hashlib
      # m = hashlib.md5()
      # #update内必须传入一个二进制类型
      # m.update("你".encode("utf-8"))
      # m.update("好".encode("utf-8"))
      # m.update("hello".encode("utf-8"))
      # m.update("哈哈".encode("utf-8"))
      # #实际上传入的就是你好hello哈哈
      # print(m.hexdigest())
    

    1.2密码加盐

      #在加密一段内容的同时插入一些无关的内容,让破解密码的成本增加
      #在确认加密内容时也加入插入时的内容来验证加密内容是否相同
      #加密时
      import hashlib
      m = hashlib.md5()
      m.update("天王盖地虎".encode("utf-8"))
      m.update("加密内容".encode("utf-8"))
      m.update("宝塔正河妖".encode("utf-8"))
      a = m.hexdigest()
      #解密时
      import hashlib
      m = hashlib.md5()
      m.update("天王盖地虎".encode("utf-8"))
      m.update("输入内容".encode("utf-8"))
      m.update("宝塔正河妖".encode("utf-8"))
      b = m.hexdigest()
      #最后来比较a,b是否相等
    

    二、subprocess模块

    2.1控制操作系统的运行

      import subprocess
      obj = subprocess.Popen("tasklist",
                 shell = True,
                 stdout=subprocess.PIPE,    #管道:连接主进程与子进程的联系
                 stderr=subprocess.PIPE
                 )
      stdout_res = obj.stdout.read()
      stderr_res = obj.stderr.read()
      print(stdout_res.decode("gbk"))
                        #解码
    

    三、os与sys模块

    3.1操作文件(os即sys其他功能请查看egon老师博客)

      import os
      #递归创建文件夹
      # os.makedirs("ac")
      #递归删除文件夹(只能删空的)
      # os.removedirs("ac")
      #浏览当前文件夹
      res = os.listdir(".")
      print(res)
      #获取文件的大小,单位是字节
      # print(os.path.getsize("文件路径"))
    
      #获取文件路径
      import sys
      print(sys.argv)
    

    四、configparser模块

    4.1解析固定配置文件

      例:
            配置文件名为:config.ini
            内容为:
                  [section1]
                  k1 = v1
                  k2:v2
                  user=egon
                  age=18
                  is_admin=true
                  salary=31
    
                  [section2]
                  k1 = v1
    
            解析固定配置文件内容:
                  import configparser
                  config = configparser.ConfigParser()
                  config.read("config.ini")
    
                  #查看配置文件中的标题
                  res = config.sections()
                  print(res)
    
                  #将票题下的K值取出来
                  res = config.options("section1")
                  print(res)
    
                  #拿到标题下的K:V
                  res = config.items("section1")
                  print(res)
    
                  #拿到标题下的某一个值
                  res = config.get("section1",'salary')
                  print(res)
  • 相关阅读:
    Javascript+css 实现网页换肤功能
    pdf版电子书
    网络编辑日常工作流程大观
    实例构造器和类型构造器的一些比较
    详解在Win2003安装光盘中集成SCSI驱动
    css学习日记
    Asp.net开发常用DOS命令
    hosts表的作用
    对于Redis中设置了过期时间的Key,你需要知道这些内容
    为什么领导不喜欢提拔老实人?退休的领导说出了实话
  • 原文地址:https://www.cnblogs.com/kk942260238/p/14262953.html
Copyright © 2011-2022 走看看