Big Integers in JavaScript
Home | Machine Learning | Crypto | Graphics
Passphrase Generator | Self-Decrypting Email | Visual Crypto | BigInts

This page demonstrates a JavaScript library for arbitrary-precision integers, BigInt.js. This page performs RSA in any base. In base 95, the message can be ordinary text. Click all the buttons in order to perform all the steps of RSA key generation, encryption, and decryption. Or just click the DO EVERYTHING button.

Time (sec)
  Display numbers in:  
  The plaintext message: m=  
  The public exponent: e=  
  p, q: bits each p=
  q=
  n=
  phi=
  d=
  c=
  m'=
  m''=
      m'' uses secret p and q to be faster.
P=c^d mod p
Q=c^d mod q
m''=((Q-P)*(p^-1) mod q)*p+P
 
         

The library allows addition, subtraction, multiplication, division, exponentiation, and inverses modulo an arbitrary number. It has the extended Euclid algorithm, and can convert between bases up to base 95. It generates true prime numbers rather than probable primes. For Internet Explorer on a 1.8 GHz WinXP machine, RSA-1024 takes 0.38 seconds to encrypt and 22 seconds to decrypt. Generating the pair of 512-bit primes usually takes around 6 minutes, and is almost always under 10 minutes. Generating a 256-bit prime takes about 14 seconds.

It's hard to imagine any practical use for this code, other than pedagogical. JavaScript is obviously too slow for most purposes. The language doesn't even specify the size of integers, so the code has to determine at runtime how many bits it can store in each array element. This page was just written for my entertainment, after seeing a request for something like this on sci.crypt.

(c) 2000-2004 Leemon Baird