示例#1
0
def test_permutation():
    from cryptanalysis import summarize_sbox
    sbox = list()
    for value in range(256):
        sbox.append(permutation(value))
        print format(sbox[-1], 'b').zfill(80)[:79]
    #import pprint
    #pprint.pprint([format(word, 'b').zfill(128) for word in sbox])
    summarize_sbox([word & 255 for word in sbox])
示例#2
0
def collision_test(hash_function):
    for index in range(20):
        sbox = []
        for byte in range(256):
            _input = bytearray(20)
            _input[index] = byte
            sbox.append(ord(hash_function(_input)[index]))

        cryptanalysis.summarize_sbox(sbox)
示例#3
0
def collision_test(hash_function):
    for index in range(20):
        sbox = []
        for byte in range(256):
            _input = bytearray(20)
            _input[index] = byte
            sbox.append(ord(hash_function(_input)[index]))
        
        cryptanalysis.summarize_sbox(sbox)
示例#4
0
def test_permutation():
    from cryptanalysis import summarize_sbox
    sbox = list()
    for value in range(256):
        sbox.append(permutation(value))
        print format(sbox[-1], 'b').zfill(80)[:79]
    #import pprint
    #pprint.pprint([format(word, 'b').zfill(128) for word in sbox])
    summarize_sbox([word & 255 for word in sbox])
示例#5
0
def test_choice(): 
    
    sbox = {(_input, choice(*_input)) for _input in (tuple(bytearray(integer_to_bytes(integer, 3))) for integer in xrange(2 ** 24))}
    print "Done "
    with open("choice_sbox.txt", 'w') as _file:
        _file.write(pprint.pformat(sbox))
   # for integer in range(2 ** 24):
   #     _input = tuple(bytearray(integer_to_bytes(integer, 3)))
   #     sbox[_input] = choice(*_input)
    
    summarize_sbox(sbox)
示例#6
0
def test_choice():

    sbox = {(_input, choice(*_input))
            for _input in (tuple(bytearray(integer_to_bytes(integer, 3)))
                           for integer in xrange(2**24))}
    print "Done "
    with open("choice_sbox.txt", 'w') as _file:
        _file.write(pprint.pformat(sbox))

# for integer in range(2 ** 24):
#     _input = tuple(bytearray(integer_to_bytes(integer, 3)))
#     sbox[_input] = choice(*_input)

    summarize_sbox(sbox)
示例#7
0
def test_sub_sboxes(permutation, argument_function, output_function):    
    sboxes = dict()
    for sbox_entry in range(256):                              
        output = output_function(permutation(*argument_function(sbox_entry)))        
        for shift in reversed(range(0, 128, 8)):    
            try:
                sboxes[shift].append((output >> shift) & 255)                    
            except KeyError:                    
                sboxes[shift] = bytearray()
                sboxes[shift].append((output >> shift) & 255)
            
    from cryptanalysis import summarize_sbox
   # print sboxes.values()
    for shift in sorted(sboxes.keys()):    
        sbox = sboxes[shift]
        print("\nSbox size: {}/{}".format(len(set(sbox)), len(sbox)))
        print("Subsection index: {}".format(shift / 8))
        summarize_sbox(sbox)
示例#8
0
def test_sub_sboxes():    
    sboxes = dict()
    for sbox_entry in range(256):                              
        output = permutation(sbox_entry)
        print format(output, 'b').zfill(128)
        for shift in reversed(range(0, 128, 8)):    
            try:
                sboxes[shift].append((output >> shift) & 255)                    
            except KeyError:                    
                sboxes[shift] = bytearray()
                sboxes[shift].append((output >> shift) & 255)
            
    from cryptanalysis import summarize_sbox
   # print sboxes.values()
    for shift in sorted(sboxes.keys()):    
        sbox = sboxes[shift]
        print("\nSbox size: {}".format(len(set(sbox))))
        print("Subsection index: {}".format(shift / 8))
        summarize_sbox(sbox)
示例#9
0
def test_round_differentials():
    rounds = 2
    sboxes = dict()
    for sbox_entry in range(256):
        a, b, c, d = 0, 0, 0, sbox_entry                          
        for round in range(rounds):
            a, b, c, d = _test_mixer(a, b, c, d)
        
        
        #print format(d, 'b').zfill(64)        
        for word in "abcd":
            for shift in reversed(range(0, 64, 8)): 
                _word = locals()[word]
                try:
                    sboxes[(word, shift)].append((_word >> shift) & 255)                    
                except KeyError:                                        
                    sboxes[(word, shift)] = bytearray()
                    sboxes[(word, shift)].append((_word >> shift) & 255)
                
    from cryptanalysis import summarize_sbox
    
    for sbox in sboxes.values():                
        #print type(sbox), len(sbox), sbox
        summarize_sbox(sbox)
示例#10
0
def test_63_exp_N_mod_257_sbox():
    sbox = [pow(63, number, 257) % 256 for number in range(256)]
    from cryptanalysis import summarize_sbox
    summarize_sbox(sbox)