在 python 中,对象不按照定义的顺序打印

我试图按照定义的顺序打印该函数的返回:


import numpy


def Decrypt_CRT_RSA(c, d, p, q):

    """

    Decrypts RSA with CRT

    :param c: The cipher text you want to decrypt

    :param d: The secret key

    :param p: A prime number forming half of the secret key

    :param q:A prime number forming the other half of the secret key

    """

    dp = d % (p - 1)

    dq = d % (q - 1)

    cp = c % p

    cq = c % q

    m0 = pow(cp, dp, p)

    m1 = pow(cq, dq, q)

    Msg = CRT([m0, m1], [p, q])[0]

    return {

        'p part of the cipher text: ' + str(cp),

        'q part of the cipher text: ' + str(cq),

        'p part of the private key: ' + str(dp),

        'q part of the private key: ' + str(dq),

        'first half of the message m: ' + str(m0),

        'second half of the message m: ' + str(m1),

        'the full message (aka m0 + m1): ' + str(Msg)

    }


c = 64649

d = 241187

p = 659

q = 673

print(Decrypt_CRT_RSA(c, d, p, q))

但它是这样打印的:


{'密文p部分:67', '完整消息(又名m0 + m1):12345', '消息前半部分m: 483', '私钥q部分: 611', '第二部分消息的一半 m: 231', 'p 私钥部分: 359', 'q 密文部分: 41'}


正如你所看到的,打印的第二件事是the full message 我最后返回的那件事。我如何让 python 尊重函数定义的返回值?或者甚至更好,以定义的方式返回(也称为新行上的每个条目)


眼眸繁星
浏览 46回答 1
1回答

潇湘沐

实际上 return 语句返回一个集合,这里的冒号在字符串内,所以尝试像这样返回 dict:  return {           'p part of the cipher text': str(cp),等等
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python