Example #1
0
def test():	
	plain_text = 26559
	key = 1960966
	print "plain_text:", bits_ops.full_bin( plain_text, cfg.BLOCK_SIZE )
	cipher_text = encrypt( plain_text, key ) 
	print "cipher_text:", bits_ops.full_bin( cipher_text, cfg.BLOCK_SIZE )
	print "plain_text( after decrypt ):", bits_ops.full_bin( decrypt( cipher_text, key ), cfg.BLOCK_SIZE )
	return
Example #2
0
def main():
	print "Try to search characteristic..."
	search_result = sc.search()
	print "DONE!\n"
	print "Try to search keys..."
	keys = sk.search( search_result )
	print "DONE!"
	print "Try to search right key..."
	key = sk.search_right_key( keys )
	print "DONE!"
	print "Right key is", bops.full_bin( key, cfg.KEY_SIZE )
Example #3
0
def search_right_key( keys ):
	infoXL, infoXR, infoYL, infoYR = get_correct_texts( conf.FILENAME_COR_TEXTS )

	plain_text = ( infoXL[ 0 ][ 0 ] << conf.HALF_BLOCK_SIZE ) | ( infoXR[ 0 ][ 0 ] )
	cipher_text = ( infoYL[ 0 ][ 0 ] << conf.HALF_BLOCK_SIZE ) | ( infoYR[ 0 ][ 0 ] )
	
	result_key = 0
	for current_key in  keys:
		current_cipher_text = algorithm.encrypt( plain_text, current_key )
		if current_cipher_text == cipher_text:
			result_key = current_key
			print "result_key =", bits_ops.full_bin( result_key, conf.KEY_SIZE )
	if result_key == 0:
		print "Can't find right key!"

	return result_key
Example #4
0
def search_right_key( text ):
	key = 0
	possible_keys = list()
	print "Please, input key's bits:"
	for i in range( cfg.KEY_SIZE ):
		print "K" + str( i + 1 ) + ":",
		current_bit = raw_input()
		possible_keys = add_bit_in_possible_keys( current_bit, i + 1, possible_keys )
	
	plain_text, cipher_text = text

	print len( possible_keys )

	for current_key in possible_keys:
			current_cipher_text = algorithm.encrypt( plain_text, current_key )
			if current_cipher_text == cipher_text:
				key = current_key
				print "result key:", bops.full_bin( key, cfg.KEY_SIZE)
	return key
Example #5
0
def main():
	statistics = ss.search()
	analogs = sa.search( statistics )
	equations = ske.search( analogs )

	print "Keys Equations:"
	for i in equations:
		for j in range( len( i[ 0 ] ) ):
			print "K" + str( i[ 0 ][ j ] ),
			if j != len( i[ 0 ] ) - 1:
				print "+",
		print "= " + str( i[ 1 ] )

	texts = ske.get_texts( cfg.FILENAME_COR_TEXTS )

	key = bops.full_bin( skey.search_right_key( texts[ 0 ] ), cfg.KEY_SIZE )
	print "Key is:", key

	return
Example #6
0
def search():
	f_block = Block_Internal( 1 )
	s_block = Block_Internal( 2 ) 
	t_block = Block_Internal( 3 )

	print "Print substitution blocks:"
	f_block.print_block()
	s_block.print_block()
	t_block.print_block()
	print

	print "Print A dependence of substitution blocks:"
	print "a_output of 1 block:", f_block.a_output
	print "a_output of 2 block:", s_block.a_output
	print "a_output of 3 block:", t_block.a_output
	print

	print "Build and print diff_table:"
	f_block.build_diff_table()
	f_block.print_diff_table()
	s_block.build_diff_table()
	s_block.print_diff_table()
	t_block.build_diff_table()
	t_block.print_diff_table()
	print

	print "Eval and print maximum of diff_tables:"
	f_block_max = list()
	s_block_max = list()
	t_block_max = list()
	f_block_max = f_block.max_in_diff_table()
	print "First block Maximum:", f_block_max
	s_block_max = s_block.max_in_diff_table()
	print "Second block Maximum:", s_block_max
	t_block_max = t_block.max_in_diff_table()
	print "Third block Maximum:", t_block_max
	print

	print"Build permutation blocks:"
	E_perm = Permutation( "E" )
	P_perm = Permutation( "P" )
	print "E-permutation:"
	print "DIRECT"
	print E_perm.direct
	print "INVERSE"
	print E_perm.inverse
	print "P-permutation:"
	print "DIRECT"
	print P_perm.direct
	print "INVERSE"
	print P_perm.inverse
	print

	variants = list()
	variants.append( list( f_block_max ) )
	variants.append( list( s_block_max ) )
	variants.append( list( t_block_max ) )
	print "variants:", variants
	valid = search_valid_bits( variants, E_perm.inverse )
	print "valid bits:", valid
	
	if valid == []:
		print "Cant't search valid bits!"
		return -1
	dA = ( valid[ 0 ][ 0 ] << 8 ) | ( valid[ 1 ][ 0 ] << 4 ) | ( valid[ 2 ][ 0 ] )
	dC = ( valid[ 0 ][ 1 ] << 5 ) | ( valid[ 1 ][ 1 ] << 2 ) | ( valid[ 2 ][ 1 ] )
	print "dA =", bin( dA ), " dC =", bin( dC )
	dXR = E_perm.make_permutation( dA, -1 )
	dXL = P_perm.make_permutation( dC, 1 )
	print "Characteristic:"
	print "dXR ( dYR ) =", bops.full_bin( dXR, cfg.HALF_BLOCK_SIZE ), " dXL =", bops.full_bin( dXL, cfg.HALF_BLOCK_SIZE )

	return f_block, s_block, t_block, E_perm, P_perm