in reply to (MeowChow) Re: RSA Factoring challenge
in thread RSA Factoring challenge
#!/usr/bin/perl -w use strict; #note that this code is brutally slow my $number = shift; #assume user knows to input a number my @all_factors = factor( $number ); my $check_factor = 0; while ($check_factor != 1 ) { $check_factor = pop @all_factors; push( @all_factors, factor( @check_factor ) ); } if( @all_factors + 0 == 1 ) { print "$number is prime\n"; } else { print "$number: " .join( ',', @all_factors ). "\n"; } exit; sub factor { #one slight change to prevent an illegal modulus operation my $n; my $p; $n=$p=pop; return if( $n ==1 ); 1 while $n%--$p; $n/$p,$p; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(MeowChow) Re3: RSA Factoring challenge
by MeowChow (Vicar) on Jul 26, 2001 at 02:43 UTC |