Ejemplo n.º 1
0
    def testPtxtPowerOf2(self):
        """Due to Issue#5"""
        plain = ffx.FFXInteger('0000065536', radix=10)
        tweak = ffx.FFXInteger('0000000000', radix=10)
        key = ffx.FFXInteger('2b7e151628aed2a6abf7158809cf4f3c', radix=16, blocksize=32)

        ffx_obj = ffx.new(key.to_bytes(16), radix=10)
        ctxt = ffx_obj.encrypt(tweak, plain)
        self.assertEqual(ffx_obj.decrypt(tweak, ctxt), plain)
Ejemplo n.º 2
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--radix", type=int, default=2)
    parser.add_argument("--tweaksize", type=int, default=8)
    parser.add_argument("--messagesize", type=int, default=32)
    parser.add_argument("--trials", type=int, default=10, required=False)
    args = parser.parse_args()

    radix = args.radix
    tweaksize = args.tweaksize
    messagesize = args.messagesize
    trials = args.trials

    keysize = 128
    K = random.randint(0, 2 ** keysize - 1)
    K = FFXInteger(K, radix=2, blocksize=keysize)

    print(
        'RADIX={}, TWEAKSIZE={}, MESSAGESIZE={}, KEY={:x}'.format(
            radix,
            tweaksize,
            messagesize,
            K.to_int()
        )
    )

    ffx_obj = ffx.new(K.to_bytes(), radix)
    for i in range(1, trials):
        T = random.randint(0, radix ** tweaksize - 1)
        T = FFXInteger(T, radix=radix, blocksize=tweaksize)

        M1 = random.randint(0, radix ** messagesize - 1)
        M1 = FFXInteger(M1, radix=radix, blocksize=messagesize)

        start = time.time()
        C = ffx_obj.encrypt(T, M1)
        encrypt_cost = time.time() - start
        encrypt_cost *= 1000.0

        start = time.time()
        M2 = ffx_obj.decrypt(T, C)
        decrypt_cost = time.time() - start
        decrypt_cost *= 1000.0

        assert M1 == M2

        print(
            'test #{} SUCCESS: (encrypt_cost={} ms, decrypt_cost={} ms, tweak={}, plaintext={}, ciphertext={})'.format(
                i,
                round(encrypt_cost, 1),
                round(decrypt_cost, 1),
                T,
                M1,
                C,
            )
        )
Ejemplo n.º 3
0
    def testFFXEncrypt1(self):
        radix = 2
        K = FFXInteger('0' * 8, radix=radix, blocksize=128)
        T = FFXInteger('0' * 8, radix=radix, blocksize=8)
        M1 = FFXInteger('0' * 8, radix=radix, blocksize=8)

        ffx_obj = ffx.new(K.to_bytes(16), radix)
        C = ffx_obj.encrypt(T, M1)
        M2 = ffx_obj.decrypt(T, C)

        self.assertEqual(M1, M2)
Ejemplo n.º 4
0
    def testFFXEncrypt1(self):
        radix = 2
        K = FFXInteger('0' * 8, radix=radix, blocksize=128)
        T = FFXInteger('0' * 8, radix=radix, blocksize=8)
        M1 = FFXInteger('0' * 8, radix=radix, blocksize=8)

        ffx_obj = ffx.new(K.to_bytes(16), radix)
        C = ffx_obj.encrypt(T, M1)
        M2 = ffx_obj.decrypt(T, C)

        self.assertEquals(M1, M2)
Ejemplo n.º 5
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--radix", type=int, default=2)
    parser.add_argument("--tweaksize", type=int, default=8)
    parser.add_argument("--messagesize", type=int, default=32)
    parser.add_argument("--trials", type=int, default=10, required=False)
    args = parser.parse_args()

    radix = args.radix
    tweaksize = args.tweaksize
    messagesize = args.messagesize
    trials = args.trials

    keysize = 128
    K = random.randint(0, 2**keysize - 1)
    K = FFXInteger(K, radix=2, blocksize=keysize)

    banner = [
        'RADIX=' + str(radix), 'TWEAKSIZE=' + str(tweaksize),
        'MESSAGESIZE=' + str(messagesize), 'KEY=' + hex(K.to_int())
    ]
    print ', '.join(banner)

    ffx_obj = ffx.new(K.to_bytes(), radix)
    for i in range(1, trials):
        T = random.randint(0, radix**tweaksize - 1)
        T = FFXInteger(T, radix=radix, blocksize=tweaksize)

        M1 = random.randint(0, radix**messagesize - 1)
        M1 = FFXInteger(M1, radix=radix, blocksize=messagesize)

        start = time.time()
        C = ffx_obj.encrypt(T, M1)
        encrypt_cost = time.time() - start
        encrypt_cost *= 1000.0

        start = time.time()
        M2 = ffx_obj.decrypt(T, C)
        decrypt_cost = time.time() - start
        decrypt_cost *= 1000.0

        assert M1 == M2

        to_print = [
            'encrypt_cost=' + str(round(encrypt_cost, 1)) + 'ms',
            'decrypt_cost=' + str(round(decrypt_cost, 1)) + 'ms',
            'tweak=' + str(T),
            'plaintext=' + str(M1),
            'ciphertext=' + str(C),
        ]
        print 'test #' + string.rjust(str(i), len(
            str(trials - 1)), '0') + ' SUCCESS: (' + ', '.join(to_print) + ')'
Ejemplo n.º 6
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--radix", type=int, default=2)
    parser.add_argument("--tweaksize", type=int, default=8)
    parser.add_argument("--messagesize", type=int, default=32)
    parser.add_argument("--trials", type=int, default=10, required=False)
    args = parser.parse_args()

    radix = args.radix
    tweaksize = args.tweaksize
    messagesize = args.messagesize
    trials = args.trials

    keysize = 128
    K = random.randint(0, 2 ** keysize - 1)
    K = FFXInteger(K, radix=2, blocksize=keysize)

    banner = ['RADIX=' + str(radix),
              'TWEAKSIZE=' + str(tweaksize),
              'MESSAGESIZE=' + str(messagesize),
              'KEY=' + hex(K.to_int())
              ]
    print ', '.join(banner)

    ffx_obj = ffx.new(K.to_bytes(), radix)
    for i in range(1, trials):
        T = random.randint(0, radix ** tweaksize - 1)
        T = FFXInteger(T, radix=radix, blocksize=tweaksize)

        M1 = random.randint(0, radix ** messagesize - 1)
        M1 = FFXInteger(M1, radix=radix, blocksize=messagesize) 

        start = time.time()
        C = ffx_obj.encrypt(T, M1)
        encrypt_cost = time.time() - start
        encrypt_cost *= 1000.0

        start = time.time()
        M2 = ffx_obj.decrypt(T, C)
        decrypt_cost = time.time() - start
        decrypt_cost *= 1000.0

        assert M1 == M2

        to_print = ['encrypt_cost=' + str(round(encrypt_cost, 1)) + 'ms',
                    'decrypt_cost=' + str(round(decrypt_cost, 1)) + 'ms',
                    'tweak=' + str(T),
                    'plaintext=' + str(M1),
                    'ciphertext=' + str(C),
                    ]
        print 'test #' + string.rjust(str(i), len(str(trials - 1)), '0') + ' SUCCESS: (' + ', '.join(to_print) + ')'
Ejemplo n.º 7
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--radix", type=int, default=2)
    parser.add_argument("--tweaksize", type=int, default=8)
    parser.add_argument("--messagesize", type=int, default=32)
    parser.add_argument("--trials", type=int, default=10, required=False)
    args = parser.parse_args()

    radix = args.radix
    tweaksize = args.tweaksize
    messagesize = args.messagesize
    trials = args.trials

    keysize = 128
    K = random.randint(0, 2**keysize - 1)
    K = FFXInteger(K, radix=2, blocksize=keysize)

    print('RADIX={}, TWEAKSIZE={}, MESSAGESIZE={}, KEY={:x}'.format(
        radix, tweaksize, messagesize, K.to_int()))

    ffx_obj = ffx.new(K.to_bytes(), radix)
    for i in range(1, trials):
        T = random.randint(0, radix**tweaksize - 1)
        T = FFXInteger(T, radix=radix, blocksize=tweaksize)

        M1 = random.randint(0, radix**messagesize - 1)
        M1 = FFXInteger(M1, radix=radix, blocksize=messagesize)

        start = time.time()
        C = ffx_obj.encrypt(T, M1)
        encrypt_cost = time.time() - start
        encrypt_cost *= 1000.0

        start = time.time()
        M2 = ffx_obj.decrypt(T, C)
        decrypt_cost = time.time() - start
        decrypt_cost *= 1000.0

        assert M1 == M2

        print(
            'test #{} SUCCESS: (encrypt_cost={} ms, decrypt_cost={} ms, tweak={}, plaintext={}, ciphertext={})'
            .format(
                i,
                round(encrypt_cost, 1),
                round(decrypt_cost, 1),
                T,
                M1,
                C,
            ))
Ejemplo n.º 8
0
    def testOverflowErrorDueToDataSize(self):
        radix = 36
        K = FFXInteger('1868ea98ae122d5cd15f1802c0b37d75',
                       radix=radix, blocksize=32)
        T = 0  # FFXInteger(0, radix=radix, blocksize=2)
        M1 = FFXInteger('qstgmuxnvxfukxrnotryuxlvdtrssxjkmtnaztbpsuwrtzdcyunguedvdlkxtxxhtghyzvhxetbjuxtfrxrktmxrvfziblzpyxyzlxpvwmtmqxfxbugxuuhpnxfvqxpxtxnkqvdvouxzbwvxskjxogrvbmxkuelfvgltnmrpcxswvmvlykxubhdselmxaddemlrvvxlkshkrkzvmtutbyljvvngvcxruwdvqsixvturfrkjlwexywsxcujmxzwtitxxxyjbptlpwrwrxslzzoxjqodnunmexqjewbgsxqnuysfvkznyxuxhrcuxqruptbghrullgmmvpwctannhpvzzqzxlwbhrfwhltrdvvzuxomxpcswsztdnadnjsztlobhldbexccgxkwdixaufxrxnvumkrsxpotgwxcxhwnnrsuevdrvjimllgmzexekzwvuxjazdysgsroepkzxvhuwmxnlrbkzvvzxjnrmlpunbxadjurgnyyufpmwjokxrtutlzbefstxnlnjdxwwfnzxxoywxjttbawjfbdxdrmxjkqxuxvkwxmuxpwefmnkxxndnkvedwtlzsamzhunuxuwyxtxrxtxlfbkdhnvbiandddfzhzxvutxvxyuhldnbsyvfqmkcyanhzttndyktqdhrlbthxkyxxakdwudvxcexxvtdfaxfjzuhoslpemnyxyvrxvdlibjnqewvvvxzfdwmxujjxofdbtwpsvhvxwkhxemlxtxhxrmjhwerztxizaxtjrcxzdxgxthbhsxerdxzqzmxibepqyjjxmfnjrmruvxnntvhykxdxnmkxeklmzzvnefdkugfhzxlxrtlnqxludyxnuljkrwuxyzllmzrrmxfxqxrnswncwtzrymfqdxnqzwpnwjcxcfvxmekrsfpmcwdxujixwmxuznhltghtohbeeffhskzxynhcuwnkuxlxyxixdzhryvhzagfjouxtrxlxouxaqnvrdkiwuhrfzxzftupswgmxkxrjdxbstxewkxvxztdiuhvlaxplqxpcvtbirmxwmfjlzlpbaxmylxjlzxdxefhtzmjootaxqxhqvffxvyxtqxorduxnzunfudrpqsxrnkrubdvxvxqxewfvsxdrdndywuxkwluxosxtsxdtndeycwfsrfrrodhvuvlxuuxvotdsahvinmxosentvursdgjxnxzxwfryzuixvdqxbkzuugrorkxzwuxhbmhsrjhkzkflthvwvkxxyxprcnbhazbswuxxajbonxnywwzxaxdmwljoanfnmkdxotuxbexrzkmxzhrnegxotkrtuxbocxrgevpwbexqbvdpevyxrfuwuzjfnwxkmnixbxdxmhbxrmxuqxdtkzzladhtznmxthzpcxlsouxxzkxsukuzdmvutxvlrklvencxauxltnpqvxpcdjjenjvtbljidwlbsuhuvujnqmpyrnhcduxnnghbmwxrcdbenjhkbitgderuenkreddnzzrnuxltmnexzxvvnxzauxnpcgpxzxdmslzsrlzuynrlsxcxevpyrxrnynnnvxmxwhpxdtaxmhppckexamfjsnyxyytzylnxtxxxvxxblxhtegzxbxzuzcsxmuxwvhcruytuqznesgfxskvkrcxiqmdluxixcvqxetzduxxxlzgvuvbjmctxcwtwmyxedfjxderpzlexnvgwbmxczejccgniuxffqsszkxjutuxjallkyxryvnfjmkqxwstmunmxlxfxumfvqvpzukjxumxxcdvzznjybmrvenfsmkqyavphlxtxzwfrrlovcjburyxwcvrodxnlznzjukxkagvqwwvmylvvcxhzcnvztmxxvupmemfwdhluuuxxmlgzawttcljacdbnuxpwzljxrlrmnzhobxoxzuvelxxienhpmfdxmejedxdxruvwajurtuxwcmlxaxfkbmhyuzzanzniyxnxsulrvupzcnrbdmfothrnmixttlftdthxunlyrdfptixbmxgxwghrowixthhdaixjofzlwluysxrryxjsrxrfyuixsljxbvvnqkprdxnyzctnrxdjnenqsxtzbxlxnhextctiulbldwxxzzrydxxidufkzudstxthtxflbxmzbzmxaxpwcxzlestyuffnduxbrwjmtkhjbsxzvuxfvuxqvndhsgszvexxmuxxsisxdzrjwwvwmzvhafvrmdrktxgyrfdztwtxddnxczmxevvcwursyxfyatdwtthxmudoefviwxbmqxdlrvnkuxxoynvjmzljoulhwfzrqvrpqtfwovirtxdubvrtqkttbjeybxxywehyczhwzxfgdvvkowporkvxddrdrktjndnesmfrvmthbglztgdxagjomnluyzrlymhxbxfhlxvlumxwblpkakxzcjhmdvdqywyvdehmkzqxcxrrkxpxeunwugxrdljnqnzaumyvutvgztbkwhbxsnnncfpwwvpnshddyzbwukprenvktyxytglsmvbqajgxrxrxewxxejevdnzrwvmrwxjxumuzmdlssnrxrxlpqkpxaxwxchyxmnkzzxttrhayrgnxsljxkxmxtxjbrnovalzxwmtpemlvnxxfdthxbljpzxdrmxursgzzytncdmxsyxnfnthrtdfnefqxtgxxbnbpstdzaxqxbitjyuvpbxsxawhxqulirfntzxixvdzrnvjlaffxrxfllzqzmysxucxtyxdqqkxxyxrkswvhyxlvcxplzmlsmgtsovrzthrxuzmxbtbvvxhsetnzaenuykxfzuzxuezlegvsszrlzxxazuxvogrczgjfmxpmuxvsnixyukwynetxeghgwfexazqxqxyxnufmotnhrxzqyithwwxiaxzomxnbnxxsztzgcknqlxlodxlewuxxcxlioghwaxddugxrzhbzvxnzngdecgvisxxmkxlqnxyvaepxsxnptxnfeutpnkvvrthrskxowxiwwkxxegxndzhuclixrwxvynpenjixrxwxdmxzqlferdfxyjhtefnxzvnx', radix=radix, blocksize=3072)

        ffx_obj = ffx.new(K.to_bytes(16), radix)
        C = ffx_obj.encrypt(T, M1)
        M2 = ffx_obj.decrypt(T, C)

        self.assertEqual(M1, M2)

        print('')
        print('TEST VECTOR: radix=' + str(radix) + ', input=' + str(M1) + ', tweak=' + str(T) + ', encrypted=' + str(C))
Ejemplo n.º 9
0
    def testValueErrorDueToBlockSize(self):
        radix = 36
        K = FFXInteger('1868ea98ae122d5cd15f1802c0b37d75',
                       radix=radix, blocksize=32)
        T = 0  # FFXInteger(0, radix=radix, blocksize=2)
        M1 = FFXInteger('nuqjmul7us7dnw4euymifiyomk0p21sigolw5egtvvg', radix=radix, blocksize=43)

        ffx_obj = ffx.new(K.to_bytes(16), radix)
        C = ffx_obj.encrypt(T, M1)
        M2 = ffx_obj.decrypt(T, C)

        self.assertEqual(M1, M2)

        print('')
        print('TEST VECTOR: radix=' + str(radix) + ', input=' + str(M1) + ', tweak=' + str(T) + ', encrypted=' + str(C))
Ejemplo n.º 10
0
    def testVectorYexpansion2(self):
        radix = 16
        K = FFXInteger('0'*32,
                       radix=radix, blocksize=32)
        T = 0  # FFXInteger(0, radix=radix, blocksize=2)
        M1 = FFXInteger('0'*49, radix=radix, blocksize=49)

        ffx_obj = ffx.new(K.to_bytes(16), radix)
        C = ffx_obj.encrypt(T, M1)
        self.assertEqual(C, '1f7b9459d22b2bee17d5b5616e03241467767c9dcbc424c21')
        M2 = ffx_obj.decrypt(T, C)

        self.assertEqual(M1, M2)

        print('')
        print('TEST VECTOR: radix=' + str(radix) + ', input=' + str(M1) + ', tweak=' + str(T) + ', encrypted=' + str(C))
Ejemplo n.º 11
0
    def testVectorYexpansion1(self):
        radix = 16
        K = FFXInteger('0'*32,
                       radix=radix, blocksize=32)
        T = 0  # FFXInteger(0, radix=radix, blocksize=2)
        M1 = FFXInteger('0'*48, radix=radix, blocksize=48)

        ffx_obj = ffx.new(K.to_bytes(16), radix)
        C = ffx_obj.encrypt(T, M1)
        self.assertEqual(C, 'ddb77d3be91a8e255fca9389a3d48da2b4476919744febea')
        M2 = ffx_obj.decrypt(T, C)

        self.assertEqual(M1, M2)

        print('')
        print('TEST VECTOR: radix=' + str(radix) + ', input=' + str(M1) + ', tweak=' + str(T) + ', encrypted=' + str(C))
Ejemplo n.º 12
0
    def testVector1(self):
        # see aes-ffx-vectors.txt

        radix = 10
        K = FFXInteger('2b7e151628aed2a6abf7158809cf4f3c',
                       radix=16, blocksize=32)
        T = FFXInteger('9876543210', radix=radix, blocksize=10)
        M1 = FFXInteger('0123456789', radix=radix, blocksize=10)

        ffx_obj = ffx.new(K.to_bytes(16), radix)
        C = ffx_obj.encrypt(T, M1)
        self.assertEquals(C, '6124200773')
        M2 = ffx_obj.decrypt(T, C)

        self.assertEquals(M1, M2)

        print ''
        print 'TEST VECTOR #1: radix=' + str(radix) + ', input=' + str(M1) + ', tweak=' + str(T) + ', encrypted=' + str(C)
Ejemplo n.º 13
0
    def testVector2(self):
        # see aes-ffx-vectors.txt

        radix = 10
        K = FFXInteger('2b7e151628aed2a6abf7158809cf4f3c',
                       radix=16, blocksize=32)
        T = 0  # FFXInteger(0, radix=radix, blocksize=2)
        M1 = FFXInteger('0123456789', radix=radix, blocksize=10)

        ffx_obj = ffx.new(K.to_bytes(16), radix)
        C = ffx_obj.encrypt(T, M1)
        self.assertEqual(C, '2433477484')
        M2 = ffx_obj.decrypt(T, C)

        self.assertEqual(M1, M2)

        print('')
        print('TEST VECTOR #2: radix=' + str(radix) + ', input=' + str(M1) + ', tweak=' + str(T) + ', encrypted=' + str(C))
Ejemplo n.º 14
0
    def testVector5(self):
        # see aes-ffx-vectors.txt

        radix = 36
        K = FFXInteger('2b7e151628aed2a6abf7158809cf4f3c',
                       radix=16, blocksize=32)
        T = FFXInteger('TQF9J5QDAGSCSPB1', radix=radix, blocksize=16)
        M1 = FFXInteger('C4XPWULBM3M863JH', radix=radix, blocksize=16)

        ffx_obj = ffx.new(K.to_bytes(16), radix)
        C = ffx_obj.encrypt(T, M1)
        self.assertEqual(str(C).upper(), 'C8AQ3U846ZWH6QZP')
        M2 = ffx_obj.decrypt(T, C)

        self.assertEqual(M1, M2)

        print('')
        print('TEST VECTOR #5: radix=' + str(radix) + ', input=' + str(M1) + ', tweak=' + str(T) + ', encrypted=' + str(C))
Ejemplo n.º 15
0
    def testVector4(self):
        # see aes-ffx-vectors.txt

        radix = 10
        K = FFXInteger('2b7e151628aed2a6abf7158809cf4f3c',
                       radix=16, blocksize=32)
        T = FFXInteger('7777777', radix=radix, blocksize=7)
        M1 = FFXInteger('999999999', radix=radix, blocksize=9)

        ffx_obj = ffx.new(K.to_bytes(16), radix)
        C = ffx_obj.encrypt(T, M1)
        self.assertEqual(C, '658229573')
        M2 = ffx_obj.decrypt(T, C)

        self.assertEqual(M1, M2)

        print('')
        print('TEST VECTOR #4: radix=' + str(radix) + ', input=' + str(M1) + ', tweak=' + str(T) + ', encrypted=' + str(C))
Ejemplo n.º 16
0
    def testVector3(self):
        # see aes-ffx-vectors.txt

        radix = 10
        K = FFXInteger('2b7e151628aed2a6abf7158809cf4f3c',
                       radix=16, blocksize=32)
        T = FFXInteger('2718281828', radix=radix, blocksize=10)
        M1 = FFXInteger('314159', radix=radix, blocksize=6)

        ffx_obj = ffx.new(K.to_bytes(16), radix)
        C = ffx_obj.encrypt(T, M1)
        self.assertEqual(C, '535005')
        M2 = ffx_obj.decrypt(T, C)

        self.assertEqual(M1, M2)

        print('')
        print('TEST VECTOR #3: radix=' + str(radix) + ', input=' + str(M1) + ', tweak=' + str(T) + ', encrypted=' + str(C))
Ejemplo n.º 17
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import ffx

radix = 2
blocksize = 2**10

K = ffx.FFXInteger('0' * 128, radix=radix, blocksize=128)
T = ffx.FFXInteger('0' * blocksize, radix=radix, blocksize=blocksize)
X = ffx.FFXInteger('0' * blocksize, radix=radix, blocksize=blocksize)

ffx_obj = ffx.new(K.to_bytes(16), radix=radix)

C = ffx_obj.encrypt(T, X)
Y = ffx_obj.decrypt(T, C)

print X
print C
print Y
Ejemplo n.º 18
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import absolute_import
from __future__ import print_function
import ffx


radix = 2
blocksize = 2 ** 10

K = ffx.FFXInteger('0' * 128, radix=radix, blocksize=128)
T = ffx.FFXInteger('0' * blocksize, radix=radix, blocksize=blocksize)
X = ffx.FFXInteger('0' * blocksize, radix=radix, blocksize=blocksize)

ffx_obj = ffx.new(K.to_bytes(16), radix=radix)

C = ffx_obj.encrypt(T, X)
Y = ffx_obj.decrypt(T, C)

print(X)
print(C)
print(Y)
Ejemplo n.º 19
0
#!/usr/bin/env python# -*- coding: utf-8 -*-
import timeimport mathimport randomimport stringimport argparse
import ffx from ffx import FFXInteger

def main():    parser = argparse.ArgumentParser()    parser.add_argument("--radix", type=int, default=2)    parser.add_argument("--tweaksize", type=int, default=8)    parser.add_argument("--messagesize", type=int, default=32)    parser.add_argument("--trials", type=int, default=10, required=False)    args = parser.parse_args()
    radix = args.radix    tweaksize = args.tweaksize    messagesize = args.messagesize    trials = args.trials
    keysize = 128 K = random.randint(0, 2 ** keysize - 1) K = FFXInteger(K, radix=2, blocksize=keysize)
    banner = ['RADIX=' + str(radix), 'TWEAKSIZE=' + str(tweaksize), 'MESSAGESIZE=' + str(messagesize), 'KEY=' + hex(K.to_int())              ] print ', '.join(banner)
    ffx_obj = ffx.new(K.to_bytes(), radix) for i in range(1, trials): T = random.randint(0, radix ** tweaksize - 1) T = FFXInteger(T, radix=radix, blocksize=tweaksize)
 M1 = random.randint(0, radix ** messagesize - 1) M1 = FFXInteger(M1, radix=radix, blocksize=messagesize) 
        start = time.time() C = ffx_obj.encrypt(T, M1)        encrypt_cost = time.time() - start        encrypt_cost *= 1000.0
        start = time.time() M2 = ffx_obj.decrypt(T, C)        decrypt_cost = time.time() - start        decrypt_cost *= 1000.0
 assert M1 == M2
        to_print = ['encrypt_cost=' + str(round(encrypt_cost, 1)) + 'ms', 'decrypt_cost=' + str(round(decrypt_cost, 1)) + 'ms', 'tweak=' + str(T), 'plaintext=' + str(M1), 'ciphertext=' + str(C),                    ] print 'test #' + string.rjust(str(i), len(str(trials - 1)), '0') + ' SUCCESS: (' + ', '.join(to_print) + ')'

if __name__ == "__main__":    main()