def _generate_prime(bits, rng):
hbyte_mask = pow(<NUM_LIT:2>, bits % <NUM_LIT:8>) - <NUM_LIT:1><EOL>while True:<EOL><INDENT>x = rng.read((bits+<NUM_LIT:7>) // <NUM_LIT:8>)<EOL>if hbyte_mask > <NUM_LIT:0>:<EOL><INDENT>x = chr(ord(x[<NUM_LIT:0>]) & hbyte_mask) + x[<NUM_LIT:1>:]<EOL><DEDENT>n = util.inflate_long(x, <NUM_LIT:1>)<EOL>n |= <NUM_LIT:1><EOL>n |= (<NUM_LIT:1> << (bits - <NUM_LIT:1>))<EOL>while not number.isPrime(n):<EOL><INDENT>n += <NUM_LIT:2><EOL><DEDENT>if util.bit_length(n) == bits:<EOL><INDENT>break<EOL><DEDENT><DEDENT>return n<EOL>
primtive attempt at prime generation