This project implements a text encryption and decryption system using a matrix-based encryption technique. This project serves as an educational and practical exploration of matrix-based encryption techniques, demonstrating the fundamental concepts of encryption and decryption in a user-friendly manner.
Clone the repository and copy the library your local project folder then include MatrixEncryptor.h
. After that you need to implement Eigen to your project. From the given link, only the folder Eigen is required. After putting it to your project folder, from your Project's Property Pages, C/C++ -> General -> Additional Include Directories
add Eigen folder's path.
Before getting started with Text Encryption With Linear Algebra, ensure that you have the following dependencies installed on your Linux system:
- g++ compiler
- Eigen library
To use the Text Encryption With Linear Algebra, follow these steps:
- Clone this repository
git clone git@github.com:farukalpay/TextEncryptionWithLinearAlgebra.git
- Clone the repository of Eigen Library:
git clone https://gitlab.com/libeigen/eigen
- Go inside the directory of Eigen Library and copy the directory Eigen into this repository
cp -r <path-to-Eigen-directory> <path-to-this-repo>
- Use the Makefile to compile with make
make
- Now you should see the executable in the directory of Text Encryption With Linear Algebra
-
Initialization:
-
Given an input string
of length , where , and each represents a character in the string.
Initialize an empty vectorto store the ASCII integer representations of characters extracted from the input string . -
Consider the input string
.
Initialize.
-
-
Token Extraction:
-
Extract tokens (words) from the input string
. Let be the tokens extracted from , where is the number of tokens. -
Extract tokens:
and .
-
-
Character Processing for Token
: -
For each token
, consisting of characters , where is the length of the token: - Convert each character
to its ASCII integer representation . - Add each
to end of the vector.
- Convert each character
-
Convert 'H' to ASCII integer
, 'e' to , 'l' to , 'l' to , 'o' to .
Add these integers to: .
-
-
Adding Space:
-
After processing each character in a token
, add a space character ' ' to the vector. -
Add a space ' ' to
.
-
-
End of Token:
-
Repeat steps 3-4 for all tokens
. -
Process characters for
: - Convert 'W' to ASCII integer
, 'o' to , 'r' to , 'l' to , 'd' to . - Add these integers to
: . - Add a space ' ' to
.
- Convert 'W' to ASCII integer
-
-
Return Result:
-
The function returns the
vector containing ASCII integer representations of characters in , with spaces after each token. -
Return
.
-
-
Initialization:
-
Let
be a square matrix of size , represented as where . -
Each element
denotes a value in the key matrix. -
Consider the ASCII representation of the string
, where the ASCII values are . Let be a square matrix of size
-
-
Random Number Generation Setup:
- Initialize a pseudo-random number generator with a random seed.
-
Uniform Distribution Setup:
- Define a uniform distribution to produce random numbers uniformly distributed between -10.0 and 10.0.
-
Random Key Generation:
- For each element
of : - Sample a random value
from the uniform distribution. - Assign
as the value of in the key matrix. - Mathematically,
for .
- Sample a random value
- For each element
-
Return the Key:
-
Once all elements of the matrix
have been assigned random values, return the resulting key matrix . -
Generated key matrix for
:
-
-
Message Padding:
-
Given a message
represented as a vector of integers , where is the size of the message and is the size of the key matrix. -
Determine the remainder
when dividing the size of the message by the size of the key matrix: . -
Pad the message with spaces to make its size a multiple of the size of the key matrix:
. -
The message
corresponds to the vector . Since the size of the key matrix is 3, the message needs to be padded with spaces to make its size a multiple of . Thus, the padded message becomes .
-
-
Message Vectorization:
-
Split the padded message
into vectors of size : , where . -
Each
is a column vector of size containing consecutive elements from . -
Generated
column matrices for :
-
-
Encryption:
- For each message vector
: - Perform matrix-vector multiplication with the key matrix
: . - After performing the matrix-vector multiplication, the resulting elements in
rounded to the nearest integer. - Each element of
represents an encrypted value corresponding to the corresponding message vector element.
- Perform matrix-vector multiplication with the key matrix
- For each message vector
For
For
-
Result:
-
Concatenate all elements of the encrypted vectors to form the encrypted message
: . -
The resulting encrypted message corresponding to the input
encrypted using this key matrix is:
-
-
Initialization:
-
Let
be the encrypted message represented as a vector of integers, where is the size of the encrypted message. -
Consider the encrypted message
-
Key matrix
used for encryption:
-
-
Segmentation:
-
Divide the encrypted message into segments, each consisting of
elements, where is the size of the key matrix . -
Segments of the encrypted message, denoted as
, are obtained by splitting into segments, where ranges from to . -
Each segment
consists of consecutive elements starting from index . -
Each segment
is represented as a column matrix of size :
-
- Segmented column matrices for
:
-
Matrix Multiplication:
- For each segment
: - Perform matrix-vector multiplication with the inverse key matrix
: - After performing the matrix-vector multiplication, the resulting elements in
rounded to the nearest integer. - Each element of
represents an decrypted ASCII value corresponding to the corresponding message vector element.
- Perform matrix-vector multiplication with the inverse key matrix
- For each segment
For
For
-
Result:
-
Concatenate all elements of the decrypted message vectors to form the decrypted message
: . The resulting decrypted message is a sequence of ASCII characters obtained by converting each integer in to its corresponding ASCII character. -
The resulting decrypted message corresponding to the encrypted message
decrypted using the key matrix is:
-
The decrypted message