did i just break RSA?

Started by
26 comments, last by vaneger 20 years, 8 months ago
quote:Original post by CodeJunkie
(3-1)! = 2!

2+1 = 3
3/3 = 0


What math universe do you live in?
Advertisement
He can see the mistake this way....

fix with:
3/3 == 1
or
3%3 == 0
quote:Original post by rypyr
What math universe do you live in?


lol

/ == -
- == +
+ == *
* == /

maybe thats why i fail all my math classes
So assuming that mod change fixes it, we''re back to the original problem: This algorithm can only test numbers up to about 12 on a 32-bit machine...maybe you''ll get as far as 25 on a 64-bit machine.
It''s the little things that kill...

Besides I think you can test to up to prime 13 before the data type overflows.(my bad)
Improved:
bool Primality(ulong n){	ulong modfact = 1;	for (ulong i = 2; i < n; ++i)		modfact = (modfact * i) % n;	return modfact == n - 1;}
^coolness^
if modfact becomes zero, you could return true immediately...
Do you mean return False?

n=6 (not a prime)

modfact = 1
i=2; modfact = 2;(1*2)%6
i=3; modfact = 0;(2*3)%6

Yes this method is much improved. Now it can handle N somewhere up to ((2^32)^1/2)-1. (I think)
the algorithm works properly becasue (n-1)! + 1 is a mutiple of n thus if it is divisble by n evenly it is a prime number thus (n-1)! +1 % n == 0 is a testing case that is correct. i was posting to access the speed of the function and where to get larger number libraries to use it with alger numbers as people have stated n = 13 is highest it works for because of overflow. please dont bash me unless you know what you are talking about thank you

This topic is closed to new replies.

Advertisement