C# Класс MpcLib.Common.FiniteField.NumTheoryUtils

Implements some number-theoretic utility functions.
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
DHPrime1536 System.Numerics.BigInteger
DHPrime2048 System.Numerics.BigInteger
DHPrime768 System.Numerics.BigInteger

Открытые методы

Метод Описание
CalcInverse ( System.Numerics.BigInteger n, System.Numerics.BigInteger prime ) : System.Numerics.BigInteger

Returns the inverse of n modulo p.

DLEncrypt ( BigZp x, System.Numerics.BigInteger p ) : System.Numerics.BigInteger

Discrete logarithm encryption.

ExtendedEuclidean ( System.Numerics.BigInteger a, System.Numerics.BigInteger b, System.Numerics.BigInteger &x, System.Numerics.BigInteger &y ) : System.Numerics.BigInteger

Performs the Extended Euclidean algorithm and returns gcd(a,b). The function also returns integers x and y such that ax + by = gcd(a,b). If gcd(a,b) = 1, then x is a multiplicative inverse of "a mod b" and y is a multiplicative inverse of "b mod a".

ExtendedEuclidean ( int a, int b, int &x, int &y ) : int

Performs the Extended Euclidean algorithm and returns gcd(a,b). The function also returns integers x and y such that ax + by = gcd(a,b). If gcd(a,b) = 1, then x is a multiplicative inverse of "a mod b" and y is a multiplicative inverse of "b mod a".

ExtendedEuclidean ( long a, long b, long &x, long &y ) : long

Performs the Extended Euclidean algorithm and returns gcd(a,b). The function also returns integers x and y such that ax + by = gcd(a,b). If gcd(a,b) = 1, then x is a multiplicative inverse of "a mod b" and y is a multiplicative inverse of "b mod a".

GetBitDecomposition ( System.Numerics.BigInteger a, System.Numerics.BigInteger prime ) : List
GetBitDecomposition ( System.Numerics.BigInteger a, System.Numerics.BigInteger prime, int length ) : List
GetBitLength ( System.Numerics.BigInteger a ) : int

Returns the actual number of bits of a byte array by ignoring trailing zeros in the binary representation.

GetBitLength ( byte a ) : int

Returns the actual number of bits of a byte array by ignoring trailing zeros in the binary representation.

GetBitLength2 ( System.Numerics.BigInteger a ) : int
GetFieldInverse ( int prime ) : int[]

Returns an array containing inverses of all field elements.

GetFieldMinimumPrimitive ( int prime ) : int
IsPrime ( int n ) : bool

Performs a O(sqrt(|n|)) primality test, where |n| is the bit-length of the input.

MillerRabin ( System.Numerics.BigInteger n, int k ) : bool

Implements the Miller-Rabin algorithm for fast compositeness test. Returns true if n is a composite number. If n is prime, returns false with high probability (this probability increases with k).

ModPow ( int powerBase, int exp, int prime ) : int

Performs modular exponentiation.

ModSqrRoot ( System.Numerics.BigInteger val, System.Numerics.BigInteger prime ) : System.Numerics.BigInteger
MultiplicativeInverse ( System.Numerics.BigInteger a, System.Numerics.BigInteger m ) : System.Numerics.BigInteger

Returns the multiplicative inverse of a modulo m.

MultiplicativeInverse ( int a, int m ) : int

Returns the multiplicative inverse of a modulo m.

MultiplicativeInverse ( long a, long m ) : long

Returns the multiplicative inverse of a modulo m.

NextRandomBigInt ( RNGCryptoServiceProvider rng, System.Numerics.BigInteger minValue, System.Numerics.BigInteger maxValue ) : System.Numerics.BigInteger

Returns a random big integer in the specified range. This is based on a simple probabilistic algorithm.

Описание методов

CalcInverse() публичный статический Метод

Returns the inverse of n modulo p.
public static CalcInverse ( System.Numerics.BigInteger n, System.Numerics.BigInteger prime ) : System.Numerics.BigInteger
n System.Numerics.BigInteger
prime System.Numerics.BigInteger
Результат System.Numerics.BigInteger

DLEncrypt() публичный статический Метод

Discrete logarithm encryption.
public static DLEncrypt ( BigZp x, System.Numerics.BigInteger p ) : System.Numerics.BigInteger
x BigZp Value to be encrypted.
p System.Numerics.BigInteger Prime modulus. Should be large enough (> 1024 bits) to ensure security.
Результат System.Numerics.BigInteger

ExtendedEuclidean() публичный статический Метод

Performs the Extended Euclidean algorithm and returns gcd(a,b). The function also returns integers x and y such that ax + by = gcd(a,b). If gcd(a,b) = 1, then x is a multiplicative inverse of "a mod b" and y is a multiplicative inverse of "b mod a".
public static ExtendedEuclidean ( System.Numerics.BigInteger a, System.Numerics.BigInteger b, System.Numerics.BigInteger &x, System.Numerics.BigInteger &y ) : System.Numerics.BigInteger
a System.Numerics.BigInteger
b System.Numerics.BigInteger
x System.Numerics.BigInteger
y System.Numerics.BigInteger
Результат System.Numerics.BigInteger

ExtendedEuclidean() публичный статический Метод

Performs the Extended Euclidean algorithm and returns gcd(a,b). The function also returns integers x and y such that ax + by = gcd(a,b). If gcd(a,b) = 1, then x is a multiplicative inverse of "a mod b" and y is a multiplicative inverse of "b mod a".
public static ExtendedEuclidean ( int a, int b, int &x, int &y ) : int
a int
b int
x int
y int
Результат int

ExtendedEuclidean() публичный статический Метод

Performs the Extended Euclidean algorithm and returns gcd(a,b). The function also returns integers x and y such that ax + by = gcd(a,b). If gcd(a,b) = 1, then x is a multiplicative inverse of "a mod b" and y is a multiplicative inverse of "b mod a".
public static ExtendedEuclidean ( long a, long b, long &x, long &y ) : long
a long
b long
x long
y long
Результат long

GetBitDecomposition() публичный статический Метод

public static GetBitDecomposition ( System.Numerics.BigInteger a, System.Numerics.BigInteger prime ) : List
a System.Numerics.BigInteger
prime System.Numerics.BigInteger
Результат List

GetBitDecomposition() публичный статический Метод

public static GetBitDecomposition ( System.Numerics.BigInteger a, System.Numerics.BigInteger prime, int length ) : List
a System.Numerics.BigInteger
prime System.Numerics.BigInteger
length int
Результат List

GetBitLength() публичный статический Метод

Returns the actual number of bits of a byte array by ignoring trailing zeros in the binary representation.
public static GetBitLength ( System.Numerics.BigInteger a ) : int
a System.Numerics.BigInteger
Результат int

GetBitLength() публичный статический Метод

Returns the actual number of bits of a byte array by ignoring trailing zeros in the binary representation.
public static GetBitLength ( byte a ) : int
a byte
Результат int

GetBitLength2() публичный статический Метод

public static GetBitLength2 ( System.Numerics.BigInteger a ) : int
a System.Numerics.BigInteger
Результат int

GetFieldInverse() публичный статический Метод

Returns an array containing inverses of all field elements.
public static GetFieldInverse ( int prime ) : int[]
prime int
Результат int[]

GetFieldMinimumPrimitive() публичный статический Метод

public static GetFieldMinimumPrimitive ( int prime ) : int
prime int
Результат int

IsPrime() публичный статический Метод

Performs a O(sqrt(|n|)) primality test, where |n| is the bit-length of the input.
public static IsPrime ( int n ) : bool
n int
Результат bool

MillerRabin() публичный статический Метод

Implements the Miller-Rabin algorithm for fast compositeness test. Returns true if n is a composite number. If n is prime, returns false with high probability (this probability increases with k).
public static MillerRabin ( System.Numerics.BigInteger n, int k ) : bool
n System.Numerics.BigInteger
k int
Результат bool

ModPow() публичный статический Метод

Performs modular exponentiation.
public static ModPow ( int powerBase, int exp, int prime ) : int
powerBase int
exp int
prime int
Результат int

ModSqrRoot() публичный статический Метод

public static ModSqrRoot ( System.Numerics.BigInteger val, System.Numerics.BigInteger prime ) : System.Numerics.BigInteger
val System.Numerics.BigInteger
prime System.Numerics.BigInteger
Результат System.Numerics.BigInteger

MultiplicativeInverse() публичный статический Метод

Returns the multiplicative inverse of a modulo m.
public static MultiplicativeInverse ( System.Numerics.BigInteger a, System.Numerics.BigInteger m ) : System.Numerics.BigInteger
a System.Numerics.BigInteger
m System.Numerics.BigInteger
Результат System.Numerics.BigInteger

MultiplicativeInverse() публичный статический Метод

Returns the multiplicative inverse of a modulo m.
public static MultiplicativeInverse ( int a, int m ) : int
a int
m int
Результат int

MultiplicativeInverse() публичный статический Метод

Returns the multiplicative inverse of a modulo m.
public static MultiplicativeInverse ( long a, long m ) : long
a long
m long
Результат long

NextRandomBigInt() публичный статический Метод

Returns a random big integer in the specified range. This is based on a simple probabilistic algorithm.
public static NextRandomBigInt ( RNGCryptoServiceProvider rng, System.Numerics.BigInteger minValue, System.Numerics.BigInteger maxValue ) : System.Numerics.BigInteger
rng System.Security.Cryptography.RNGCryptoServiceProvider
minValue System.Numerics.BigInteger Inclusive lower bound.
maxValue System.Numerics.BigInteger Exclusive upper bound.
Результат System.Numerics.BigInteger

Описание свойств

DHPrime1536 публичное статическое свойство

public static BigInteger,System.Numerics DHPrime1536
Результат System.Numerics.BigInteger

DHPrime2048 публичное статическое свойство

public static BigInteger,System.Numerics DHPrime2048
Результат System.Numerics.BigInteger

DHPrime768 публичное статическое свойство

public static BigInteger,System.Numerics DHPrime768
Результат System.Numerics.BigInteger