OXIESEC PANEL
- Current Dir:
/
/
opt
/
gsutil
/
third_party
/
rsa
/
rsa
/
__pycache__
Server IP: 2a02:4780:11:1594:0:ef5:22d7:a
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
02/11/2025 08:19:48 AM
rwxr-xr-x
📄
__init__.cpython-39.pyc
1 KB
02/11/2025 08:19:48 AM
rw-r--r--
📄
_compat.cpython-39.pyc
3.71 KB
02/11/2025 08:19:48 AM
rw-r--r--
📄
common.cpython-39.pyc
3.86 KB
02/11/2025 08:19:48 AM
rw-r--r--
📄
core.cpython-39.pyc
1.18 KB
02/11/2025 08:19:48 AM
rw-r--r--
📄
key.cpython-39.pyc
22.54 KB
02/11/2025 08:19:48 AM
rw-r--r--
📄
machine_size.cpython-39.pyc
1.37 KB
02/11/2025 08:19:48 AM
rw-r--r--
📄
pem.cpython-39.pyc
2.29 KB
02/11/2025 08:19:48 AM
rw-r--r--
📄
pkcs1.cpython-39.pyc
11.44 KB
02/11/2025 08:19:48 AM
rw-r--r--
📄
prime.cpython-39.pyc
3.63 KB
02/11/2025 08:19:48 AM
rw-r--r--
📄
randnum.cpython-39.pyc
1.64 KB
02/11/2025 08:19:48 AM
rw-r--r--
📄
transform.cpython-39.pyc
4.89 KB
02/11/2025 08:19:48 AM
rw-r--r--
Editing: prime.cpython-39.pyc
Close
a �'k`� � @ s� d Z ddlmZ ddlZddlZddgZdd� Zdd � Zd d� Z dd � Z dd� Zdd� Ze dkr�ed� ddlZed�D ]4Ze�� \ZZer� q�ed dkrxerxede � qxed� dS )z�Numerical functions related to primes. Implementation based on the book Algorithm Design by Michael T. Goodrich and Roberto Tamassia, 2002. � )�rangeN�getprime�are_relatively_primec C s |dkr|| | } }q | S )zPReturns the greatest common divisor of p and q >>> gcd(48, 180) 12 r � )�p�qr r �(/opt/gsutil/third_party/rsa/rsa/prime.py�gcd s r c C s4 t j�| �}|dkrdS |dkr$dS |dkr0dS dS )a� Returns minimum number of rounds for Miller-Rabing primality testing, based on number bitsize. According to NIST FIPS 186-4, Appendix C, Table C.3, minimum number of rounds of M-R testing, using an error probability of 2 ** (-100), for different p, q bitsizes are: * p, q bitsize: 512; rounds: 7 * p, q bitsize: 1024; rounds: 4 * p, q bitsize: 1536; rounds: 3 See: http://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf i � i � i � � )�rsa�common�bit_size)�numberZbitsizer r r �get_primality_testing_rounds* s r c C s� | dk rdS | d }d}|d@ s2|d7 }|dL }qt |�D ]~}tj�| d �d }t||| �}|dks:|| d krtq:t |d �D ]0}t|d| �}|dkr� dS || d kr� q:q� dS q:dS )a. Calculates whether n is composite (which is always correct) or prime (which theoretically is incorrect with error probability 4**-k), by applying Miller-Rabin primality testing. For reference and implementation example, see: https://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test :param n: Integer to be tested for primality. :type n: int :param k: Number of rounds (witnesses) of Miller-Rabin testing. :type k: int :return: False if the number is composite, True if it's probably prime. :rtype: bool � F� r r T)r r �randnum�randint�pow)�n�k�d�r�_�a�xr r r �miller_rabin_primality_testingD s( r c C s2 | dk r| dv S | d@ sdS t | �}t| |d �S )z�Returns True if the number is prime, and False otherwise. >>> is_prime(2) True >>> is_prime(42) False >>> is_prime(41) True r > r r � r r F)r r )r r r r r �is_primey s r! c C s* | dksJ �t j�| �}t|�r|S qdS )a Returns a prime number that can be stored in 'nbits' bits. >>> p = getprime(128) >>> is_prime(p-1) False >>> is_prime(p) True >>> is_prime(p+1) False >>> from rsa import common >>> common.bit_size(p) == 128 True r N)r r Zread_random_odd_intr! )�nbits�integerr r r r � s c C s t | |�}|dkS )z�Returns True if a and b are relatively prime, and False if they are not. >>> are_relatively_prime(2, 3) True >>> are_relatively_prime(2, 4) False r )r )r �br r r r r � s �__main__z'Running doctests 1000x or until failurei� �d z%i timesz Doctests done)�__doc__�rsa._compatr � rsa.commonr �rsa.randnum�__all__r r r r! r r �__name__�print�doctest�count�testmod�failures�testsr r r r �<module> s( 5