diff --git a/bin/find_primes.py b/bin/find_primes.py index 1481910..c17b1a8 100644 --- a/bin/find_primes.py +++ b/bin/find_primes.py @@ -16,8 +16,11 @@ print('Detected numpy version {__version__}'.format(**locals())) except ImportError: + print('Numpy is not found! Finding primes will be slower!') NUMPY_ENABLED = False +print() + def _check_num(n): ''' Internel function to check the input. @@ -36,10 +39,10 @@ def _check_factors(ans, n, retry = 1, max_retries = 3): return 0 if retry == max_retries + 1: - print(f'Factor Error. The multiplication of {ans} is not {n}.') - raise FactorError(f'Factor Error. The multiplication of {ans} is not {n}.') + print('Factor Error. The multiplication of {ans} is not {n}.'.format(**locals())) + raise FactorError('Factor Error. The multiplication of {ans} is not {n}.'.format(**locals())) - print(f'Factor Error. The multiplication of {ans} is not {n}. Retry {retry}.') + print('Factor Error. The multiplication of {ans} is not {n}. Retry {retry}.'.format(**locals())) return retry + 1 @@ -2453,7 +2456,7 @@ def multiply_point(P, k, curve): return P2 - def lenstra(n, mode = 1, tries = 10): + def factor(n, mode = 1, tries = 10, retry = 1): factors = [] for i in (2, 3): while n % i == 0: @@ -2485,10 +2488,7 @@ def lenstra(n, mode = 1, tries = 10): i = 1 while True: i += 1 - if mode == 0: - P2 = add_points(P, P2, curve) - - elif mode == 1: + if mode == 1: P2 = multiply_point(P2, i, curve) elif mode == 2: @@ -2531,10 +2531,14 @@ def lenstra(n, mode = 1, tries = 10): return factors factors.append(n) - factors.sort() - return factors + checked = _check_factors(factors, n, retry) + if checked == 0: + factors.sort() + return factors + + return factor(n, retry = checked) - return lenstra(n) + return factor(n) def factor_pollardpm1(n, retry = 1): ''' diff --git a/build/lib/find_primes/__init__.py b/build/lib/find_primes/__init__.py index 20c5c6e..eefb243 100644 --- a/build/lib/find_primes/__init__.py +++ b/build/lib/find_primes/__init__.py @@ -1,6 +1,6 @@ ''' A module to finds all kinds of primes. -Python version: 3.6+ (If runs test) +Python version: 3.6+ ''' from time import time @@ -8,7 +8,7 @@ from random import randint, randrange from functools import reduce from operator import mul -from sys import version_info +from sys import version, version_info from argparse import ArgumentParser NUMPY_ENABLED = True @@ -17,6 +17,7 @@ print('Detected numpy version {__version__}'.format(**locals())) except ImportError: + print('Numpy is not found! Finding primes will be slower!') NUMPY_ENABLED = False PRIME_TEST = True @@ -26,8 +27,11 @@ print('Detected rsa version {__version__}'.format(**locals())) except ImportError: + print('Rsa is not found! Factor Test will be disabled!') FACTOR_TEST = False +print() + LEFT = 'left' RIGHT = 'right' BOTH = 'both' @@ -37,6 +41,8 @@ HEXAGON = 'hexagon' HEPTAGON = 'heptagon' +CAN_RUN_TEST = version_info[0] == 3 and version_info[1] >= 6 + def _check_num(n): ''' Internel function to check the input. @@ -55,10 +61,10 @@ def _check_factors(ans, n, retry = 1, max_retries = 3): return 0 if retry == max_retries + 1: - print(f'Factor Error. The multiplication of {ans} is not {n}.') - raise FactorError(f'Factor Error. The multiplication of {ans} is not {n}.') + print('Factor Error. The multiplication of {ans} is not {n}.'.format(**locals())) + raise FactorError('Factor Error. The multiplication of {ans} is not {n}.'.format(**locals())) - print(f'Factor Error. The multiplication of {ans} is not {n}. Retry {retry}.') + print('Factor Error. The multiplication of {ans} is not {n}. Retry {retry}.'.format(**locals())) return retry + 1 @@ -150,7 +156,7 @@ def find_palindromes_base_2(n): base2_palin_primes = [] for ix, xp in enumerate(primes): palin_num = xp[::-1] - result = eval(f'0b{palin_num}') + result = eval('0b{palin_num}'.format(**locals())) if is_prime(result) and palin_num == xp: base2_palin_primes.append(result) @@ -181,12 +187,12 @@ def find_square_palindromes(n): ''' _check_num(n) palin_primes = find_palindromes(n) - square_palin_prime = {} + square_palin_primes = {} for x in palin_primes: if str(x ** 2)[::-1] == str(x ** 2): - square_palin_prime[x] = x ** 2 + square_palin_primes[x] = x ** 2 - return square_palin_prime + return square_palin_primes def find_arithmetic_prime_progressions(n): ''' @@ -2909,7 +2915,7 @@ def multiply_point(P, k, curve): return P2 - def factor(n, mode = 1, tries = 10): + def factor(n, mode = 1, tries = 10, retry = 1): factors = [] for i in (2, 3): while n % i == 0: @@ -2941,10 +2947,7 @@ def factor(n, mode = 1, tries = 10): i = 1 while True: i += 1 - if mode == 0: - P2 = add_points(P, P2, curve) - - elif mode == 1: + if mode == 1: P2 = multiply_point(P2, i, curve) elif mode == 2: @@ -2987,8 +2990,12 @@ def factor(n, mode = 1, tries = 10): return factors factors.append(n) - factors.sort() - return factors + checked = _check_factors(factors, n, retry) + if checked == 0: + factors.sort() + return factors + + return factor(n, retry = checked) return factor(n) @@ -3218,8 +3225,8 @@ def test(): print(f'Factor Test Time: {round(end_all - start_all, 12)} seconds.') if __name__ == '__main__': - if version_info[0] == 3 and version_info[1] >= 6: + if CAN_RUN_TEST: test() else: - print('The test method can\'t run in your python version.') \ No newline at end of file + print('The test method can\'t run in your python version ' + version.split(' (')[0] + '.') \ No newline at end of file diff --git a/build/scripts-3.10/find_primes.py b/build/scripts-3.10/find_primes.py index 1481910..c17b1a8 100644 --- a/build/scripts-3.10/find_primes.py +++ b/build/scripts-3.10/find_primes.py @@ -16,8 +16,11 @@ print('Detected numpy version {__version__}'.format(**locals())) except ImportError: + print('Numpy is not found! Finding primes will be slower!') NUMPY_ENABLED = False +print() + def _check_num(n): ''' Internel function to check the input. @@ -36,10 +39,10 @@ def _check_factors(ans, n, retry = 1, max_retries = 3): return 0 if retry == max_retries + 1: - print(f'Factor Error. The multiplication of {ans} is not {n}.') - raise FactorError(f'Factor Error. The multiplication of {ans} is not {n}.') + print('Factor Error. The multiplication of {ans} is not {n}.'.format(**locals())) + raise FactorError('Factor Error. The multiplication of {ans} is not {n}.'.format(**locals())) - print(f'Factor Error. The multiplication of {ans} is not {n}. Retry {retry}.') + print('Factor Error. The multiplication of {ans} is not {n}. Retry {retry}.'.format(**locals())) return retry + 1 @@ -2453,7 +2456,7 @@ def multiply_point(P, k, curve): return P2 - def lenstra(n, mode = 1, tries = 10): + def factor(n, mode = 1, tries = 10, retry = 1): factors = [] for i in (2, 3): while n % i == 0: @@ -2485,10 +2488,7 @@ def lenstra(n, mode = 1, tries = 10): i = 1 while True: i += 1 - if mode == 0: - P2 = add_points(P, P2, curve) - - elif mode == 1: + if mode == 1: P2 = multiply_point(P2, i, curve) elif mode == 2: @@ -2531,10 +2531,14 @@ def lenstra(n, mode = 1, tries = 10): return factors factors.append(n) - factors.sort() - return factors + checked = _check_factors(factors, n, retry) + if checked == 0: + factors.sort() + return factors + + return factor(n, retry = checked) - return lenstra(n) + return factor(n) def factor_pollardpm1(n, retry = 1): ''' diff --git a/dist/find_primes-2.1.6-py3-none-any.whl b/dist/find_primes-2.1.6-py3-none-any.whl new file mode 100644 index 0000000..dcd71dc Binary files /dev/null and b/dist/find_primes-2.1.6-py3-none-any.whl differ diff --git a/dist/find_primes-2.1.6.tar.gz b/dist/find_primes-2.1.6.tar.gz new file mode 100644 index 0000000..31ecb27 Binary files /dev/null and b/dist/find_primes-2.1.6.tar.gz differ diff --git a/find_primes.egg-info/PKG-INFO b/find_primes.egg-info/PKG-INFO index a447bc6..0e0efad 100644 --- a/find_primes.egg-info/PKG-INFO +++ b/find_primes.egg-info/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: find-primes -Version: 2.1.5 +Version: 2.1.6 Summary: A module for finding primes and finding factors of big numbers. Home-page: https://github.com/git4robot/pypi_find_primes Author: JamesJ @@ -11,6 +11,7 @@ Classifier: Programming Language :: Python Classifier: License :: OSI Approved :: MIT License Classifier: Development Status :: 4 - Beta Classifier: Topic :: Scientific/Engineering :: Mathematics +Requires-Python: >=3.6.0 Description-Content-Type: text/markdown License-File: LICENSE diff --git a/find_primes.egg-info/SOURCES.txt b/find_primes.egg-info/SOURCES.txt index ca3d01c..24ad71c 100644 --- a/find_primes.egg-info/SOURCES.txt +++ b/find_primes.egg-info/SOURCES.txt @@ -6,4 +6,5 @@ find_primes/__init__.py find_primes.egg-info/PKG-INFO find_primes.egg-info/SOURCES.txt find_primes.egg-info/dependency_links.txt +find_primes.egg-info/requires.txt find_primes.egg-info/top_level.txt \ No newline at end of file diff --git a/find_primes.egg-info/requires.txt b/find_primes.egg-info/requires.txt new file mode 100644 index 0000000..d0ad667 --- /dev/null +++ b/find_primes.egg-info/requires.txt @@ -0,0 +1,2 @@ +numpy +rsa diff --git a/find_primes/__init__.py b/find_primes/__init__.py index 20c5c6e..eefb243 100644 --- a/find_primes/__init__.py +++ b/find_primes/__init__.py @@ -1,6 +1,6 @@ ''' A module to finds all kinds of primes. -Python version: 3.6+ (If runs test) +Python version: 3.6+ ''' from time import time @@ -8,7 +8,7 @@ from random import randint, randrange from functools import reduce from operator import mul -from sys import version_info +from sys import version, version_info from argparse import ArgumentParser NUMPY_ENABLED = True @@ -17,6 +17,7 @@ print('Detected numpy version {__version__}'.format(**locals())) except ImportError: + print('Numpy is not found! Finding primes will be slower!') NUMPY_ENABLED = False PRIME_TEST = True @@ -26,8 +27,11 @@ print('Detected rsa version {__version__}'.format(**locals())) except ImportError: + print('Rsa is not found! Factor Test will be disabled!') FACTOR_TEST = False +print() + LEFT = 'left' RIGHT = 'right' BOTH = 'both' @@ -37,6 +41,8 @@ HEXAGON = 'hexagon' HEPTAGON = 'heptagon' +CAN_RUN_TEST = version_info[0] == 3 and version_info[1] >= 6 + def _check_num(n): ''' Internel function to check the input. @@ -55,10 +61,10 @@ def _check_factors(ans, n, retry = 1, max_retries = 3): return 0 if retry == max_retries + 1: - print(f'Factor Error. The multiplication of {ans} is not {n}.') - raise FactorError(f'Factor Error. The multiplication of {ans} is not {n}.') + print('Factor Error. The multiplication of {ans} is not {n}.'.format(**locals())) + raise FactorError('Factor Error. The multiplication of {ans} is not {n}.'.format(**locals())) - print(f'Factor Error. The multiplication of {ans} is not {n}. Retry {retry}.') + print('Factor Error. The multiplication of {ans} is not {n}. Retry {retry}.'.format(**locals())) return retry + 1 @@ -150,7 +156,7 @@ def find_palindromes_base_2(n): base2_palin_primes = [] for ix, xp in enumerate(primes): palin_num = xp[::-1] - result = eval(f'0b{palin_num}') + result = eval('0b{palin_num}'.format(**locals())) if is_prime(result) and palin_num == xp: base2_palin_primes.append(result) @@ -181,12 +187,12 @@ def find_square_palindromes(n): ''' _check_num(n) palin_primes = find_palindromes(n) - square_palin_prime = {} + square_palin_primes = {} for x in palin_primes: if str(x ** 2)[::-1] == str(x ** 2): - square_palin_prime[x] = x ** 2 + square_palin_primes[x] = x ** 2 - return square_palin_prime + return square_palin_primes def find_arithmetic_prime_progressions(n): ''' @@ -2909,7 +2915,7 @@ def multiply_point(P, k, curve): return P2 - def factor(n, mode = 1, tries = 10): + def factor(n, mode = 1, tries = 10, retry = 1): factors = [] for i in (2, 3): while n % i == 0: @@ -2941,10 +2947,7 @@ def factor(n, mode = 1, tries = 10): i = 1 while True: i += 1 - if mode == 0: - P2 = add_points(P, P2, curve) - - elif mode == 1: + if mode == 1: P2 = multiply_point(P2, i, curve) elif mode == 2: @@ -2987,8 +2990,12 @@ def factor(n, mode = 1, tries = 10): return factors factors.append(n) - factors.sort() - return factors + checked = _check_factors(factors, n, retry) + if checked == 0: + factors.sort() + return factors + + return factor(n, retry = checked) return factor(n) @@ -3218,8 +3225,8 @@ def test(): print(f'Factor Test Time: {round(end_all - start_all, 12)} seconds.') if __name__ == '__main__': - if version_info[0] == 3 and version_info[1] >= 6: + if CAN_RUN_TEST: test() else: - print('The test method can\'t run in your python version.') \ No newline at end of file + print('The test method can\'t run in your python version ' + version.split(' (')[0] + '.') \ No newline at end of file diff --git a/setup.py b/setup.py index f37ecad..0e1c432 100644 --- a/setup.py +++ b/setup.py @@ -7,10 +7,12 @@ setup( name = 'find_primes', - version = '2.1.5', + version = '2.1.6', author = 'JamesJ', author_email = 'GGJamesQQ@yeah.net', description = 'A module for finding primes and finding factors of big numbers.', + install_requires = ['numpy', 'rsa'], + python_requires = '>=3.6.0', classifiers = [ 'Programming Language :: Python', 'License :: OSI Approved :: MIT License',