Re: Easy test of surrogate factoring
From: Décio Luiz Gazzoni Filho (decio_at_decpp.removethis.net)
Date: 02/18/05
- Next message: Matt Gutting: "Re: Easy test of surrogate factoring"
- Previous message: Matt Gutting: "Re: Easy test of surrogate factoring"
- In reply to: Matt Gutting: "Re: Easy test of surrogate factoring"
- Next in thread: Matt Gutting: "Re: Easy test of surrogate factoring"
- Reply: Matt Gutting: "Re: Easy test of surrogate factoring"
- Reply: Marcel Martin: "Re: Easy test of surrogate factoring"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Fri, 18 Feb 2005 13:22:20 -0200
Matt Gutting wrote:
> <snip>
>
> Heck, James, *I* can write a program to factor an RSA number. How about
> this?
>
> int M;
> M = //insert the RSA number here
> for (int i=2; i<=sqrt(M);i++) {
> if (M % i = 0) {
> cout << i << " is a factor of " << M;
> }
> }
I don't think your program works, because a typical RSA number won't fit in
an integer. Try this (if you have GMP and the C++ class interface):
#include <iostream>
#include <gmpxx.h>
int main()
{
mpz_class M(/*insert RSA number here between quotes*/);
for(mpz_class p=2; p<=sqrt(M); mpz_nextprime(p.get_mpz_t(),p.get_mpz_t())
if(mpz_divisible_p(M.get_mpz_t(),p.get_mpz_t())
{
std::cout << p << " is a factor of " << M << std::endl;
break;
}
return 0;
}
I included a few optimizations, although a key would be to try backwards
from sqrt(M), because any given factors will be closer to sqrt(M) than 2.
Décio
- Next message: Matt Gutting: "Re: Easy test of surrogate factoring"
- Previous message: Matt Gutting: "Re: Easy test of surrogate factoring"
- In reply to: Matt Gutting: "Re: Easy test of surrogate factoring"
- Next in thread: Matt Gutting: "Re: Easy test of surrogate factoring"
- Reply: Matt Gutting: "Re: Easy test of surrogate factoring"
- Reply: Marcel Martin: "Re: Easy test of surrogate factoring"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|