Python半素因式分解方程求解器问题

发布于 2025-01-07 18:39:17 字数 11502 浏览 1 评论 0原文

我是一名农民/新手数论研究员。几年前,我碰巧发现了素数分布中出现的一种模式,该模式将素数的数量与 300 个类似斐波那契数列的运算联系起来。好吧,作为一个一直使用笔和纸的人,当我将我的方法转换为计算机代码时,我不知所措(所以我聘请了一名程序员用 Perl 实现我的代码)。该代码有效,但不是我现在需要的过程;我想询问程序员社区,他们认为使此(Python)代码工作的最佳方法是什么。另外,作为一名研究人员,我并不太关心人们将此代码用于自己的用途 - 我只是想看看你用它做什么!

Perl 程序生成的结果发表在 AT&T Online Encyclopedia of Integer Sequences 中。 https://oeis.org/search?q=helkenberg&language=english& ;go=Search

下面的程序是我最近的努力,但我一生都无法弄清楚如何让代码的某些部分工作。

例如(来自下面的较大程序),

print"""THIS CODE WILL NOT COMPILE (example p*q = 29*73)
print [(int(p) + 90*x_0) * int(q)+ 90*x_0)]/90 #example 23
print [(int(p) + 90*x_1) * (int(q)+90*x_1)]/90 #example 215

z(0) = [(int(p) + 90*x_0) * int(q)+ 90*x_0)]/90
z(1) = [(int(p) + 90*x_1) * (int(q)+90*x_1)]/90
#This defines a new process, a Fibonacci-like sequence:

a = z(1) - z(0) #example (192=215-23)
g = 180 #think the unit circle, clock cycles

m_0 = a + g #example 192+180 = 372

z(2) = m_0 + z(1) #example 587 = 372 + 215

m_1 = m_0 + g #example 552 = 372 + 180

z(3) = z(2)+ m_1 #example 1139 = 587 + 552

m_2 = m_1 + g #example 732 = 552 + 180

z(4) = z(3) + m_2 #example 1871 = 1139 + 732

我正在自学如何编码,但我一生都无法弄清楚如何实现它!

最后,我需要使用这些值(z 项)来求解以下形式的方程:

0 = r - [(((90*n))+29)*y) + z_n]
0 = r - [(((90*n))+73)*y) + z_n]

其中 z 项用于 29 和 73(作为示例)

这是我到目前为止所得到的。

print    "1522605027922533360535618378132637429718068114961380688657908494580122963258952897654000350692006139"

variable = raw_input('copy and paste the above number')

#This valuable function reduces an arbitrarily large number to the SUM OF ITS DIGITS
new_variable = sum(map(int, str(variable)))
print new_variable

next_step = sum(map(int, str(new_variable)))
print next_step

new_step = sum(map(int, str(next_step)))

print "The digital root of our test number is", new_step, "A fine answer."

if int(new_step) > 9:
print "We cannot have a two digit digital root!Enter the sum of those two numbers here!"

newest_data = raw_input ('>enter the digital root here')

#newest_data = raw_input ()

if new_step == 3:
print "This number is divisible by 3."
if new_step == 6:
print "This number is divisible by 3."
if new_step == 9:
print "This number is divisible by 3 and 9."

if newest_data == 3:
print "This number is divisible by 3."
if newest_data == 6:
print "This number is divisible by 3."
if newest_data == 9:
print "This number is divisible by 3 and 9."

print "What is the last digit of our number?"
last_digit = raw_input("Last digit here")

print last_digit

if int(last_digit) == 0:
print "This number is divisible by 2 and 5."
if int(last_digit) == 2:
print "This number is divisible by 2."
if int(last_digit) == 4:
print "This number is divisible by 2."
if int(last_digit) == 6:
print "This number is divisible by 2."
if int(last_digit) == 8:
print "This number is divisible by 2."

digital_root = int(new_step)
new_digit = int(last_digit)

if digital_root == 1 and new_digit == 1:
print "your primitive is 91"

elif digital_root == 1 and new_digit == 3:
print "your primitive is 73"

elif digital_root == 1 and new_digit == 7:
print "your primitive is 37"

elif digital_root == 1 and new_digit == 9:
print "your primitive is 19"

elif digital_root == 2 and new_digit == 1:
print "your primitive is 11"

elif digital_root == 2 and new_digit == 3:
print "your primitive is 73"

elif digital_root == 2 and new_digit == 7:
print "your primitive is 47"

elif digital_root == 2 and new_digit == 9:
print "your primitive is 29"

elif digital_root == 4 and new_digit == 1:
print "your primitive is 31"

elif digital_root == 4 and new_digit == 3:
print "your primitive is 13"

elif digital_root == 4 and new_digit == 7:
print "your primitive is 67"

elif digital_root == 4 and new_digit == 9:
print "your primitive is 49"

elif digital_root == 5 and new_digit == 1:
print "your primitive is 41"

elif digital_root == 5 and new_digit == 3:
print "your primitive is 23"

elif digital_root == 5 and new_digit == 7:
print "your primitive is 77"

elif digital_root == 5 and new_digit == 9:
print "your primitive is 59"

elif digital_root == 7 and new_digit == 1:
print "your primitive is 61"

elif digital_root == 7 and new_digit == 3:
print "your primitive is 43"

elif digital_root == 7 and new_digit == 7:
print "your primitive is 7"

elif digital_root == 7 and new_digit == 9:
print "your primitive is 79"

elif digital_root == 8 and new_digit == 1:
print "your primitive is 71"

elif digital_root == 8 and new_digit == 3:
print "your primitive is 53"

elif digital_root == 8 and new_digit == 7:
print "your primitive is 17"

elif digital_root == 8 and new_digit == 9:
print "your primitive is 89"


primitive = raw_input("enter primitive here")
new_value = int(variable) - int(primitive)
stored_data = new_value/90

print "this is our new number, the position of our test number in a dr,ld index.", stored_data

print "This number above is our test number (r)."

tuple = [73,91,19,37,11,23,29,77,47,59,83,41,13,61,31,43,49,7, 67,79,17,89,53,71]

print tuple
print " the example is based on 29*73"
p = raw_input("p from tuple (to be defined)") # example 29
q = raw_input("q associated with p") #example 73

#def make_incrementor (n): return lambda x: x + n
#cannot figure this one out
#notice x_0 and then x_1:
print"""THIS CODE WILL NOT COMPILE (example p*q = 29*73)
print [(int(p) + 90*x_0) * int(q)+ 90*x_0)]/90 #example 23
print [(int(p) + 90*x_1) * (int(q)+90*x_1)]/90 #example 215

z(0) = [(int(p) + 90*x_0) * int(q)+ 90*x_0)]/90
z(1) = [(int(p) + 90*x_1) * (int(q)+90*x_1)]/90

#This defines a new process, a Fibonacci-like sequence:

a = z(1) - z(0) #example (192=215-23)
g = 180 #think the unit circle, clock cycles

m_0 = a + g #example 192+180 = 372

z(2) = m_0 + z(1) #example 587 = 372 + 215

m_1 = m_0 + g #example 552 = 372 + 180

z(3) = z(2)+ m_1 #example 1139 = 587 + 552

m_2 = m_1 + g #example 732 = 552 + 180

z(4) = z(3) + m_2 #example 1871 = 1139 + 732

"""

print "seed values for sequence z = [23, 215]"
print "set of z terms [23, 215, 587, 1139, 1871,.....] "


print "notice the last-digit pattern for the z term means that every term of z will end  in a [3, 5, 7, 9, 1], in that order, but also IN A POWER SERIES. Also notice that our test number (r) ends with the last digit 8. So prior to computing w, we know that none of the solutions represented by z (where z = r) are possible."

print """
there are 24 equations (posed as alternatives):

r = stored_data test number, RSA-100 clock position
print "RSA-100 = 19 +     (90*16917833643583704005951315312584860330200756832904229873976761050890255147321698862822226118800068)"
Startng at 19 degrees, RSA100 is 169..... 1/4 rotations from the 0 position on the clock face.

#special case: where r-z = 0, factor found.

0 = r - [(((90*n))+19)*y) + z_n]
0 = [(((r-z_n)/y)-19)]/x - 90]

0 = r - [(((90*n)+91)*y) + z_n]
0 = [(((r-z_n)/y)-91)]/n - 90]

0 = r - [(((90*n)+37)*y) + z_n]
0 = [(((n-z_n)/y)-37)]/n - 90]

0 = r - [(((90*n)+73)*y) + z_n]
0 = [(((r-z_n)/y)-73)]/n - 90]

0 = r - [(((90*n)+11)*y) + z_n]
0 = [(((r-z_n)/y)-11)]/n - 90]

0 = r - [(((90*n)+59)*y) + z_n]
0 = [(((r-z_n)/y)-59)]/n - 90]

0 = r - [(((90*n)+29)*y) + z_n]
0 = [(((r-z_n)/y)-29)]/x - 90]

0 = r - [(((90*n)+41)*y) + z_n]
0 = [(((r-z_n)/y)-41)]/n - 90]

0 = r - [(((90*n)+47)*y) + z_n]
0 = [(((r-z_n)/y)-47)]/n - 90]

0 = r - [(((90*n)+77)*y) + z_n]
0 = [(((r-z_n)/y)-77)]/n - 90]

0 = r - [(((90*n)+83)*y) + z_n]
0 = [(((r-z_n)/y)-83)]/n - 90]

0 = r - [(((90*n)+23)*y) + z_n]
0 = [(((r-z_n)/y)-83)]/n - 90]

0 = r - [(((90*n)+13)*y) + z_n]
0 = [(((r-z_n)/y)-13)]/n - 90]

0 = r - [(((90*n)+43)*y) + z_n]
0 = [(((r-z_n)/y)-43)]/n - 90]

0 = r - [(((90*n)+31)*y) + z_n]
0 = [(((r-z_n)/y)-31)]/n - 90]

0 = r - [(((90*n)+79)*y) + z_n]
0 = [(((r-z_n)/y)-79)]/n - 90]

0 = r - [(((90*n)+49)*y) + z_n]
0 = [(((r-z_n)/y)-49)]/n - 90]

0 = r - [(((90*n)+61)*y) + z_n]
0 = [(((r-z_n)/y)-61)]/n - 90]

0 = r - [(((90*n)+67)*y) + z_n
0 = [(((r-z_n)/y)-67)]/n - 90]

0 = r - [(((90*n)+7)*y) + z_n]
0 = [(((r-z_n)/y)-7)]/n - 90]

0 = r - [(((90*n)+17)*y) + z_n]
0 = [(((r-z_n)/y)-17)]/n - 90]

0 = r - [(((90*n)+53)*y) + z_n]
0 = [(((r-z_n)/y)-53)]/n - 90]

0 = r - [(((90*n)+71)*y) + z_n]
0 = [(((r-z_n)/y)-71)]/n - 90]

0 = r - [(((90*n)+89)*y) + z_n]
0 = [(((r-z_n)/y)-89)]/n - 90]
"""



#Here is the OLD PROGRAM in Perl

#!/usr/bin/perl

use strict;
use warnings;

use Math::BigInt;
use POSIX;
use Getopt::Long;

my $rsa              = '';
my $p                = '';
my $q                = '';
my $digit_root_chart = '';

GetOptions(
'rsa|r=s'   => \$rsa,
'p=s'       => \$p,
'q=s'       => \$q,
'digit|d=i' => \$digit_root_chart,
) or die "Problem with command";

# /*
#  * General algorithm goes here.
#  *
#  */

my $length_of_semiprime = length($rsa);
my $digit_root          = &digit_root($rsa);

print "digit root: $digit_root\n";

$rsa = Math::BigInt->new($rsa);
print "rsa: $rsa\n";
my $new_rsa = $rsa->copy();
$new_rsa -=
  $digit_root_chart;  # need to figure out a way to tablize the digit root table
$new_rsa /= 90;
print "new_rsa: $new_rsa\n";

$p = Math::BigInt->new($p);
$q = Math::BigInt->new($q);
my $y = &first_two_calcs( $p, $q );
print "p = $p, q = $q\n";
&check_for_factor( $p, $q, $y );

$p += 90;
$q += 90;
my $z = &first_two_calcs( $p, $q );
print "p = $p, q = $q\n";
&check_for_factor( $p, $q, $z );

$p += 90;
$q += 90;
print "p = $p, q = $q\n";
my @r = &second_calcs( $y, $z );
$y = $r[0];
$z = $r[1];
&check_for_factor( $p, $q, $z );

while (1) {
   $p += 90;
   $q += 90;

my @t = &third_calc( $y, $z );
$y = $t[0];
$z = $t[1];

if ( $z <= $new_rsa ) {
    &check_for_factor( $p, $q, $z )
      if ( ( length($p) || length($q) ) >=
        ( ( $length_of_semiprime / 2 ) - 1 ) );
}
else {
    last;
}
}

# This sub() is used for the first two calculations
sub first_two_calcs {
my ( $p, $q ) = @_;
my $z = $p * $q;
my $x = $z / 9;

# if its a whole number we move along
if ( ( $z % 9 ) == 0 ) {
    print "($p * $q) / 9 = $x\n";
}
else {
    print "num doesn't div evenly: ($p * $q) / 9 = $x\n";
    $x = int( $x / 10 );
    print "new num: (($p * $q) / 9) / 10 = $x\n";
}
return $x;
}

# /*
#  * This sub() checks to see if it is a factor.
#  *
#  */
sub check_for_factor {
my ( $p, $q, $z ) = @_;

print "Check_for_factor(p = $p, q = $q, z = $z)\n";

for ( $p, $q ) {
    my $temp = $new_rsa - $z;
    my $y    = ( $temp / $_ );

    if ( ( $temp % $_ ) == 0 ) {
        print "\n******* factor found: $_ for $rsa *******\n";
        exit(0);
    }
    elsif ( ( int( $y / 10 ) ) == $new_rsa ) {
        print "\n******* factor found: $_ for $rsa *******\n";
        exit(0);
    }
    else {
        print "factor NOT found: ($new_rsa - $z) / $_ = $y\n";
    }
}
}

# This sub() is used for the rest of the calculations
sub second_calcs {
my ( $y, $z ) = @_;
my $j = $z - $y;
my $k = $j + 180;
my $l = $z + $k;

print "$z - $y = |$j|\n";
print "$j + 180 = $k\n";
print "$k + $z = $l\n";

return ( $k, $l );
}

sub third_calc {
my ( $y, $z ) = @_;

my $k = $y + 180;
my $l = $z + $k;

return ( $k, $l );
}

# /*
#  * This sub() calcs the digit root:
#  * example: $rsa = 12345
#  * 1 + 2 + 3 + 4 + 5 = 15 and 1 + 5 = 6 (digit root)
#  */
sub digit_root {
my $rsa = shift;

$rsa = Math::BigInt->new($rsa);

return ( 1 + ( ( $rsa - 1 ) % 9 ) );
}

I am a farmer / novice number theory researcher. I happened to discover some years back a pattern that emerged in the distribution of the prime numbers that related the number of primes to the operation of 300 Fibonacci-like sequences. Well, as a person who has always used pen and paper I was at a loss when it came to converting my methods into computer code (so I hired a programmer to implement my code in Perl). That code worked but it was not the process that I now need; I wish to ask a community of programmers what they think is the best approach to making this (Python) code work. Also, as a researcher I am not overly concerned with people appropriating this code for their own uses - I would just like to see what you do with it!

The results generated by the Perl program were published in the AT&T Online Encyclopedia of Integer Sequences. https://oeis.org/search?q=helkenberg&language=english&go=Search

The program below is my recent effort but I cannot for the life of me figure out how to get certain parts of the code to work.

For instance (from the larger program below),

print"""THIS CODE WILL NOT COMPILE (example p*q = 29*73)
print [(int(p) + 90*x_0) * int(q)+ 90*x_0)]/90 #example 23
print [(int(p) + 90*x_1) * (int(q)+90*x_1)]/90 #example 215

z(0) = [(int(p) + 90*x_0) * int(q)+ 90*x_0)]/90
z(1) = [(int(p) + 90*x_1) * (int(q)+90*x_1)]/90
#This defines a new process, a Fibonacci-like sequence:

a = z(1) - z(0) #example (192=215-23)
g = 180 #think the unit circle, clock cycles

m_0 = a + g #example 192+180 = 372

z(2) = m_0 + z(1) #example 587 = 372 + 215

m_1 = m_0 + g #example 552 = 372 + 180

z(3) = z(2)+ m_1 #example 1139 = 587 + 552

m_2 = m_1 + g #example 732 = 552 + 180

z(4) = z(3) + m_2 #example 1871 = 1139 + 732

I am teaching myself how to code and I cannot for the life of me figure out how to implement this!!!

Lastly, I need to use those values (of the z term) to solve an equation of the form:

0 = r - [(((90*n))+29)*y) + z_n]
0 = r - [(((90*n))+73)*y) + z_n]

where the z term is used for both 29 and 73 (as an example)

Here is what I have so far.

print    "1522605027922533360535618378132637429718068114961380688657908494580122963258952897654000350692006139"

variable = raw_input('copy and paste the above number')

#This valuable function reduces an arbitrarily large number to the SUM OF ITS DIGITS
new_variable = sum(map(int, str(variable)))
print new_variable

next_step = sum(map(int, str(new_variable)))
print next_step

new_step = sum(map(int, str(next_step)))

print "The digital root of our test number is", new_step, "A fine answer."

if int(new_step) > 9:
print "We cannot have a two digit digital root!Enter the sum of those two numbers here!"

newest_data = raw_input ('>enter the digital root here')

#newest_data = raw_input ()

if new_step == 3:
print "This number is divisible by 3."
if new_step == 6:
print "This number is divisible by 3."
if new_step == 9:
print "This number is divisible by 3 and 9."

if newest_data == 3:
print "This number is divisible by 3."
if newest_data == 6:
print "This number is divisible by 3."
if newest_data == 9:
print "This number is divisible by 3 and 9."

print "What is the last digit of our number?"
last_digit = raw_input("Last digit here")

print last_digit

if int(last_digit) == 0:
print "This number is divisible by 2 and 5."
if int(last_digit) == 2:
print "This number is divisible by 2."
if int(last_digit) == 4:
print "This number is divisible by 2."
if int(last_digit) == 6:
print "This number is divisible by 2."
if int(last_digit) == 8:
print "This number is divisible by 2."

digital_root = int(new_step)
new_digit = int(last_digit)

if digital_root == 1 and new_digit == 1:
print "your primitive is 91"

elif digital_root == 1 and new_digit == 3:
print "your primitive is 73"

elif digital_root == 1 and new_digit == 7:
print "your primitive is 37"

elif digital_root == 1 and new_digit == 9:
print "your primitive is 19"

elif digital_root == 2 and new_digit == 1:
print "your primitive is 11"

elif digital_root == 2 and new_digit == 3:
print "your primitive is 73"

elif digital_root == 2 and new_digit == 7:
print "your primitive is 47"

elif digital_root == 2 and new_digit == 9:
print "your primitive is 29"

elif digital_root == 4 and new_digit == 1:
print "your primitive is 31"

elif digital_root == 4 and new_digit == 3:
print "your primitive is 13"

elif digital_root == 4 and new_digit == 7:
print "your primitive is 67"

elif digital_root == 4 and new_digit == 9:
print "your primitive is 49"

elif digital_root == 5 and new_digit == 1:
print "your primitive is 41"

elif digital_root == 5 and new_digit == 3:
print "your primitive is 23"

elif digital_root == 5 and new_digit == 7:
print "your primitive is 77"

elif digital_root == 5 and new_digit == 9:
print "your primitive is 59"

elif digital_root == 7 and new_digit == 1:
print "your primitive is 61"

elif digital_root == 7 and new_digit == 3:
print "your primitive is 43"

elif digital_root == 7 and new_digit == 7:
print "your primitive is 7"

elif digital_root == 7 and new_digit == 9:
print "your primitive is 79"

elif digital_root == 8 and new_digit == 1:
print "your primitive is 71"

elif digital_root == 8 and new_digit == 3:
print "your primitive is 53"

elif digital_root == 8 and new_digit == 7:
print "your primitive is 17"

elif digital_root == 8 and new_digit == 9:
print "your primitive is 89"


primitive = raw_input("enter primitive here")
new_value = int(variable) - int(primitive)
stored_data = new_value/90

print "this is our new number, the position of our test number in a dr,ld index.", stored_data

print "This number above is our test number (r)."

tuple = [73,91,19,37,11,23,29,77,47,59,83,41,13,61,31,43,49,7, 67,79,17,89,53,71]

print tuple
print " the example is based on 29*73"
p = raw_input("p from tuple (to be defined)") # example 29
q = raw_input("q associated with p") #example 73

#def make_incrementor (n): return lambda x: x + n
#cannot figure this one out
#notice x_0 and then x_1:
print"""THIS CODE WILL NOT COMPILE (example p*q = 29*73)
print [(int(p) + 90*x_0) * int(q)+ 90*x_0)]/90 #example 23
print [(int(p) + 90*x_1) * (int(q)+90*x_1)]/90 #example 215

z(0) = [(int(p) + 90*x_0) * int(q)+ 90*x_0)]/90
z(1) = [(int(p) + 90*x_1) * (int(q)+90*x_1)]/90

#This defines a new process, a Fibonacci-like sequence:

a = z(1) - z(0) #example (192=215-23)
g = 180 #think the unit circle, clock cycles

m_0 = a + g #example 192+180 = 372

z(2) = m_0 + z(1) #example 587 = 372 + 215

m_1 = m_0 + g #example 552 = 372 + 180

z(3) = z(2)+ m_1 #example 1139 = 587 + 552

m_2 = m_1 + g #example 732 = 552 + 180

z(4) = z(3) + m_2 #example 1871 = 1139 + 732

"""

print "seed values for sequence z = [23, 215]"
print "set of z terms [23, 215, 587, 1139, 1871,.....] "


print "notice the last-digit pattern for the z term means that every term of z will end  in a [3, 5, 7, 9, 1], in that order, but also IN A POWER SERIES. Also notice that our test number (r) ends with the last digit 8. So prior to computing w, we know that none of the solutions represented by z (where z = r) are possible."

print """
there are 24 equations (posed as alternatives):

r = stored_data test number, RSA-100 clock position
print "RSA-100 = 19 +     (90*16917833643583704005951315312584860330200756832904229873976761050890255147321698862822226118800068)"
Startng at 19 degrees, RSA100 is 169..... 1/4 rotations from the 0 position on the clock face.

#special case: where r-z = 0, factor found.

0 = r - [(((90*n))+19)*y) + z_n]
0 = [(((r-z_n)/y)-19)]/x - 90]

0 = r - [(((90*n)+91)*y) + z_n]
0 = [(((r-z_n)/y)-91)]/n - 90]

0 = r - [(((90*n)+37)*y) + z_n]
0 = [(((n-z_n)/y)-37)]/n - 90]

0 = r - [(((90*n)+73)*y) + z_n]
0 = [(((r-z_n)/y)-73)]/n - 90]

0 = r - [(((90*n)+11)*y) + z_n]
0 = [(((r-z_n)/y)-11)]/n - 90]

0 = r - [(((90*n)+59)*y) + z_n]
0 = [(((r-z_n)/y)-59)]/n - 90]

0 = r - [(((90*n)+29)*y) + z_n]
0 = [(((r-z_n)/y)-29)]/x - 90]

0 = r - [(((90*n)+41)*y) + z_n]
0 = [(((r-z_n)/y)-41)]/n - 90]

0 = r - [(((90*n)+47)*y) + z_n]
0 = [(((r-z_n)/y)-47)]/n - 90]

0 = r - [(((90*n)+77)*y) + z_n]
0 = [(((r-z_n)/y)-77)]/n - 90]

0 = r - [(((90*n)+83)*y) + z_n]
0 = [(((r-z_n)/y)-83)]/n - 90]

0 = r - [(((90*n)+23)*y) + z_n]
0 = [(((r-z_n)/y)-83)]/n - 90]

0 = r - [(((90*n)+13)*y) + z_n]
0 = [(((r-z_n)/y)-13)]/n - 90]

0 = r - [(((90*n)+43)*y) + z_n]
0 = [(((r-z_n)/y)-43)]/n - 90]

0 = r - [(((90*n)+31)*y) + z_n]
0 = [(((r-z_n)/y)-31)]/n - 90]

0 = r - [(((90*n)+79)*y) + z_n]
0 = [(((r-z_n)/y)-79)]/n - 90]

0 = r - [(((90*n)+49)*y) + z_n]
0 = [(((r-z_n)/y)-49)]/n - 90]

0 = r - [(((90*n)+61)*y) + z_n]
0 = [(((r-z_n)/y)-61)]/n - 90]

0 = r - [(((90*n)+67)*y) + z_n
0 = [(((r-z_n)/y)-67)]/n - 90]

0 = r - [(((90*n)+7)*y) + z_n]
0 = [(((r-z_n)/y)-7)]/n - 90]

0 = r - [(((90*n)+17)*y) + z_n]
0 = [(((r-z_n)/y)-17)]/n - 90]

0 = r - [(((90*n)+53)*y) + z_n]
0 = [(((r-z_n)/y)-53)]/n - 90]

0 = r - [(((90*n)+71)*y) + z_n]
0 = [(((r-z_n)/y)-71)]/n - 90]

0 = r - [(((90*n)+89)*y) + z_n]
0 = [(((r-z_n)/y)-89)]/n - 90]
"""



#Here is the OLD PROGRAM in Perl

#!/usr/bin/perl

use strict;
use warnings;

use Math::BigInt;
use POSIX;
use Getopt::Long;

my $rsa              = '';
my $p                = '';
my $q                = '';
my $digit_root_chart = '';

GetOptions(
'rsa|r=s'   => \$rsa,
'p=s'       => \$p,
'q=s'       => \$q,
'digit|d=i' => \$digit_root_chart,
) or die "Problem with command";

# /*
#  * General algorithm goes here.
#  *
#  */

my $length_of_semiprime = length($rsa);
my $digit_root          = &digit_root($rsa);

print "digit root: $digit_root\n";

$rsa = Math::BigInt->new($rsa);
print "rsa: $rsa\n";
my $new_rsa = $rsa->copy();
$new_rsa -=
  $digit_root_chart;  # need to figure out a way to tablize the digit root table
$new_rsa /= 90;
print "new_rsa: $new_rsa\n";

$p = Math::BigInt->new($p);
$q = Math::BigInt->new($q);
my $y = &first_two_calcs( $p, $q );
print "p = $p, q = $q\n";
&check_for_factor( $p, $q, $y );

$p += 90;
$q += 90;
my $z = &first_two_calcs( $p, $q );
print "p = $p, q = $q\n";
&check_for_factor( $p, $q, $z );

$p += 90;
$q += 90;
print "p = $p, q = $q\n";
my @r = &second_calcs( $y, $z );
$y = $r[0];
$z = $r[1];
&check_for_factor( $p, $q, $z );

while (1) {
   $p += 90;
   $q += 90;

my @t = &third_calc( $y, $z );
$y = $t[0];
$z = $t[1];

if ( $z <= $new_rsa ) {
    &check_for_factor( $p, $q, $z )
      if ( ( length($p) || length($q) ) >=
        ( ( $length_of_semiprime / 2 ) - 1 ) );
}
else {
    last;
}
}

# This sub() is used for the first two calculations
sub first_two_calcs {
my ( $p, $q ) = @_;
my $z = $p * $q;
my $x = $z / 9;

# if its a whole number we move along
if ( ( $z % 9 ) == 0 ) {
    print "($p * $q) / 9 = $x\n";
}
else {
    print "num doesn't div evenly: ($p * $q) / 9 = $x\n";
    $x = int( $x / 10 );
    print "new num: (($p * $q) / 9) / 10 = $x\n";
}
return $x;
}

# /*
#  * This sub() checks to see if it is a factor.
#  *
#  */
sub check_for_factor {
my ( $p, $q, $z ) = @_;

print "Check_for_factor(p = $p, q = $q, z = $z)\n";

for ( $p, $q ) {
    my $temp = $new_rsa - $z;
    my $y    = ( $temp / $_ );

    if ( ( $temp % $_ ) == 0 ) {
        print "\n******* factor found: $_ for $rsa *******\n";
        exit(0);
    }
    elsif ( ( int( $y / 10 ) ) == $new_rsa ) {
        print "\n******* factor found: $_ for $rsa *******\n";
        exit(0);
    }
    else {
        print "factor NOT found: ($new_rsa - $z) / $_ = $y\n";
    }
}
}

# This sub() is used for the rest of the calculations
sub second_calcs {
my ( $y, $z ) = @_;
my $j = $z - $y;
my $k = $j + 180;
my $l = $z + $k;

print "$z - $y = |$j|\n";
print "$j + 180 = $k\n";
print "$k + $z = $l\n";

return ( $k, $l );
}

sub third_calc {
my ( $y, $z ) = @_;

my $k = $y + 180;
my $l = $z + $k;

return ( $k, $l );
}

# /*
#  * This sub() calcs the digit root:
#  * example: $rsa = 12345
#  * 1 + 2 + 3 + 4 + 5 = 15 and 1 + 5 = 6 (digit root)
#  */
sub digit_root {
my $rsa = shift;

$rsa = Math::BigInt->new($rsa);

return ( 1 + ( ( $rsa - 1 ) % 9 ) );
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

醉南桥 2025-01-14 18:39:17

我认为您的代码的主要问题(您标记为“此代码将无法编译”的部分)是您在应该使用的地方使用 [方括号]使用括号。在Python中,与数学不同,方括号表示一种非常具体的数据类型,称为列表。您应该用常规括号替换方括号。

print ((int(p) + 90*x_0) * int(q)+ 90*x_0))/90 #example 23 
print ((int(p) + 90*x_1) * (int(q)+90*x_1))/90 #example 215  
z(0) = ((int(p) + 90*x_0) * int(q)+ 90*x_0))/90 
z(1) = ((int(p) + 90*x_1) * (int(q)+90*x_1))/90 

另外,z(n) 会给你带来问题。我不太确定 z(0) 应该以编程方式是什么。然而,除非 z 是一个函数,否则您可能希望 z 是一个 n 元素的列表。在这种情况下,您可以使用 z[1], z[2], ... z[n] 访问这些元素。

这可能并不是一切都错了,但这是一个开始。我建议阅读 python.org 上的 python 教程,并查看 python 代码示例来提高您的能力理解。

I think the main issue with your code (the part that you label "THIS CODE WILL NOT COMPILE") is that you're using [square brackets] where you should be using parentheses. In python, unlike in mathematics, the square brackets denote a very specific data type called a list. You should replace your square brackets with regular parentheses.

print ((int(p) + 90*x_0) * int(q)+ 90*x_0))/90 #example 23 
print ((int(p) + 90*x_1) * (int(q)+90*x_1))/90 #example 215  
z(0) = ((int(p) + 90*x_0) * int(q)+ 90*x_0))/90 
z(1) = ((int(p) + 90*x_1) * (int(q)+90*x_1))/90 

Also, z(n) is going to give you problems. I'm not quite sure what z(0) is supposed to be programmatically. Unless z is a function however, you would probably want z to be a list of n elements. In which case you would access those elements with z[1], z[2], ... z[n].

That's probably not everything wrong, but it's a start. I recommend reading the python tutorial at python.org, and also looking at examples of python code to improve your understanding.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文