zoukankan      html  css  js  c++  java
  • Security and Cryptography in Python

    Security and Cryptography in Python - Hash Functions(1)

    Properties of a Hash Function

    1. It is an one-way deterministic function
    2. The output is dependent on all input bits
    3. Output is uniformly distributed
    4. "Impossible" (difficult) make a collision

    Use of Hash Functions

    1. Digital signature
    2. Shadow files (passwords)
    3. HMAC
    4. Make deterministic identifiers

    Code in Python:

    import hashlib
    
    def modify(m):
        l = list(m)
        l[0] = l[0] ^ 1
        return bytes(l)
    
    m = "This is the hash value message".encode()
    
    sha256 = hashlib.sha256()
    sha256.update(m)
    d = sha256.digest()
    print(d)
    
    sha256 = hashlib.sha256()
    sha256.update(m)
    d = sha256.digest()
    print(d)
    
    m = modify(m)
    print(m)
    
    sha256 = hashlib.sha256()
    sha256.update(m)
    d = sha256.digest()
    print(d)
    

    Running Result:

    image-20210221201144526

    相信未来 - 该面对的绝不逃避,该执著的永不怨悔,该舍弃的不再留念,该珍惜的好好把握。
  • 相关阅读:
    内容敏感图像压缩
    线性筛素数
    一元三次方程
    holiday
    电话网络
    expect之初使用
    python基本数据类型
    Linux系统中的日志管理
    Linux计划任务(at,crontab)
    RHEL7 启动配置 加密
  • 原文地址:https://www.cnblogs.com/keepmoving1113/p/14426192.html
Copyright © 2011-2022 走看看