dear all,
i am simulating my crypto scheme in python, i am a new user to it.
p = 512 bit number and i need to calculate largest prime factor for it, i am looking for two things:
- Fastest code to process this large prime factorization
- Code that can take 512 bit of number as input and can handle it.
I have seen different implementations in other languages, my whole code is in python and this is last point where i am stuck. So let me know if there is any implementation in python.
Kindly explain in simple as i am new user to python
sorry for bad english.
edit (taken from OP's answer below):
#!/usr/bin/env python
def highest_prime_factor(n):
if isprime(n):
return n
for x in xrange(2,n ** 0.5 + 1):
if not n % x:
return highest_prime_factor(n/x)
def isprime(n):
for x in xrange(2,n ** 0.5 + 1):
if not n % x:
return False
return True
if __name__ == "__main__":
import time
start = time.time()
print highest_prime_factor(1238162376372637826)
print time.time() - start
The code above works (with a bit of delay) for "1238162376372637826" but extending it to
10902610991329142436630551158108608965062811746392 57767545600484549911304430471090261099132914243663 05511581086089650628117463925776754560048454991130443047
makes python go crazy. Is there any way so that just like above, i can have it calculated it in no time?