Large Integer Arithmetic tool is always a boon for cryptographers and other math researchers, when I was in my college days I had a passion for Math, especially Prime Factorization and Public Key Cryptography, somehow I was not comfortable with using high level languages like java or python for these tasks despite their support for large integer arithmetic, but I needed some specific math libraries, after many days of search, I found a complete standalone large integer math library - Aribas.

Aribas is a large integer math interpreter written by Prof. Dr. Otto Forste with a rich collection of math libraries which can be used for cryptography and other number theory research, it can be called as a programming language in itself where you can write specific scripts and execute them using Aribas, something which will be very handy for programmers who want to develop their own utilities for specialized math functions and also integrate it to high level languages like java or C for robust math support.

Even though it has an excellent documentation, I would like to highlight some cool features of Aribas here so that it will make a best impression to you, so the next time you need to work with cryptography or any math project involving large integers, you can jump into this tool straightaway, the main motivation for me to write about this is I could find this highly effective tool only after a rigorous search for a large integer math library.

I am confident that once you skim through these sections, you will be bookmarking Aribas, thanks Prof. Dr. Otto Forste for this great tool.

Aribas is a lightweight tool which you can download from here, its available on all flavors of UNIX and Windows.

To invoke the interactive interpreter (something similar to the one in languages like python), unzip Aribas archive (aribasw.zip) and run aribasw executable from aribas directory, you are all set you explore the math world in seconds!

A couple of important Aribas settings which comes to my mind are

2.1. Floating Point Precision Settings

This is something you can configure through the interactive interpreter GUI (Aribasw -> Preferences -> FloatPrec) or in command line using the set_floatprec() function, depending on the precision, your floating point results will vary, for example consider the value of pi (22/7), the difference in results with floating point precisions set to 32 and 128 are shown below.

==> set_floatprec(32).

-: 32

==> 22/7.

-: 3.14285714

==> set_floatprec(128).

-: 128

==> 22/7.

-: 3.14285_71428_57142_85714_28571_42857_14285_7

==>

2.2 Memory Settings

Since large integer math is a memory intensive operation and also Aribas is a language in itself, it uses its own heap and you can specify the memory size (in KB) which Aribas can use to execute your code (between 512KB to 32MB), something similar to specifying the heap size for JVM, for example you can specify a heap size of 10MB for Aribas by invoking Aribas with the -m option shown below

aribasw -m10000 (Uses upto 10MB)

Another useful function is memavail() which you can invoke to get the reserved/free memory available, for the above invocation of Aribas (with heap size of 10MB), the results I got were shown below.

==> memavail().

total number of garbage collections: 0

5091840 Bytes reserved; 5091840 Bytes active (44 used, 5091796 free)

58079 Bytes free for user defined symbols and symbol names

-: 4972

==>

Aribas is a complete language in itself for its purpose of large integer math support, this means it has control structures like if-else, looping constructs like for, while, file handling routines, I/O, different data types like Arrays, Strings, etc, in short you can have your own Aribas project with multiple source files for developing a tool which may solve your problem.

Look at some sample Aribas scripts here to understand the coding part of it.

4.1 Computing multiplicative inverse

This is an important function used frequently in cryptography and other math algorithms, the multiplicative inverse, multiplicative inverse of a and b is an integer m where (a * m) % b = 1

The multiplicative inverse of 5 and 24 is 5.

==> mod_inverse(5, 24).

-: 5

==>

The multiplicative inverse of 6 and 31 is 26.

==> mod_inverse(6, 31).

-: 26

==>

Even though it has an excellent documentation, I would like to highlight some cool features of Aribas here so that it will make a best impression to you, so the next time you need to work with cryptography or any math project involving large integers, you can jump into this tool straightaway, the main motivation for me to write about this is I could find this highly effective tool only after a rigorous search for a large integer math library.

1. Downloading, Invoking the Aribas interpreter |

2. Aribas Settings |

3. Scripting in Aribas |

4. Important Large Integer Math functions in Aribas |

5. A small tip (write it in your memory).. |

I am confident that once you skim through these sections, you will be bookmarking Aribas, thanks Prof. Dr. Otto Forste for this great tool.

Aribas is a lightweight tool which you can download from here, its available on all flavors of UNIX and Windows.

To invoke the interactive interpreter (something similar to the one in languages like python), unzip Aribas archive (aribasw.zip) and run aribasw executable from aribas directory, you are all set you explore the math world in seconds!

A couple of important Aribas settings which comes to my mind are

2.1. Floating Point Precision Settings

This is something you can configure through the interactive interpreter GUI (Aribasw -> Preferences -> FloatPrec) or in command line using the set_floatprec() function, depending on the precision, your floating point results will vary, for example consider the value of pi (22/7), the difference in results with floating point precisions set to 32 and 128 are shown below.

==> set_floatprec(32).

-: 32

==> 22/7.

-: 3.14285714

==> set_floatprec(128).

-: 128

==> 22/7.

-: 3.14285_71428_57142_85714_28571_42857_14285_7

==>

2.2 Memory Settings

Since large integer math is a memory intensive operation and also Aribas is a language in itself, it uses its own heap and you can specify the memory size (in KB) which Aribas can use to execute your code (between 512KB to 32MB), something similar to specifying the heap size for JVM, for example you can specify a heap size of 10MB for Aribas by invoking Aribas with the -m option shown below

aribasw -m10000 (Uses upto 10MB)

Another useful function is memavail() which you can invoke to get the reserved/free memory available, for the above invocation of Aribas (with heap size of 10MB), the results I got were shown below.

==> memavail().

total number of garbage collections: 0

5091840 Bytes reserved; 5091840 Bytes active (44 used, 5091796 free)

58079 Bytes free for user defined symbols and symbol names

-: 4972

==>

Aribas is a complete language in itself for its purpose of large integer math support, this means it has control structures like if-else, looping constructs like for, while, file handling routines, I/O, different data types like Arrays, Strings, etc, in short you can have your own Aribas project with multiple source files for developing a tool which may solve your problem.

Look at some sample Aribas scripts here to understand the coding part of it.

4.1 Computing multiplicative inverse

This is an important function used frequently in cryptography and other math algorithms, the multiplicative inverse, multiplicative inverse of a and b is an integer m where (a * m) % b = 1

The multiplicative inverse of 5 and 24 is 5.

==> mod_inverse(5, 24).

-: 5

==>

The multiplicative inverse of 6 and 31 is 26.

==> mod_inverse(6, 31).

-: 26

==>

4.2 Factorization and Prime numbers

There are several functions available for factoring a number using different algorithms which will be handy for researchers, like the quadratic sieve factorization algorithm shown below.

==> qs_factorize(437). (437 = 23 * 19)

-: 19

==>

Another function I found very useful is finding the next prime number

==> next_prime(35).

-: 37

==>

And primality tests

==> prime32test(119). (17 * 7)

-: 0 (false)

==> prime32test(179).

-: 1 (true)

==>

==> qs_factorize(437). (437 = 23 * 19)

-: 19

==>

Another function I found very useful is finding the next prime number

==> next_prime(35).

-: 37

==>

And primality tests

==> prime32test(119). (17 * 7)

-: 0 (false)

==> prime32test(179).

-: 1 (true)

==>

Believe me, these functions will reduce your effort greatly when you dealing with very large numbers.

For users of other scripting languages like python, this is something which needs to be bootstrapped in mind when you program in Aribas, end all your statements with a dot (.), please don't ask me how many times I keyed in Enter before doing that :).

## No comments:

Post a Comment