did i just break RSA?

Started by
26 comments, last by vaneger 20 years, 8 months ago
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;
}
Advertisement
wow...um, where did you get that algorithm?
i designed it my self thanks
If you don't mind me asking what is the largest prime it can test? (perhaps 11)

[edit]
that's using unsigned integer

[edited by - CodeJunkie on August 13, 2003 5:52:00 PM]
Looks like an algorithm we learned in one of my number theory courses. Dont really remember what is was called tho
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
______________________________________________________________
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Formats______________________________________________________________________________________
Your primality test (which is well known) runs in exponential time, and is therefore inferior to this.
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
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]

This topic is closed to new replies.

Advertisement