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
  • 相关阅读:
    NO OO NO LIFE:OO第二单元总结
    凡为过往,皆是序章——软工全系列个人总结
    Think on 小黄衫
    软工-结对编程作业#3
    你问我答,不亦乐乎——软工案例分析作业
    软工-结对编程作业#2
    软工-结对编程作业#1
    道法之间——软工第2次博客作业
    软工-个人阅读作业#1
    OO_Unit4 UML模型化设计总结
  • 原文地址:https://www.cnblogs.com/dreamblog/p/10222065.html
Copyright © 2011-2022 走看看