bigz {gmp} | R Documentation |
Type class supporting arithmetic operations on very large integers.
as.bigz(a, mod = NA) as.character.bigz(x,b=10,...) as.double.bigz(x,...) is.na.bigz(x) print.bigz(x,...)
a |
Either integer, numeric or string value
(String value: ither starting with 0x for hexadecimal, 0b for
binary, 0 for octal or without prefix for decimal values.
Any format error results return an Error message) |
b |
Base: from 2 to 32 |
x |
Numeric value |
... |
Additional parameters |
mod |
An integer, numeric, string or bigz of the internal modulus, see below. |
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 "=="
, "!="
,
"<"
, "<="
, ">"
, 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:
"mod.bigz"
, where the second operands
value is used.
A bigz class representing the parameter value.
x = as.bigz(1234567890123456789012345678901234567890) will not work as integer will be first converted to a double and then converted to a "bigz" element.
Correct syntaxe: x = as.bigz("1234567890123456789012345678901234567890")
Immanuel Scholz
Gnu MP Library see http://swox.com/gmp
## 1+1=2 a = as.bigz(1) a + a ## Not run: ## 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 # Return result in hexa as.character(c,b=16) ## End(Not run)