Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

change a do {} while(1); to a do {} and add debugging

  • Loading branch information...
commit aeff0ed161f92327d109f34da90b75e7db099a53 1 parent 058d022
Duke Leto authored

Showing 2 changed files with 10 additions and 10 deletions. Show diff stats Hide diff stats

  1. +5 3 lib/Math/Factoring.pm
  2. +5 7 spec/pollard_rho.cc
8 lib/Math/Factoring.pm
@@ -28,12 +28,14 @@ sub _random()
28 28 my $state = rand_init($n);
29 29 my $rand = GMP->new;
30 30 Rmpz_urandomm($rand, $state, $n,1);
  31 + #warn "return rand=$rand";
31 32 return $rand;
32 33 }
33 34
34 35 sub _factor_pollard_rho($$$)
35 36 {
36 37 my ($n,$a,$x0) = @_;
  38 + warn "_factor_pollard($n,$a,$x0)\n";
37 39 my ($x,$y,$q,$d) = map { GMP->new } ( 1 .. 4 );
38 40 my ($i,$j) = (1,1);
39 41 $q = 1; $x = $x0; $y = $x0;
@@ -61,8 +63,8 @@ sub _factor_pollard_rho($$$)
61 63 }
62 64 }
63 65 }
64   - return 0;
65   - } while (1);
  66 + };
  67 + return 0;
66 68
67 69 }
68 70
@@ -77,7 +79,7 @@ sub factor($)
77 79 my $t;
78 80 while( !is_prime($n) ) {
79 81 $t = _factor_pollard_rho($n,$a,$x0);
80   - warn "found t=$t";
  82 + warn "found t=$t,n=$n";
81 83 last if $t == 0;
82 84 push @factors, "$t";
83 85 $n /= $t;
12 spec/pollard_rho.cc
@@ -42,9 +42,9 @@ Integer factor(Integer n, int a_int, int x0)
42 42 if (!isprime(d))
43 43 return factor(d, (random() & 32) - 16, random() & 31);
44 44 else return d;
45   - }
46   - } // if ( (i % j) == 0)
47   - } // while n != 1
  45 + }
  46 + }
  47 + } // while n != 1
48 48 return 0;
49 49 }
50 50
@@ -55,10 +55,8 @@ main (int argc, char *argv[])
55 55 int x0, a;
56 56 int p;
57 57
58   - if (argc != 2) {
59   - cerr << "Usage: " << argv[0] << " NumberToFactor" << endl;
60   - return -1;
61   - }
  58 + if (argc != 2) { cerr << "Usage: " << argv[0] << " NumberToFactor" << endl;
  59 + return -1; }
62 60
63 61 n = argv[1];
64 62

0 comments on commit aeff0ed

Please sign in to comment.
Something went wrong with that request. Please try again.