diff options
author | adamantike <mike@fmanganiello.com.ar> | 2016-03-17 11:06:44 +0100 |
---|---|---|
committer | Sybren A. Stüvel <sybren@stuvel.eu> | 2016-03-17 11:07:48 +0100 |
commit | 5f4b7b331f6b2606afcdd951830368f9ccaad6e2 (patch) | |
tree | c0983b5e219af2e6e93bd9378fb3398c56a29542 /rsa/randnum.py | |
parent | 527e3cae602db7d4576bfebdb90bc2b53916bf68 (diff) | |
download | rsa-git-5f4b7b331f6b2606afcdd951830368f9ccaad6e2.tar.gz |
Use specific function for odd integer generation
Diffstat (limited to 'rsa/randnum.py')
-rw-r--r-- | rsa/randnum.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/rsa/randnum.py b/rsa/randnum.py index 12a6757..3c788a5 100644 --- a/rsa/randnum.py +++ b/rsa/randnum.py @@ -59,6 +59,19 @@ def read_random_int(nbits): return value +def read_random_odd_int(nbits): + """Reads a random odd integer of approximately nbits bits. + + >>> read_random_odd_int(512) & 1 + 1 + """ + + value = read_random_int(nbits) + + # Make sure it's odd + return value | 1 + + def randint(maxvalue): """Returns a random integer x with 1 <= x <= maxvalue |