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

    Security and Cryptography in Python - Hash Functions(4)

    Why iterate over hash function and demonstrated by implementation in Python

    Code in Python:

    import hashlib
    import base64
    
    
    def guess_password(salt, iterations, entropy):
        alphabet = "abcdefghijklmnopqrstuvwxyz"
        for c1 in alphabet:
            for c2 in alphabet:
                password = str.encode(c1 + c2)
                value = base64.b64encode(hashlib.pbkdf2_hmac("sha512", password, salt, iterations, dklen=128))
                if value == entropy:
                    return password
        return "".encode()
    
    
    iterations = 45454
    salt = base64.b64decode("6VuJKkHVTdDelbNMPBxzw7INW2NkYlR/LoW40L7kVAI=".encode())
    validation = "SALTED-SHA512-PBKDF2"
    entropy = "15KqQ3c+ozUsKvgNZmwU0GNT+De1x/W+/MBkotAgPnMHJ90YDrgYrQRvY4YkCdBhNs+JkStX7EjnCNWAAW5xATANwPlKwBdyFyqrkqnRyxtb+ccd2S2aflf1CwaDOGXl7RKyToGdNjPNzK0gWSaoFX7eSe6Eugnhw51ioPP/OUg=".encode()
    
    password = "??".encode()
    
    password = guess_password(salt, iterations, entropy)
    print(password)
    value = base64.b64encode(hashlib.pbkdf2_hmac("sha512", password, salt, iterations, dklen=128))
    print(value)
    print(entropy)
    
    

    Running Result (The password is 'pw'):

    image-20210307101612265

    相信未来 - 该面对的绝不逃避,该执著的永不怨悔,该舍弃的不再留念,该珍惜的好好把握。
  • 相关阅读:
    CentOS 7 修改国内yum源
    k8s 安装
    python2 python3同时安装了scrapy如何区分调用
    scrapy log 设置
    hello django
    linux 分割大文件
    scrapy 对不同的Item进行分开存储
    纯C实现的一套low b 贪吃蛇(娱乐版)
    Python之如何实现一行输入多个值
    HDU2571:命运(DP)
  • 原文地址:https://www.cnblogs.com/keepmoving1113/p/14493558.html
Copyright © 2011-2022 走看看