AssertEqual Doesnt Throw an Error even if Values are Different

647 views python
8

I have this code in 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()

Why does it doesn't throw an error? Why does encrypted variable is equal to 0x3925841d02dc09fbdc118597196a0b32 , when in fact they have different values? The same behavior is also observe in decryption variable.

answered question

The numbers are equal but only represented differently as hexadecimal value (prefixed with 0x) and decimal value (no prefix). 0xa == 10

1 Answer

12

They are equal.

the 0x in front of a number means that the representation is base 16 (hex). If you use a calculator to convert 0x3925841d02dc09fbdc118597196a0b32 to decimal format, you will see it is the same value assigned to it in that block of code.

posted this

Have an answer?

JD

Please login first before posting an answer.