Provides a collection of cryptography functions and a command line tool with interactive prompts to demonstrate key encryption flows and algorithms.
See engines
in package.json:
"engines": {
"node": ">= 16.0.0",
"npm": ">= 8.0.0"
},
File structure:
├── images/
├── patches/
├── source/
│ ├── algorithms/
│ │ ├── baby-step-giant-step/
│ │ └── ...
│ ├── common/
│ │ ├── constants/
│ │ ├── utilities/
│ │ └── ...
│ ├── illustration/
│ │ ├── ElGamal.ts
│ │ └── ...
│ ├── types/
│ ├── command.ts
│ └── entry-point.ts
└── README.md
Use the following commands to help you to run or develop this project locally:
git clone https://github.com/SiegeSailor/formulas.git
Go to the folder you just created with git clone
. It should be typically named formulas
:
cd formulas
Install all the packages you need. Remember that you have to run this under node >= 16.0.0
and npm >= 8.0.0
. You can simply use nvm use 16
if you have multiple versions on your local machine:
npm install
Then you are able to run the command-line tool with:
npm run start
This command-line tool allows you to either demonstrate encryption flow or execute algorithms with the inputs from you. Here is an example of RSA:
Executing Euclidean algorithm with your own inputs:
Formulas uses Jest for unit tests purpose. You can generate the coverage report:
npm run test -- --coverage
Or see the detail for each test case:
npm run test -- --verbose
Jest has an issue working with the type bigint
in multiple test files, which is widely used for algorithms in this project. In order to solve it, the property has been set in jest.config.js
. Unfortunately, this setup will drag down some performance during testing:
module.exports = {
...
maxWorkers: 1,
};
Available mathematic algorithm implantation:
- Baby Step Giant Step
- Blum Blum Shub
- Chinese Remainder
- Euclidean
- Extended Euclidean
- Fast Modular Exponentiation
- Miller Rabin Primarily Test
- Multiplicative Inverse
- Naor Reingo
- Pollard P-1 Factorization
- Pollard Rho
- Primitive Root Search
Demonstrable command-line based encryption flow with three parties involved: