PKCS1.py 文件源码

python
阅读 32 收藏 0 点赞 0 评论 0

项目:CRYPTO 作者: ndiab 项目源码 文件源码
def PKCS1(message : int, size_block : int) -> int:
    """
    PKCS1 padding function
    the format of this padding is :

    0x02 | 0x00 | [0xFF...0xFF] | 0x00 | [message]
    """
    # compute the length in bytes of the message
    length = math.ceil(math.ceil(math.log2(message-1)) / 8)

    template = "0200"

    # generate a template 0xFFFFF.....FF of size_block bytes
    for i in range(size_block-2):
        template = template + 'FF'
    template = int(template,16)

    # Add the 00 of the end of the padding to the template
    for i in range(length+1) :
        template = template ^ (0xFF << i*8)

    # add the padding to the original message
    message = message | template

    return message
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号