An RSA implementation in NodeJS
This is an RSA calculator to compute prime numbers(p, q), mod value, psi value, public and private exponents. You can also perform string encryption and decryption.
Features:
- Calculating primes(p, q), mod value(n), psi value(psi), public exponent(e) and private exponent(d).
- All values are generated based on one input which is size of mod (n) (in bits)
- String encryption and decryption.
Algorithm:
Suppose the required size of mod value is 16bits.
- Generate two prime numbers (p, q) such that the size of their product (which is mod value, n) is 16.
n = p * q
- Calculate psi value.
psi = (p-1) * (q-1)
- Compute a public exponent (e) such that e and psi are co-primes and 0 < e < psi.
e
- Compute private exponent (d).
For a constant k, d = (k*psi + 1)/e; such that (k*psi + 1) % e = 0
- For encryption
c = (t^e) % n
- For decryption
t = (c^d) % n
Example:
- size = 16bits
- p = 181; q = 191;
- n =p*q = 34571
- psi = (p-1)(q-1) = 34200
- e = 7
- d = 19543
Instructions:
- Clone the Repo
- Install dependencies
npm install
- Check index.js file for implementation
✌️Thats it!!✌️
PS: The maximum acceptable size of mod value is 31