• python 校验 BLE resolvable private address


    #!/usr/bin/env python
    # -*- coding:utf-8 -*-
    # @author: david
    # pip install pycrypto‎demo

    from Crypto.Cipher import AES

    def bytesToHexString(bs):
    # hex_str = ''
    # for item in bs:
    # hex_str += str(hex(item))[2:].zfill(2).upper() + " "
    # return hex_str
    return ''.join(['%02X ' % b for b in bs])

    def hexStringTobytes(str):
    str = str.replace(" ", "")
    return bytes.fromhex(str)
    # return a2b_hex(str)

    def stringTobytes(str):
    return bytes(str,encoding='utf8')

    def bytesToString(bs):
    return bytes.decode(bs,encoding='utf8')

    if __name__ == '__main__':

               #uint8_t  irk[16]={

               #        0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x12

               #};
               #注意key的顺序,高位在前

        mac = '69C9A7FCA4D0'
    key = '12111111111111111111111111111111'
    plaintext = '00000000000000000000000000'+ mac[0:6]
    prand = mac[0:6]
    hash = mac[6:]
    hexstr_key = hexStringTobytes(key)
    hexstr_plaintext = hexStringTobytes(plaintext)
    cryptor = AES.new(hexstr_key,AES.MODE_ECB)
    ciphertext = cryptor.encrypt(hexstr_plaintext)
    # print(bytesToHexString(ciphertext))
    cryptor_prand = bytesToHexString(ciphertext)[39:].replace(" ", "")
    print('MAC:'+mac)
    print('prand = ' + prand)
    print('hash = ' + hash)
    print('encrypt = ' + cryptor_prand)
    if( hash == cryptor_prand):
    print('mac pass')

    未经本人同意 请务转载 David QQ:435398366
  • 相关阅读:
    nio原理分析与代码实现
    SpringMvc下载excel文件
    centos6下mysql-5.5.21的安装
    CentOS下开启mysql远程连接,远程管理数据库
    客户端更新策略
    IDEA插件开发基础
    简易ORM(基于注解)
    尝试使用Java6API读取java代码
    Java源代码分析与生成
    Common Configration实验
  • 原文地址:https://www.cnblogs.com/dreamblog/p/10222065.html
Copyright © 2020-2023  润新知