Exemplo n.º 1
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,
            )
        )
Exemplo n.º 2
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)
Exemplo 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)
Exemplo n.º 4
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) + ')'
Exemplo n.º 5
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))
Exemplo n.º 6
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))
Exemplo n.º 7
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))
Exemplo n.º 8
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))
Exemplo n.º 9
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))
Exemplo n.º 10
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))
Exemplo n.º 11
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))
Exemplo n.º 12
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))
Exemplo n.º 13
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)
Exemplo n.º 14
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) + ')'
Exemplo n.º 15
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,
            ))
Exemplo n.º 16
0
    def testFFXInteger4(self):
        X = FFXInteger('000')

        self.assertEqual(X.to_bytes(), six.b('\x00'))
Exemplo n.º 17
0
 def testFFXInteger3(self):
     for blocksize in range(1, 129):
         X = FFXInteger('0', radix=2, blocksize=blocksize)
         self.assertEquals(len(X), blocksize)
Exemplo n.º 18
0
    def testFFXInteger4(self):
        X = FFXInteger('000')

        self.assertEquals(X.to_bytes(), '\x00')
Exemplo n.º 19
0
    def testFFXInteger5(self):
        X = FFXInteger('11111111')

        self.assertEquals(X.to_bytes(), '\xFF')
Exemplo n.º 20
0
    def testFFXInteger6(self):
        X = FFXInteger('FF', radix=16)

        self.assertEquals(X.to_bytes(), '\xFF')
Exemplo n.º 21
0
    def testFFXInteger3(self):
        X = FFXInteger('000')
        Y = FFXInteger('111')

        self.assertEquals(str(X) + str(Y), '000111')
Exemplo n.º 22
0
    def testFFXInteger4(self):
        X = FFXInteger('000')

        self.assertEquals(X.to_bytes(), '\x00')
Exemplo n.º 23
0
    def testFFXInteger2(self):
        X = FFXInteger('000')
        Y = FFXInteger('111')

        self.assertEquals(X + Y, 7)
        self.assertEquals(X + Y, FFXInteger('111'))
Exemplo n.º 24
0
    def testFFXInteger1(self):
        X = FFXInteger('1')
        Y = FFXInteger('1')

        self.assertEquals(X + Y, 2)
        self.assertEquals(X + Y, FFXInteger('10'))
Exemplo n.º 25
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()
Exemplo n.º 26
0
    def testFFXInteger5(self):
        X = FFXInteger('11111111')

        self.assertEqual(X.to_bytes(), six.b('\xFF'))
Exemplo n.º 27
0
    def testFFXInteger6(self):
        X = FFXInteger('FF', radix=16)

        self.assertEqual(X.to_bytes(), six.b('\xFF'))