# CryptoCalculator - 2020

*The original version with just the powerMod calculator was attained from: https://www.mtholyoke.edu/courses/quenell/s2003/ma139/js/powermod.html

## CryptoCalculator

This is a piece of work created to help with identifying and understanding the beginner levels of IT Security and encryption techniques

The largest value that this Calculator can calculate is 9007199254740991 due to standard Javascript restrictions

For the Large Number Calculator (with no limits apart from the speed that your computer takes to process)
you can visit the other page Big Integer Calculator

*The Big Number Calculator also has more calculators and examples to work with...

## Modular Calculators:

### Mod Calculation

 Base: Modulus: b MOD m =

### PowerMod Calculation

 Base: Exponent: Modulus: be MOD m =

### Modular Inverse:

 Base k-1 (k-1) : Public key p (p) : k-1 MOD p =

## General Tools:

### Generate Random Prime number

 Random prime number maximum (max) : Random Prime Number =

### Generate Random Number

 Random number maximum (max) : Random Number =

## Elgamal Examples:

Sender has: y, g, p values

Receiver has all values and has secret x value

### Tools:

 [ p ] Generate a random prime number with the tool above and enter it in (p) : [ x ] Generates a random private key with the tool above for random number (x): [ r ] Generates a random number with the tool above for random number (r): [ g ] Choose a primitive root of (p) value (g): [ m ] Create message to encode (m):

## Encode:

### Step 1 - Calculate y (y):

 public key g (g) : private key x (x) : Public key p (p) : [ y ] = gx MOD p =

### Step 2 - Calculate k (k):

 public key y (y) : Random Number r (r) : Public key p (p) : [ k ] = yr MOD p =

### Step 3 - Calculate Code 1 (C1):

 public key g (g) : Random Number r (r) : Public key p (p) : [ C1 ] = gr MOD p =

### Step 4 - Calculate Code 2 (C2):

 Cipher Text m (m) : K Value k (k) : Public key p (p) : [ C2 ] = m * k MOD p =

### Step 4 (Exponential) - Calculate Code 2 (C2):

 Cipher Text m (m) : K Value k (k) : Public key p (p) : G vlaue g (g) : (Exponential) [ C2 ] = (gm * k) MOD p =

## Decode:

### Step 1 - Calculate (encoded) k (k):

 Code 1 (C1) : Private Key x (x) : Public key p (p) : (decoded) [ k ] = C1x MOD p =

### Step 2 - Modular Inverse:

 Base k(k) : Public key p (p) : k-1 =

### Step 3 - Decrypt Message:

 Modular inverse number (k-1) : Code 2 C2(C2) : Public key p (p) : (message) [ m ] = k-1C2 MOD p =

### Step 3 - Exponential Decrypt Message:

#### Get Value A:

*Use C2 value from Step 4 (Exponential) - Calculate Code 2 (C2)

 Modular inverse number (k-1) : (Step 4 (Exponential) - Calculate) Code 2 C2(C2) : Public key p (p) : [ a ] = k-1C2 MOD p =

#### Get Message:

 Enter Value A (a) : Value G (g) : Public key p (p) : (message) [ m ] = gm MOD p =

## Paillier Examples:

Sender has: n,g Values

Receiver has all values including secret λ and μ values

### Tools:

*If you want to manually enter the values, enter them in the inputs instead of clicking on compute button

 [ p ] Generate a random prime number for (p) : Enter maximum value of number then click compute: [ q ] Generate a random prime number based on (p) : Enter maximum value of number then click compute: [ n ] Calculate based on (p) and (q) : [ g ] Generate (g) based on (n) : [ r ] Generate random number (r) : Enter maximum value of number then click compute: [ m ] Create message to encode (m):

## Encode:

### Get λ (Lambda) value:

 Enter Value P (p) : Value Q (q) : [ λ ] = lcm(p - 1, q - 1) =

### Calculate K Value :

 Enter Value G (g) : Value λ (Lambda) (λ) : Value N (n) : [ k ] = L(gλ MOD n2) =

### Calculate μ (Mu) Value :

 Base k (k) : Public key n (n) : [ μ ] = k-1 MOD n =

### Encrypt Message (c) :

 Base g (g) : Base r (r) : Exponent and Modulus n (n) : Message to encrypt m (m) : [ c ] = gmrn MOD n2 =

## Decode:

### Decrypt Message (M) :

 Encrypted message c (c) : Exponent λ (λ) : Modulus n (n) : Value μ(μ) : [ m ] = L(cλMOD n2).μ MOD n =

## CryptoCalculator

Created by: @sqeel404

### Description

This project was put together during the mid semester break to help identify and understand the underlying concepts, formulas and principles within the Cryptography classes.

There are 3 main pages:

#### index.html - https://cryptocalc.giondesign.com.au/original-content/originalcalc.html

This is the original site, it holds the standard base calculations in javascript, however due to the javascript large number limitations it can not hadle substantially large numbers, so it ony contains the basic concepts and tools, such as:

• Modulus calculation
• Power modulus calculations
• Modulus Inverse Calculations
• Random Prime number
• Random number
• Elgamal Encryption
• Elgamal Decryption
• Paillier Encryption
• Paillier Decryption

#### BigIntCalculator.html - https://cryptocalc.giondesign.com.au/original-content/bigintcalculator/bigintcalculator.html

This is a child of the original site, it has the same initial calculations, however this version uses the BigInteger.js javascript library which allows uses to do calculations on substantially large numbers. Due to this, further examples have been added as they can use substantially larger numbers for their calculations.

The tools so far are:

• Modulus calculation
• Power modulus calculations
• Modulus Inverse Calculations
• Random Prime number
• Random number
• Convert Number to Binary
• Convert Binary to Number
• Elgamal Encryption
• Elgamal Decryption
• Paillier Encryption
• Paillier Decryption
• Elgamal Homomorphic encryption/decryption and multiplication of secret numbers

*The Paillier version for secret addition of numbers will be added shortly for reference.

### Main Site - https://cryptocalc.giondesign.com.au/

This is the new main site and holds all the original calculators, plus extra General tools, hashing examples, IPFS examples and more.

The main site is now the updated version to follow and use as it has substantially higher calculations, resources and tools.

Enjoy, and hope it helps fellow users in their cryptographic learnings and education.