def get_LargeRandomNumber(disp):

	'''Initially set all the bits to 0'''
	p = '0'*(bitInteger)
	list_p = list(p)

	'''Set the last bit to 1 to ensure that the number is odd thus a possible prime'''
	list_p[bitInteger-1] = '1'

	'''Set the first bit (or 25th bit) to 1 ensure that the number is large'''
	list_p[bitInteger-lengthPrime] = '1'

	frameinfo = getframeinfo(currentframe())
	if disp:
		print "Bit: 0 set as 1"

	'''Randomly pick the other bits from 2-6' to be 0 or 1'''
	for i in range(bitInteger-lengthPrime+1, bitInteger-1):
		'''num is the psuedorandom number generated
		and list_p[i] is the LSB of num'''
		(num, list_p[i]) =  get_RandomBit()
		
		if disp:
			print "Bit:",(i-(bitInteger-lengthPrime)), "number ", num, "extracts ", list_p[i]
		
	p = "".join(list_p)
	if disp:
		print "Bit: 6 set as 1"
		print "Number is ",int(p[bitInteger-lengthPrime:],2), "-",p,'\n'
	return p
Ejemplo n.º 2
0
print "s = %d\n"%s_int

'''Now Alice and Bob cooperatively pick a random number u'''
'''Set all the bits of u until k to 0'''
frameinfo = getframeinfo(currentframe())
print 'line:',frameinfo.lineno+2
list_u = ['0']*length
for i in range(0,length+1-k):
	list_u[i] = '0'

'''Set the k+1 bit of u to 1'''
list_u[length+1-k] = '1'

'''Generate random bits for the rest of the remaning bits in u'''
for i in range(length+2-k,length):
	(x,list_u[i]) = get_RandomBit()
u = "".join(list_u)

'''Computing the decimal value of u'''
u_int = int(u,2)

'''Printing all the values computed until now'''
print "k = %d, u = %d\n" % (k,u_int)
frameinfo = getframeinfo(currentframe())
print 'line:',frameinfo.lineno+2
print "u = "+u+"\n"

'''Both Alice and Bob compute hash of u'''
frameinfo = getframeinfo(currentframe())
print 'line:',frameinfo.lineno+2
hu = hashfun(u)