sac

package
v1.2.35 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 29, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// number of parallel siever instances
	NUM_SIEVERS = 20

	// number of parallel solver instances.
	NUM_SOLVERS = 10
)
View Source
const (
	REDUCABLE = iota
	REDUCED
	INSERTED
	DISJUNCT
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Director

type Director struct {
	// contains filtered or unexported fields
}

The director is the controller for solver and siever instances in a parallel implementation.<p>

func (*Director) Factorize

func (d *Director) Factorize(m *math.Int) *math.Int

Factorize integer m and return a factor.<p> @param m BigInteger - value to be factorized @return BigInteger - factor of m

func (*Director) Handled

func (d *Director) Handled(id int, r Relation, rc int)

Solver response: Relation r has finished with given result.<p> @param id int - solver identifier @param r Relation - processed relation @param rc Result - processing state

func (*Director) Sieved

func (d *Director) Sieved(id int, x, y *math.Int) bool

Siever response: found new relation.<p> @param id int - siever identifier @param x BigInteger - x value of relation (function arg) @param y BigInteger - y value (function result) @return boolean - relation accepted?

type FactorBase

type FactorBase interface {

	// Prepare factor base.<p>
	// @param m BigInteger - number to be factorized
	// @return boolean - successful operation?
	Init(m *math.Int) bool

	// Get number of primes in the factor base.<P>
	// @return int - number of primes in factor base
	GetNumPrimes() int

	// Get the i.th primes in the factor base.<p>
	// @param i int - prime index
	// @return BigInteger - prime value
	GetPrime(i int) *math.Int

	// Solve the equation x^2 = m (mod p)
	// @param i int - prime index in factor base
	// @return BigInteger - solution (x)
	GetSqrt(i int) *math.Int

	// Get index of first (smallest) prime from factor base that
	// is a factor of f.<p>
	// @param f BigInteger - number (unsquare part of y)
	// @param pos int - last index (smaller than new index)
	// @return int - index of first occurring prime
	FirstPrimeIndex(f *math.Int, pos int) int

	// Extract a sub factor base.<p>
	// @param id int - identifier of sub factor base
	// @param start int - offset into full factor base
	// @param size int - number of successive primes
	// @return FactorBase - extracted sub factor base
	GetSubBase(id, start, size int) FactorBase

	// Check if number has a prime factor in factor base.<p>
	// @param a BigInteger - number to be tested
	// @return boolean - number has factor in factor base
	Covers(a *math.Int) bool

	// Get identifier of factor base.<p>
	// @return int - identifier
	GetId() int
}

Factor base: contains a given number of suitable primes.<p> A prime 'p' can be included in the factor base if 'm' (the number to be factorized) is a quadratic residue modulo p.<p> An integer y is smooth over fb if all the prime factors of y are contained in the factor base fb.<p>

type FactorBaseImpl

type FactorBaseImpl struct {
	Instance

	FbMult *math.Int // multiplicative = Prod(i=1,B) p(i)
	// contains filtered or unexported fields
}

Factor base: contains a given number of suitable primes.<p> A prime 'p' can be included in the factor base if 'm' (the number to be factorized) is a quadratic residue modulo p.<p> An integer y is smooth over fb if all the prime factors of y are contained in the factor base fb.<p>

func (*FactorBaseImpl) Covers

func (fb *FactorBaseImpl) Covers(a *math.Int) bool

Check if number has a prime factor in factor base.<p> @param a BigInteger - number to be tested @return boolean - number has factor in factor base

func (*FactorBaseImpl) FirstPrimeIndex

func (fb *FactorBaseImpl) FirstPrimeIndex(f *math.Int, pos int) int

Get index of first (smallest) prime from factor base that is a factor of f.<p> @param f BigInteger - number (unsquare part of y) @param pos int - last index (smaller than new index) @return int - index of first occurring prime

func (*FactorBaseImpl) GetId

func (fb *FactorBaseImpl) GetId() int

Get identifier of factor base.<p> @return int - identifier

func (*FactorBaseImpl) GetNumPrimes

func (fb *FactorBaseImpl) GetNumPrimes() int

Get number of primes in the factor base.<P> @return int - number of primes in factor base

func (*FactorBaseImpl) GetPrime

func (fb *FactorBaseImpl) GetPrime(i int) *math.Int

Get the i.th primes in the factor base.<p> @param i int - prime index @return BigInteger - prime value

func (*FactorBaseImpl) GetSqrt

func (fb *FactorBaseImpl) GetSqrt(i int) *math.Int

Solve the equation x^2 = m (mod p) @param i int - prime index in factor base @return BigInteger - solution (x)

func (*FactorBaseImpl) GetSubBase

func (fb *FactorBaseImpl) GetSubBase(id, start, size int) FactorBase

Extract a sub factor base.<p> @param id int - identifier of sub factor base @param start int - offset into full factor base @param size int - number of successive primes @return FactorBase - extracted sub factor base

func (*FactorBaseImpl) Init

func (fb *FactorBaseImpl) Init(m *math.Int) bool

Prepare factor base.<p> @param m BigInteger - number to be factorized @return boolean - successful operation?

type Function

type Function struct {
	// contains filtered or unexported fields
}

Quadratic function used for sieving: y = x^2 - m = (x'+r)^2 - m<p> x is always small so that y < 2m is ensured; x' = 1..x'(max)<p>

func NewFunction

func NewFunction(n *math.Int) *Function

Instanciate function (and compute/initialize helpers).<p> @param n BigInteger - number to be decomposed

func (*Function) F

func (f *Function) F(x *math.Int) *math.Int

Compute function result y = (x+r)^2 - m.<p> @param x BigInteger - x argument @return BigInteger - function result

type Instance

type Instance interface {

	// Set instance identification (id and name).<p>
	// @param id int - identifier
	// @param name String - instance name
	Ident(id int, name string)

	// Return instance identifier.<p>
	// @return int - instance identifier
	GetId() int

	// Check if instance is active.<p>
	// @return boolean - instance active?
	IsActive() bool

	// Terminate instance.<p>
	Terminate()

	Run()
}

An instance can run concurrently with other instances (of same or different type).<p>

type InstanceImpl

type InstanceImpl struct {
	// contains filtered or unexported fields
}

An instance can run concurrently with other instances (of same or different type).<p>

func (*InstanceImpl) GetId

func (i *InstanceImpl) GetId() int

Return instance identifier.<p> @return int - instance identifier

func (*InstanceImpl) Ident

func (i *InstanceImpl) Ident(id int, name string)

Set instance identification (id and name).<p> @param id int - identifier @param name String - instance name

func (*InstanceImpl) IsActive

func (i *InstanceImpl) IsActive() bool

Check if instance is active.<p> @return boolean - instance active?

func (*InstanceImpl) Terminate

func (i *InstanceImpl) Terminate()

Terminate instance.<p>

type Queue

type Queue struct {
	// contains filtered or unexported fields
}

A queue is a FIFO stack for relations.>p> Adding and retrieving relations is thread-safe.<p>

func NewQueue

func NewQueue(id int) *Queue

Instanciate a new queue with given identifier.<p> @param id int - queue identifier

func (*Queue) Get

func (q *Queue) Get() (r Relation)

Get relation from queue.<p> If the queue is empty, the method waits for a new entry to arrive in the queue. A return value of 'null' indicates an error/exception.<p> @return Relation - retrieved relation (first in list)

func (*Queue) NumEntries

func (q *Queue) NumEntries() int

Get number of entries in the queue.<p> @return

func (*Queue) Put

func (q *Queue) Put(r Relation)

Put relation into queue (append to end of list).<p> @param r Relation - relation to be stored

func (*Queue) String

func (q *Queue) String() string

Generate a printable representation of the queue object.<p> @return String - queue in printable (and readable) form

type Relation

type Relation interface {

	// Initialize new relation for (x,y)<p>
	// @param x BigInteger - argument to square function
	// @param y BigInteger - fb-smooth function result
	Init(x, y *math.Int)

	// Normalize relation over factor base (reduce yh)<p>
	// @param fb FactorBase - factor base for reduction
	// @param m BigInteger - modulus
	Normalize(fb FactorBase, m *math.Int)

	// Multiply this relation with r:  this = this * r<p>
	// @param r Relation - multiplicator from list
	// @param fb FactorBase - factor base for reduction
	// @param m BigInteger - modulus
	Multiply(r Relation, fb FactorBase, m *math.Int)

	// Get smallest prime factor of f.<p>
	// @param fb FactorBase - list of primes
	// @return int - index of first prime
	FirstPrimeIndex(fb FactorBase, pos int) int

	// Returns (x-s) if relation is square (x^2 = s^2 mod m).<p>
	// @return BigInteger - (x-s) if square or null otherwise
	IsSquared() *math.Int

	// Check if h has factors in factor base fb.<p>
	// @param fb FactorBase - factor base to be used
	// @return boolean - h has factors in fb
	IsReducable(fb FactorBase) bool

	// Check if relation is completely reduced.<p>
	// @return boolean - relation reduced?
	IsReduced() bool

	// Check if f has factors in factor base fb.<p>
	// @param fb FactorBase - factor base to be used
	// @return boolean - f has factors in fb
	IsCovered(fb FactorBase) bool

	// Generate printable representation of relation.<p<
	// @return String - printable (and readable) relation
	String() string
}

A relation (x,y) with x square and y smooth over factor base.<p> Relations can be combined and eventually lead to a y value that is a quadratic residue modulo m.<p>

type RelationImpl

type RelationImpl struct {
	// contains filtered or unexported fields
}

A relation (x,y) with x square and y smooth over factor base.<p> Relations can be combined and eventually lead to a y value that is a quadratic residue modulo m.<p>

func (*RelationImpl) FirstPrimeIndex

func (r *RelationImpl) FirstPrimeIndex(fb FactorBase, pos int) int

Get smallest prime factor of f.<p> @param fb FactorBase - list of primes @return int - index of first prime

func (*RelationImpl) Init

func (r *RelationImpl) Init(x, y *math.Int)

Initialize new relation for (x,y)<p> @param x BigInteger - argument to square function @param y BigInteger - fb-smooth function result

func (*RelationImpl) IsCovered

func (r *RelationImpl) IsCovered(fb FactorBase) bool

Check if f has factors in factor base fb.<p> @param fb FactorBase - factor base to be used @return boolean - f has factors in fb

func (*RelationImpl) IsReducable

func (r *RelationImpl) IsReducable(fb FactorBase) bool

Check if h has factors in factor base fb.<p> @param fb FactorBase - factor base to be used @return boolean - h has factors in fb

func (*RelationImpl) IsReduced

func (r *RelationImpl) IsReduced() bool

Check if relation is completely reduced.<p> @return boolean - relation reduced?

func (*RelationImpl) IsSquared

func (r *RelationImpl) IsSquared() *math.Int

Returns (x-s) if relation is square (x^2 = s^2 mod m).<p> @return BigInteger - (x-s) if square or null otherwise

func (*RelationImpl) Multiply

func (r *RelationImpl) Multiply(re Relation, fb FactorBase, m *math.Int)

Multiply this relation with r: this = this * r<p> @param r Relation - multiplicator from list @param fb FactorBase - factor base for reduction @param m BigInteger - modulus

func (*RelationImpl) Normalize

func (r *RelationImpl) Normalize(fb FactorBase, m *math.Int)

Normalize relation over factor base (reduce yh)<p> @param fb FactorBase - factor base for reduction @param m BigInteger - modulus

func (*RelationImpl) String

func (r *RelationImpl) String() string

Generate printable representation of relation.<p< @return String - printable (and readable) relation

type Siever

type Siever interface {
	Instance

	// Initialize solver instance.<p>
	// @param id int - siever identifier
	// @param m BigInteger - number to be factorized
	// @param fb FactorBase - factor base to be used
	// @param cb SieverCallback - callback for siever rersponses
	// @return boolean - successful operation?
	Init(id int, m *math.Int, fb FactorBase, cb SieverCallback) bool

	// Set siever interval for siever instance.<p>
	// @param x0 BigInteger - start of interval
	// @param x1 BigInteger - end of interval (inclusive)
	SetSieveInterval(x0, x1 *math.Int)
}

The Siever interface generically describes the methods of a siever instance.<p>

type SieverCallback

type SieverCallback func(id int, x, y *math.Int) bool

Handle a sieved relation (x,y).<p> @param id int - identifier of siever @param x BigInteger - x value (function arg) @param y BigInteger - y value (function result) @return boolean - relation accepted?

type SieverImpl

type SieverImpl struct {
	InstanceImpl
	// contains filtered or unexported fields
}

Sieve relations (x,y) with x^2 = y (mod m) and y smooth over factor base from a given sieve interval.<p>

func (*SieverImpl) Init

func (s *SieverImpl) Init(id int, m *math.Int, fb FactorBase, cb SieverCallback) bool

Initialize solver instance.<p> @param id int - siever identifier @param m BigInteger - number to be factorized @param fb FactorBase - factor base to be used @param cb SieverCallback - callback for siever rersponses @return boolean - successful operation?

func (*SieverImpl) Run

func (s *SieverImpl) Run()

Run instance process.<p>

func (*SieverImpl) SetSieveInterval

func (s *SieverImpl) SetSieveInterval(x0, x1 *math.Int)

Set siever interval for siever instance.<p> @param x0 BigInteger - start of interval @param x1 BigInteger - end of interval (inclusive)

type Solver

type Solver interface {
	Instance

	// Put relation into input queue for solver.<p>
	// This method is called by another thread (Director).<p>
	// @param r Relation - new relation for solver
	// @return boolean - delivery successful?
	Put(r Relation) bool

	// Initialize solver instance.<p>
	// @param id int - solver identifier
	// @param m BigInteger - number to be factorized
	// @param fb Factorbase - factor base to be used
	// @param cb SolverCallback - callback for requests/responses
	// @return boolean - successful operation?
	Init(id int, m *math.Int, fb FactorBase, cb SolverCallback) bool

	// Return number of pending relations in input queue.<p>
	// @return int - number of pending relations
	NumPending() int
}

Generic interface for solver instances.<p>

type SolverCallback

type SolverCallback func(id int, r Relation, rc int)

Response -- relation handled with result state.<p> @param id int - solver identifier @param r Relation - processed relation @param rc Result - result / processing state

type SolverImpl

type SolverImpl struct {
	InstanceImpl
	// contains filtered or unexported fields
}

A solver instance handle relations for a section of the factor base.<p> A transformed relation is returned together with state information.<p>

func (*SolverImpl) Init

func (s *SolverImpl) Init(id int, m *math.Int, fb FactorBase, cb SolverCallback) bool

Initialize solver instance.<p> @param id int - solver identifier @param m BigInteger - number to be factorized @param fb Factorbase - factor base to be used @param cb SolverCallback - callback for requests/responses @return boolean - successful operation?

func (*SolverImpl) NumPending

func (s *SolverImpl) NumPending() int

Return number of pending relations in input queue.<p> @return int - number of pending relations

func (*SolverImpl) Put

func (s *SolverImpl) Put(r Relation) bool

Put relation into input queue for solver.<p> This method is called by another thread (Director).<p> @param r Relation - new relation for solver @return boolean - delivery successful?

func (*SolverImpl) Run

func (s *SolverImpl) Run()

Start the solver process.<p>

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL