zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    Oracle中快速查找锁与锁等待
    Oracle查看、修改连接数
    内置数据类型
    代码片段一
    设计模式学习四:依赖倒置原则
    队列
    设计模式学习六:代理模式
    linux 自学系列:一直kill掉多个进程
    设计模式学习五:装饰器模式
    通过__metaclass__为类动态增加方法实例
  • 原文地址:https://www.cnblogs.com/dreamblog/p/10222065.html
Copyright © 2011-2022 走看看