-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4103e9f
commit dab4d55
Showing
17 changed files
with
94 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,150 +1,9 @@ | ||
# Encroval | ||
|
||
## Index | ||
* [Description](#description) | ||
* [Get Started](#get-started) | ||
* [Install requirements](#install-requirements) | ||
* [Enter the input](#enter-the-input) | ||
* [Run](#run) | ||
* [Configuration](#configuration) | ||
* [Examples](#examples) | ||
* [Encryption](#encryption-example) | ||
* [Text Decryption](#text-decryption-example) | ||
* [Image Decryption](#image-decryption-example) | ||
|
||
## Description | ||
|
||
Encroval is an encryption tool that allows you to encrypt a text into other text or image using a password. | ||
|
||
It can encrypt a text of any length and the password can be up to 2<sup>128</sup> bits long and accepts any UTF-8 character (1,112,064 different characters). | ||
|
||
|
||
|
||
|
||
## Get Started | ||
|
||
#### Install Requirements | ||
|
||
```bash | ||
pip3 install -r requirements.txt | ||
``` | ||
|
||
|
||
#### Enter the input | ||
|
||
##### Select the text to encrypt | ||
Place the text you want to encrypt (a `.txt` file) in the `input` folder. | ||
|
||
##### Select the text/image to decrypt | ||
Place the text you want to encrypt (a `.txt` file) or the image (a `.png` file) in the `input` folder. | ||
|
||
|
||
#### Run | ||
|
||
```bash | ||
python3 main.py | ||
``` | ||
|
||
|
||
|
||
|
||
## Configuration | ||
|
||
You can change the `POS_LEN` in the `config.py` file, which changes the input text's maximum length. | ||
|
||
Default is `POS_LEN = 4`, so the maximum length the text can have by default is **32,446** | ||
|
||
The more the `POS_LEN` is, the longer the text can be, but the longer it will take to encrypt and decrypt it. | ||
|
||
| POS_LEN | Max text lenght | | ||
|-|-| | ||
| 1 | 2 | | ||
| 2 | 107 | | ||
| 3 | 2,026 | | ||
| 4 | 32,446 | | ||
| 5 | 524,169 | | ||
| 6 | 8,386,749 | | ||
| 7 | 134,188,028 | | ||
| 8 | 2,147,329,544 | | ||
| ... | ... | | ||
|
||
|
||
|
||
|
||
## Examples | ||
|
||
### Encryption example | ||
|
||
<img width=400 src=readme-assets/example_encryption.png> | ||
|
||
##### `config.py` | ||
|
||
```python | ||
POS_LEN = 2 | ||
``` | ||
|
||
##### Input text (`input/test.txt`) | ||
```txt | ||
This is a test 123!!! | ||
It can have every UTF-8 character! ✔️ ❤️ ☆ | ||
``` | ||
|
||
##### Password | ||
```txt | ||
test#@–{}password123¿? | ||
``` | ||
|
||
##### Encrypted text (`output/encrypted_text.txt`) | ||
```txt | ||
3e8b00b4bcbb4ff246fdb3bc9afd63cf080e1cbefdc4b4bb2b5f1400f3fd4e6cb10d40825d0ab41e080e4e751a1ebbb8e7c4448fc14434d5c84d7fb3cc68e2c66033d5cfeece84bd256888b5e3dbb5bdc7fd47845be373e44bc8defbabb92e544f5eb0b4c43403084344d663 | ||
``` | ||
|
||
##### Encrypted image (`output/encrypted_image.png`) | ||
<img width=70 src=readme-assets/encrypted_image.png> | ||
|
||
|
||
|
||
### Text Decryption example | ||
|
||
<img width=400 src=readme-assets/example_text_decryption.png> | ||
|
||
##### Input text (`input/encrypted_text.txt`) | ||
```txt | ||
This is a test 123!!! | ||
It can have every UTF-8 character! ✔️ ❤️ ☆ | ||
``` | ||
|
||
##### Password | ||
```txt | ||
test#@–{}password123¿? | ||
``` | ||
|
||
##### Decrypted text (`output/decrypted_text.txt`) | ||
```txt | ||
This is a test 123!!! | ||
The text can have every UTF-8 character! ✔️ ❤️ ☆ | ||
``` | ||
|
||
|
||
|
||
### Image Decryption example | ||
|
||
<img width=400 src=readme-assets/example_image_decryption.png> | ||
|
||
##### Input image (`input/encrypted_image.png`) | ||
<img width=70 src=readme-assets/encrypted_image.png> | ||
|
||
##### Password | ||
```txt | ||
test#@–{}password123¿? | ||
``` | ||
|
||
##### Decrypted image (`output/decrypted_image.txt`) | ||
```txt | ||
This is a test 123!!! | ||
It can encrypt a text of any length with a password and the only way to decrypt it is by knowing it. | ||
|
||
The text can have every UTF-8 character! ✔️ ❤️ ☆ | ||
``` | ||
The password can be up to 2<sup>128</sup> bits long and accepts any UTF-8 character (1,112,064 different characters). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
POS_LEN = 2 | ||
POS_LEN = 4 | ||
""" | ||
The length that the positions in the encryption will have (in hex) | ||
1 = 0x0 - 0xF Max text length: 2 | ||
2 = 0x00 - 0xFF Max text length: 107 | ||
3 = 0x000 - 0xFFF Max text length: 2,026 | ||
4 = 0x0000 - 0xFFFF Max text length: 32,446 | ||
5 = 0x00000 - 0xFFFFF Max text length: 524,169 | ||
6 = 0x000000 - 0xFFFFFF Max text length: 8,386,749 | ||
7 = 0x0000000 - 0xFFFFFFF Max text length: 134,188,028 | ||
8 = 0x00000000 - 0xFFFFFFFF Max text length: 2,147,329,544 | ||
1 = 0x0 - 0xF Max text length: 1 | ||
2 = 0x00 - 0xFF Max text length: 105 | ||
3 = 0x000 - 0xFFF Max text length: 2,024 | ||
4 = 0x0000 - 0xFFFF Max text length: 32,443 | ||
5 = 0x00000 - 0xFFFFF Max text length: 524,166 | ||
6 = 0x000000 - 0xFFFFFF Max text length: 8,386,745 | ||
7 = 0x0000000 - 0xFFFFFFF Max text length: 134,188,024 | ||
8 = 0x00000000 - 0xFFFFFFFF Max text length: 2,147,329,539 | ||
... | ||
This affects the maximum length of the message that can be encrypted | ||
Max text length isn't equal to the number of bits that a position can have, because those bits are also used to store other things | ||
""" |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
This is a test 123!!! | ||
|
||
The text can have every UTF-8 character! ✔️ ❤️ ☆ | ||
It can have every UTF-8 character! ✔️ ❤️ ☆ |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import hashlib | ||
import sys; sys.path.append("..") | ||
from constants.constants import * | ||
import random | ||
|
||
def enc(txt, encryption_code:str) -> str: | ||
encTxt = "" | ||
for x in txt: | ||
encTxt += encryption_code[int(x,16)] # The symbol in the equivalent position | ||
return encTxt | ||
|
||
|
||
# Decrypt an encrypted text with an encryption code | ||
def dec(txt, encryption:str) -> str: | ||
decTxt = "" | ||
for x in txt: | ||
decTxt += HEX_SYMB[encryption.index(x)] # The symbol in the equivalent position | ||
return decTxt | ||
|
||
|
||
# Encode the password to sha512 and get a hash (length = 128) | ||
def get_pwd_hash(pwd:str) -> str: | ||
return hashlib.sha512(pwd.encode()).hexdigest() | ||
|
||
|
||
def get_encryption_code(hash:str) -> str: | ||
encryption_code = "" | ||
while len(encryption_code) < 16: # While the encryption string doesn't have 16 symbols | ||
if (hash[0] not in encryption_code): | ||
encryption_code += hash[0] | ||
hash = h2h(hash) | ||
return encryption_code | ||
|
||
|
||
def get_textE_len_idxs(seed:int, encryption_len:int, textE_len_digits:int) -> tuple: # Save txt_len_enc in the first POS_LEN indexes | ||
random.seed(seed) | ||
return random.sample(range(encryption_len), textE_len_digits) | ||
|
||
def get_textE_idxs(seed:int, encryption_len:int, textE_len:int, textE_len_idxs:tuple) -> tuple: | ||
random.seed(seed) | ||
textE_idxs = [] | ||
for _ in range(textE_len): | ||
while True: | ||
idx = random.randint(0, encryption_len-1) | ||
if idx not in textE_idxs and idx not in textE_len_idxs: | ||
textE_idxs.append(idx) | ||
break | ||
return textE_idxs | ||
|
||
|
||
# Create a new hash from a hash | ||
def h2h(hash:str, iters:int=1) -> str: | ||
for _ in range(iters): | ||
hash = hashlib.sha512(hash.encode()).hexdigest() | ||
return hash | ||
|
||
# Convert from text to hexadecimal | ||
def t2h(txt:str) -> str: | ||
return txt.encode('utf-8').hex() | ||
|
||
# Convert hexadecimal to utf-8 | ||
def h2t(hex:str)-> str: | ||
return bytes.fromhex(hex).decode('utf-8') |