Important: The math in this document is not one-to-one with the code. The code is just an implementation of the algorithm.
Details for the algorithm is here. Here is math version if you think you can handle that.
Note: Every indexing in this page is done zero-indexed. This includes string indices, matrix indices and vector indices.
- Choose
$N$ to be a power of$2$ . - Create
$N$ sequences ($f_0, f_1, \cdots, f_{N - 1}$ ) s.t.$\forall i, j: f_{i,j} \in \textbf C$ . There is no need for a closed-form formula (and we recommend that there aren't any). - Define
$F_0, F_1, \cdots, F_{N - 1}$ with the Discrete Fourier Transform of$f_0, f_1, \cdots, f_{N - 1}$ .
- Create a key matrix
$\textbf A$ with the rule:
- Calculate
$\textbf A^{-1}$ using Gauss-Jordan Method.
- Let
$m$ be the data to encrypt. - Define a sequence
$s$ with lenght$N$ s.t.$\forall i: s_i \in \textbf C$ with the rule:
Note:
$m_i$ operator is the zero-indexed$i$ . element of$m$ .
-
Define
$S$ to be$\mathrm{DFT}\{s\}$ . -
Define
$\textbf b$ with the elements of$S$ .
- Solve the equation
$\textbf A \textbf x = \textbf b$ for$\textbf x$ .$\textbf x$ is the encrypted data to store.
- Calculate
$\textbf b$ using the equation$\textbf A \textbf x = \textbf b$ . - Define a sequence
$T$ s.t.$T_i = \textbf b_i$ . - Define
$t$ to be$\mathrm{IDFT}\{T\}$ . - Let
$m$ be the data that is obtained by decryption s.t.$\mathrm{len}(m) = t_0$ and$\forall i \in \{0..\mathrm{len}(m) - 1\}: m_i = t_{i + 1}$