# 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 - BigInteger version

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

This version uses the BigInteger.js Library which can handle very large numbers in JavaScript and can be found at: https://github.com/peterolson/BigInteger.js

## Modular Calculators:

### Mod Calculation

 Base Value: Modulus: b MOD m =

### PowerMod Calculation

 Base: Exponent: Modulus: be MOD m =

### Modular Inverse:

 Base k-1 (k-1) : Modulus (m) : k-1 MOD m =

## General Tools:

### Generate Random Prime number

#For fun, you input an extremely large number into the maximum field,
open the console in inspector and watch how many calculations are made before finding a match...
depending on the number can take some time...

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

### Generate Random Number

 Random number maximum (max) : Random Number =

### Convert number to Binary

 Number to convert to binary: Binary value =

### Convert Binary to Number

 Binary Value to convert to number: Binary value =

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

*Warning - before running this method, if it is a large number is will take alot of time and computing power to get the answer

 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) : Enter maximum value of number then click compute: [ 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 =

## Elgamal Homomorphism Examples (multiplying 2 numbers secretly):

*Secretly Multiplying 2 messages and returning a result (M = M1 * M2)

### Tools:

#For fun, you can input an extremely large number into the maximum field,
open the console in inspector and watch how many calculations are made before finding a match for [p], and [g]....
depending on the number can take some time....

 Maximum number for Random Number Generation : [ p ] Generate a random prime number for (p) : [ x ] Generates a random private key for (x): [ g ] Choose a primitive root of (p) value (g): [ r1 ] Generates a random number for (r1): [ r2 ] Generates a random number for (r2): [ m1 ] Create message to encode (m1): [ m2 ] Create message to encode (m2):

### Calculate y (y):

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

### Calculate k (k1):

 public key y (y) : Random Number r1 (r1) : Public key p (p) : [ k1 ] = yr1 MOD p =

### Calculate k (k2):

 public key y (y) : Random Number r2 (r2) : Public key p (p) : [ k2 ] = yr2 MOD p =

### Calculate Code 1 (C11):

 public key g (g) : Random Number r1 (r1) : Public key p (p) : [ C11 ] = gr1 MOD p =

### Calculate Code 1 (C21):

 public key g (g) : Random Number r2 (r2) : Public key p (p) : [ C21 ] = gr2 MOD p =

### Calculate Code 2 (C12):

 Cipher Text m1 (m1) : K Value k1 (k1) : Public key p (p) : [ C12 ] = (m1 * k1) MOD p =

### Calculate Code 2 (C22):

 Cipher Text m2 (m2) : K Value k2 (k2) : Public key p (p) : [ C22 ] = (m2 * k2) MOD p =

### Calculate value A (a):

 Value C11 (C11) : Value C21 (C21) : Public key p (p) : [ A ] = (C11 * C21) MOD p =

### Calculate value B (b):

 Value C12 (C12) : Value C22 (C22) : Public key p (p) : [ B ] = (C12 * C22) MOD p =

### Calculate final message (m):

 Value A (a) : Value B (b) : Value X (x) : Public key p (p) : Message =

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