Learn R Programming

gmp (version 0.2-2)

bigz: Large sized integer values

Description

Type class supporting arithmetic operations on very large integers.

Usage

as.bigz(a, mod = NA)
as.character.bigz(a)
as.double.bigz(x,...)is.na.bigz(a)
print.bigz(x,...)

Arguments

a
Either integer, numeric or string value (String value: ither starting with 0x for hexadecimal, 0b for binary or without prefix for decimal values. Any format error results in 0)
x
Numeric value
...
Additional parameters
mod
An integer, numeric, string or bigz of the internal modulus, see below.

Value

  • A bigz class representing the parameter value.

Details

Bigzs are integers of infinite, but given length (means: only restricted by the host memory). Basic arithmetic operations can be performed on bigzs as addition, subtraction, multiplication, division, modulation (remainder of division), power, multiplicative inverse, calculating of the greatest common divisor, test whether the integer is prime and other things that comes in need when performing standard cryptographic operations.

For a review of basic arithmetics, see "add.bigz".

The most important logical operators are supported, such as "==", "!=", "<"< code="">, "<="< code="">, ">", and ">=".

Objects of class "bigz" may have an attribute mod which specifies a modulus that is applied after each arithmetic operation. If the result is going to have a modulus, result = mod.bigz(result, modulus) is called after performing the arithmetic operation and the result will have the attribute mod set accordingly.

Powers of bigzs can only be performed, if either a modulus is going to be applied to the result bigz or if the exponent fits into an integer value. So if you want to calculate a power in a finite group, don't use a ^ b %% c, but use as.bigz(a,c) ^ b, instead. The following rules for the result's modulus apply when performing arithmetic operations on bigzs:

If none of the operand has a modulus set, the result will not have a modulus. If both operands have a different modulus, the result will not have a modulus, except in case of "mod.bigz", where the second operands value is used. If only one of the operands has a modulus or both have a common (the same), it is set and applied to the result, except in case of mod.bigz, where the second operands value is used.

Gnu MP Library see http://swox.com/gmp, Home page: http://mulcyber.toulouse.inra.fr/projects/gmp/

[object Object] ## 1+1=2 a = as.bigz(1) a + a

## calculate c = x^e mod n x <- as.bigz("0x123456789abcdef") # my secret message e <- as.bigz(3) # something smelling like a dangerous public RSA exponent n <- as.bigz("0x4378a27...") # probably a product of two primes

# first way to do it right modulus(x) <- n c <- x ^ e

# similar second way (maybe more sensefull if you reuse e) to do it right modulus(e) <- n c <- x ^ e

# third way to do it right c <- x ^ as.bigz(e, n)

# WRONG! (although very beautiful. Maybe ok for small examples) c <- x ^ e

arith