mirror of
https://github.com/apprenticeharper/DeDRM_tools
synced 2024-12-27 09:58:59 +01:00
optimised and corrected primes func drastically
This commit is contained in:
parent
0b206e3fc5
commit
f688bee0aa
1 changed files with 20 additions and 17 deletions
|
@ -126,23 +126,26 @@ def SHA256(message):
|
||||||
# For K4M/PC 1.6.X and later
|
# For K4M/PC 1.6.X and later
|
||||||
# generate table of prime number less than or equal to int n
|
# generate table of prime number less than or equal to int n
|
||||||
def primes(n):
|
def primes(n):
|
||||||
if n==2: return [2]
|
"""
|
||||||
elif n<2: return []
|
Return a list of prime integers smaller than or equal to n
|
||||||
s=range(3,n+1,2)
|
:param n: int
|
||||||
mroot = n ** 0.5
|
:return: list->int
|
||||||
half=(n+1)/2-1
|
"""
|
||||||
i=0
|
if n == 2:
|
||||||
m=3
|
return [2]
|
||||||
while m <= mroot:
|
elif n < 2:
|
||||||
if s[i]:
|
return []
|
||||||
j=(m*m-3)/2
|
primeList = [2]
|
||||||
s[j]=0
|
|
||||||
while j<half:
|
for potentialPrime in range(3, n + 1, 2):
|
||||||
s[j]=0
|
isItPrime = True
|
||||||
j+=m
|
for prime in primeList:
|
||||||
i=i+1
|
if potentialPrime % prime == 0:
|
||||||
m=2*i+3
|
isItPrime = False
|
||||||
return [2]+[x for x in s if x]
|
if isItPrime is True:
|
||||||
|
primeList.append(potentialPrime)
|
||||||
|
|
||||||
|
return primeList
|
||||||
|
|
||||||
# Encode the bytes in data with the characters in map
|
# Encode the bytes in data with the characters in map
|
||||||
def encode(data, map):
|
def encode(data, map):
|
||||||
|
|
Loading…
Reference in a new issue