【发布时间】:2018-11-04 21:51:04
【问题描述】:
我在 Python 中有这段代码
import unittest
class AES_TEST(unittest.TestCase):
def test_encryption(self):
print('Encryption : ')
plaintext = 0x3243f6a8885a308d313198a2e0370734
encrypted = 75960790320075369159181001580855561010
print(encrypted)
print('0x3925841d02dc09fbdc118597196a0b32')
self.assertEqual(encrypted, 0x3925841d02dc09fbdc118597196a0b32)
def test_decryption(self):
print('Decryption : ')
ciphertext = 0x3925841d02dc09fbdc118597196a0b32
decrypted = self.AES.decrypt(ciphertext)
decrypted = 66814286504060421741230023322616923956
print(decrypted)
print('0x3243f6a8885a308d313198a2e0370734')
self.assertEqual(decrypted, 0x3243f6a8885a308d313198a2e0370734)
if __name__ == '__main__':
unittest.main()
为什么它不抛出错误?为什么 encrypted 变量等于 0x3925841d02dc09fbdc118597196a0b32 ,而实际上它们具有不同的值?在decryption 变量中也观察到相同的行为。
【问题讨论】:
-
这些数字是相等的,但只是以十六进制值(前缀为
0x)和十进制值(无前缀)的方式表示。0xa == 10
标签: python numbers hex decimal assertion