defrabin_random_bit_generator(): # Choose two prime numbers p = 61 q = 53 n = p * q # Calculate the product of the two prime numbers x = random.randint(1, n-1) # Generate a random number x returnbin((x**2) % n)[2:] # Return the result of x^2 mod n in binary format
# Test function deftest_rabin_random_bit_generator(): # Generate 10 random bits using the Rabin random bit generator generated_bits = [rabin_random_bit_generator() for _ inrange(10)] print(generated_bits) # Print the generated random bits
test_rabin_random_bit_generator() # Call the test function
版本二:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
import random
defrabin_random_bit_generator(): # Choose two prime numbers p = 61 q = 53 n = p * q # Calculate the product of the two prime numbers x = random.randint(1, n-1) # Generate a random number x returnbin((x**2) % n)[2:] # Return the result of x^2 mod n in binary format
# Test function deftest_rabin_random_bit_generator(): # Generate 10 random bits using the Rabin random bit generator generated_bits = [rabin_random_bit_generator() for _ inrange(10)] print(generated_bits) # Print the generated random bits
test_rabin_random_bit_generator() # Call the test function