mirror of
https://github.com/cedricbonhomme/Stegano.git
synced 2025-05-13 01:18:31 +02:00
Improved implementation of some generators thanks to Vincent Demange (http://lita.sciences.univ-metz.fr/~demange/).
This commit is contained in:
parent
1c568f6095
commit
f830226cf8
1 changed files with 16 additions and 18 deletions
|
@ -39,19 +39,19 @@ def fermat():
|
||||||
"""
|
"""
|
||||||
Generate the n-th Fermat Number.
|
Generate the n-th Fermat Number.
|
||||||
"""
|
"""
|
||||||
n = 0
|
y = 5
|
||||||
while True:
|
while True:
|
||||||
n += 1
|
yield y
|
||||||
yield pow(2, pow(2, n)) + 1
|
y = pow(y-1,2)+1
|
||||||
|
|
||||||
def mersenne():
|
def mersenne():
|
||||||
"""
|
"""
|
||||||
Generate 2^n-1.
|
Generate 2^n-1.
|
||||||
"""
|
"""
|
||||||
n = 0
|
y = 1
|
||||||
while True:
|
while True:
|
||||||
n += 1
|
yield y
|
||||||
yield pow(2, n) - 1
|
y = 2*y + 1
|
||||||
|
|
||||||
def eratosthenes():
|
def eratosthenes():
|
||||||
"""
|
"""
|
||||||
|
@ -107,20 +107,18 @@ def fibonacci():
|
||||||
yield a
|
yield a
|
||||||
a, b = b, a + b
|
a, b = b, a + b
|
||||||
|
|
||||||
|
|
||||||
def syracuse(l=15):
|
def syracuse(l=15):
|
||||||
n = 0
|
"""
|
||||||
|
Generate the sequence of Syracuse.
|
||||||
|
"""
|
||||||
|
y = l
|
||||||
while True:
|
while True:
|
||||||
yield syracuse_gen(n, l)
|
yield y
|
||||||
n += 1
|
q,r = divmod(y,2)
|
||||||
|
if r == 0:
|
||||||
def syracuse_gen(n, l=15):
|
y = q
|
||||||
if n == 0:
|
else:
|
||||||
return l
|
y = 3*y + 1
|
||||||
if syracuse_gen(n-1) % 2 == 0:
|
|
||||||
return syracuse_gen(n-1)/2
|
|
||||||
elif syracuse_gen(n-1) % 2 == 1:
|
|
||||||
return 3*syracuse_gen(n-1)+1
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Add table
Reference in a new issue