Public Group

#### Archived

This topic is now archived and is closed to further replies.

# did i just break RSA?

This topic is 5452 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

ok these two functions when combined will find the primiality of a given number in so far the fastest possible time, however i dont have a larger number library to allow it to work correctly (once the number gets too big for an unsigned long it doesnt work any more). Can some one test this code for me using a large number library and tell me how its working? Also if it works correctly with bigger numbers will this break RSA encryption?
ulong factorial(ulong n)
{
if(n<= 1)
return n;
ulong temp = n;
recurse:
temp--;
n = n * temp ;
if(temp <= 1)
return n;
else
goto recurse;
}
bool Primality(ulong n)
{
if( (factorial(n - 1) + 1) / n == 0 )
return true;
return false;
}


##### Share on other sites
wow...um, where did you get that algorithm?

##### Share on other sites
i designed it my self thanks

##### Share on other sites
If you don't mind me asking what is the largest prime it can test? (perhaps 11)

that's using unsigned integer

[edited by - CodeJunkie on August 13, 2003 5:52:00 PM]

##### Share on other sites
Looks like an algorithm we learned in one of my number theory courses. Dont really remember what is was called tho

##### Share on other sites
I don''t think that function works correctly, unless you happen to be talking about something other than prime versus composite numbers.

Also, this line:

(factorial(n - 1) + 1) / n == 0

boils down to:

factorial(n-1)+1 < n

due to integer division. And, if I''m not mistaken, that statement is never true...

______________________________________________________________
The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ
MySite
______________________________________________________________

##### Share on other sites
Your primality test (which is well known) runs in exponential time, and is therefore inferior to this.

##### Share on other sites
quote:
Original post by vaneger
i designed it my self thanks

Sorry man, I wasn't being serious. Does this algorithm work with any prime number? Let's start with the first prime number, n=3?

if( (factorial(n - 1) + 1) / n == 0 ) :

(3-1)! + 1 = 2 + 1 = 3
3/3 != 0

doh!

Edit: Fixed my typo (forgot the minus one)

[edited by - rypyr on August 13, 2003 5:59:10 PM]

(3-1)! = 2!

2+1 = 3
3/3 = 0

##### Share on other sites
Ah, here's what it's called:
Wilson's Theorem

EDIT: Although vaneger doesn't seem to have implemented it correctly...

[edited by - Beer Hunter on August 13, 2003 6:00:17 PM]

1. 1
2. 2
Rutin
22
3. 3
JoeJ
18
4. 4
5. 5

• 17
• 40
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631726
• Total Posts
3001910
×