bigz                   package:gmp                   R Documentation

_L_a_r_g_e _s_i_z_e_d _i_n_t_e_g_e_r _v_a_l_u_e_s

_D_e_s_c_r_i_p_t_i_o_n:

     Type class supporting arithmetic operations on very large
     integers.

_U_s_a_g_e:

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

_A_r_g_u_m_e_n_t_s:

       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.

_D_e_t_a_i_l_s:

     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:

     *  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.

_V_a_l_u_e:

     A bigz class representing the parameter value.

_N_o_t_e:

     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")

_A_u_t_h_o_r(_s):

     Immanuel Scholz

_R_e_f_e_r_e_n_c_e_s:

     Gnu MP Library see http://swox.com/gmp

_E_x_a_m_p_l_e_s:

     ## 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)

