亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 python 中,對象不按照定義的順序打印

在 python 中,對象不按照定義的順序打印

眼眸繁星 2023-12-09 15:36:24
我試圖按照定義的順序打印該函數的返回:import numpydef 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 = 64649d = 241187p = 659q = 673print(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 尊重函數定義的返回值?或者甚至更好,以定義的方式返回(也稱為新行上的每個條目)
查看完整描述

1 回答

?
瀟湘沐

TA貢獻1816條經驗 獲得超6個贊

實際上 return 語句返回一個集合,這里的冒號在字符串內,所以嘗試像這樣返回 dict:

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

等等


查看完整回答
反對 回復 2023-12-09
  • 1 回答
  • 0 關注
  • 148 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號