我試圖按照定義的順序打印該函數的返回: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),
等等
添加回答
舉報
0/150
提交
取消