def generate_probable_safe_prime(**kwargs):
 exact_bits = kwargs.pop('exact_bits', None)
 randfunc = kwargs.pop('randfunc', None)
 if kwargs:
  print 'Unknown parameters:', kwargs.keys()
 if (randfunc is None):
  randfunc = Random.new().read
 result = COMPOSITE
 while (result == COMPOSITE):
  q = generate_probable_prime(exact_bits=(exact_bits - 1), randfunc=randfunc)
  candidate = ((q * 2) + 1)
  if (candidate.size_in_bits() != exact_bits):
   continue
  result = test_probable_prime(candidate, randfunc=randfunc)
 return candidate

def generate_probable_safe_prime ( ** kwargs ) : exact_bits = kwargs . pop ( 'exact_bits' , None ) randfunc = kwargs . pop ( 'randfunc' , None ) if kwargs : print 'Unknown parameters:' , kwargs . keys ( ) if ( randfunc is None ) : randfunc = Random . new ( ) . read result = COMPOSITE while ( result == COMPOSITE ) : q = generate_probable_prime ( exact_bits = ( exact_bits - 1 ) , randfunc = randfunc ) candidate = ( ( q * 2 ) + 1 ) if ( candidate . size_in_bits ( ) != exact_bits ) : continue result = test_probable_prime ( candidate , randfunc = randfunc ) return candidate
generate a random .