github.com/gnolang/gno@v0.0.0-20240520182011-228e9d0192ce/gnovm/tests/files/xfactor_long.gno (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"math/big"
     6  )
     7  
     8  var ctr = 0
     9  
    10  func main() {
    11  	// 157 bit n = pq with p ~= 78 bits
    12  	n := big.NewInt(0)
    13  	n.SetString("273966616513101251352941655302036077733021013991", 10)
    14  
    15  	i := big.NewInt(0)
    16  	// Set i to be p - 10e6
    17  	i.SetString("496968652506233112158689", 10)
    18  
    19  	// Move temp big int out here so no possible GC thrashing
    20  	temp := big.NewInt(0)
    21  	// Avoid creating the new bigint each time
    22  	two := big.NewInt(2)
    23  	for {
    24  		// Sanity check
    25  		ctr++
    26  		if ctr == 5000100 {
    27  			panic("oops")
    28  		}
    29  		// Check if the odd number is a divisor of n
    30  		temp.Mod(n, i)
    31  		if temp.Sign() == 0 {
    32  			fmt.Println(i)
    33  			break
    34  		}
    35  
    36  		i.Add(i, two)
    37  	}
    38  }
    39  
    40  // Output:
    41  // 496968652506233122158689