def test_vector4(self): # this test was designed with 10 rounds. key_bytes = binascii.unhexlify('2b7e151628aed2a6abf7158809cf4f3c') input = "999999999" tweak = "7777777" expected_result = "658229573" self.assertEqual(expected_result, FPE.encrypt(key_bytes, input, tweak))
def testDec1(self): key_bytes = crypto.generate_random_bytes(config.AES_KEY_SIZE) input = "999999999" tweak = "7777777" self.assertEqual( input, FPE.decrypt(key_bytes, FPE.encrypt(key_bytes, input, tweak), tweak))
def testfail(self): key_bytes = binascii.hexlify( b'GM\x7fB\x11\x80\xaf\x19\x9c\xbe]D5\x80M\x1f') input = "999999999" tweak = "7777777" self.assertEqual( input, FPE.decrypt(key_bytes, FPE.encrypt(key_bytes, input, tweak), tweak))
def testDec2_Random(self): key_bytes = crypto.generate_random_bytes(config.AES_KEY_SIZE) print(key_bytes) input = str( int.from_bytes(crypto.generate_random_bytes(2), byteorder='big')) tweak = str( int.from_bytes(crypto.generate_random_bytes(2), byteorder='big')) self.assertEqual( input, FPE.decrypt(key_bytes, FPE.encrypt(key_bytes, input, tweak), tweak))
def test_vector3(self): key_bytes = binascii.unhexlify('2b7e151628aed2a6abf7158809cf4f3c') input = "314159" tweak = "2718281828" expected_result = "535005" self.assertEqual(expected_result, FPE.encrypt(key_bytes, input, tweak))
def test_vector2(self): key_bytes = binascii.unhexlify('2b7e151628aed2a6abf7158809cf4f3c') input = "0123456789" tweak = "" expected_result = "2433477484" self.assertEqual(expected_result, FPE.encrypt(key_bytes, input, tweak))
def test_vector1(self): key_bytes = binascii.unhexlify('2b7e151628aed2a6abf7158809cf4f3c') input = "0123456789" tweak = "9876543210" expected_result = "6124200773" self.assertEqual(expected_result, FPE.encrypt(key_bytes, input, tweak))
import fpe as fpe import crypto as crypto for i in range(0, 100000): key_bytes = crypto.generate_random_bytes(16) input = int.from_bytes(crypto.generate_random_bytes(4), byteorder='big') tweak = int.from_bytes(crypto.generate_random_bytes(4), byteorder='big') cipher = fpe.encrypt(key_bytes, input, tweak) deciphered = fpe.decrypt(key_bytes, cipher, tweak)