Skip to content

Commit 6f0d255

Browse files
Add files via upload
1 parent dab4d55 commit 6f0d255

File tree

10 files changed

+76
-29
lines changed

10 files changed

+76
-29
lines changed

README.md

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,53 @@
11
# Encroval
22

3+
## Index
4+
* [Description](#description)
5+
* [Get Started](#get-started)
6+
* [Install requirements](#install-requirements)
7+
* [Enter the input](#enter-the-input)
8+
* [Run](#run)
9+
* [Configuration](#configuration)
10+
311
## Description
412

513
Encroval is an encryption tool that allows you to encrypt a text into other text or image using a password.
614

7-
It can encrypt a text of any length with a password and the only way to decrypt it is by knowing it.
15+
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).
16+
17+
18+
19+
20+
## Get Started
21+
22+
#### Install Requirements
23+
24+
```bash
25+
pip3 install -r requirements.txt
26+
```
27+
28+
29+
#### Enter the input
30+
31+
##### Select the text to encrypt
32+
Place the text you want to encrypt (a `.txt` file) in the `input` folder.
33+
34+
##### Select the text/image to decrypt
35+
Place the text you want to encrypt (a `.txt` file) or the image (a `.png` file) in the `input` folder.
36+
37+
38+
#### Run
39+
40+
```bash
41+
python3 main.py
42+
```
43+
44+
45+
46+
47+
## Configuration
48+
49+
You can change the `POS_LEN` in the `config.py` file, which changes the input text's maximum length.
50+
51+
Default is `POS_LEN = 4`, so the maximum length the text can have by default is **32,446**
852

9-
The password can be up to 2<sup>128</sup> bits long and accepts any UTF-8 character (1,112,064 different characters).
53+
The more the `POS_LEN` is, the longer the text can be, but the longer it will take to encrypt and decrypt it.

classes/Decryptor.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ def __init__(self, ciphertext:str, pwd:str):
1212

1313

1414
def decrypt(self) -> str:
15-
encrypted_len = len(self.ciphertext) # Same as ENC_LEN
16-
if not all(c in HEX_SYMB for c in self.ciphertext) or len(self.ciphertext) != encrypted_len:
15+
cipher_len = len(self.ciphertext) # Same as CIPHER_LEN
16+
17+
if not all(c in HEX_SYMB for c in self.ciphertext) or len(self.ciphertext) != cipher_len:
1718
raise Exception("Encrypted text is invalid")
1819

1920
# Seed the random generator with the hash
@@ -24,13 +25,13 @@ def decrypt(self) -> str:
2425
encryption_code = get_encryption_code(self.hash)
2526

2627
# Decrypt the text length
27-
textE_len_digits = len(format(encrypted_len,"x")) # If the position length is 5, the length of the encrypted text will fit in 5 digits
28-
textE_len_idxs = get_textE_len_idxs(seed, encrypted_len, textE_len_digits)
28+
textE_len_digits = len(format(cipher_len,"x")) # If the position length is 5, the length of the encrypted text will fit in 5 digits
29+
textE_len_idxs = get_textE_len_idxs(seed, cipher_len, textE_len_digits)
2930
textE_lenE = "".join([self.ciphertext[idx] for idx in textE_len_idxs])
3031
textE_len = int(dec(textE_lenE, encryption_code), 16)
3132

3233
# Decrypt the text
33-
textE_idxs = get_textE_idxs(seed, encrypted_len, textE_len, textE_len_idxs)
34+
textE_idxs = get_textE_idxs(seed, cipher_len, textE_len, textE_len_idxs)
3435
textE = "".join([self.ciphertext[idx] for idx in textE_idxs])
3536
text = h2t(dec(textE, encryption_code))
3637

classes/Encryptor.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def __init__(self, text:str, pwd:str):
1111
self.hash = get_pwd_hash(self.pwd)
1212

1313

14-
def encrypt(self) -> str:
14+
def encrypt(self) -> str: # Returns a ciphertext
1515
if len(self.text)>TXT_MAX_LEN or len(self.text)==0:
1616
raise Exception("Text length is invalid")
1717

@@ -22,19 +22,21 @@ def encrypt(self) -> str:
2222
# Get the encryption code
2323
encryption_code = get_encryption_code(self.hash)
2424

25-
# Fill the encrypted text with random characters
26-
ciphertext = [random.choice(HEX_SYMB) for _ in range(ENC_LEN)]
25+
# Fill the ciphertext with random characters
26+
ciphertext = [random.choice(HEX_SYMB) for _ in range(CIPHER_LEN)]
2727

28-
# INFO: Encrypt the text and text length
28+
# INFO: Encrypt the text
2929
textE = enc(t2h(self.text), encryption_code)
30-
textE_len_digits = len(format(ENC_LEN,"x")) # If the position length is 5, the length of the encrypted text will fit in 5 digits
30+
31+
# INFO: Encrypt the text length
3132
textE_len = len(textE)
32-
textE_len_fixed_len = format(textE_len,"x").rjust(textE_len_digits,"0")
33+
textE_len_max_digits = len(format(CIPHER_LEN,"x")) # If the position length is 5, the length of the encrypted text will fit in 5 digits
34+
textE_len_fixed_len = format(textE_len,"x").rjust(textE_len_max_digits,"0")
3335
textE_lenE = enc(textE_len_fixed_len, encryption_code) # Encrypted text length (fixed length)
3436

3537
# Get the indexes where the INFO will be stored
36-
textE_len_idxs = get_textE_len_idxs(seed, ENC_LEN, textE_len_digits)
37-
textE_idxs = get_textE_idxs(seed, ENC_LEN, len(textE), textE_len_idxs)
38+
textE_len_idxs = get_textE_len_idxs(seed, CIPHER_LEN, textE_len_max_digits)
39+
textE_idxs = get_textE_idxs(seed, CIPHER_LEN, len(textE), textE_len_idxs)
3840

3941
# Save the text and text length in toret
4042
for i,idx in enumerate(textE_len_idxs):

classes/Menu.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
class Menu():
1515
def __init__(self):
1616
self.create_folders()
17+
print(f'\n{Text("Max length of the text",Fore.CYAN)}: {Text(f"{TXT_MAX_LEN:,}",Fore.GREEN)} (you can change it in {Text("config.py",Fore.LIGHTYELLOW_EX)}')
1718
option = Options(["EXIT", "Encrypt", "Decrypt text", "Decrypt image"]).get_choice()
1819

1920
if option == 0:
-22 Bytes
Binary file not shown.
-12 Bytes
Binary file not shown.
181 Bytes
Binary file not shown.

config.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
POS_LEN = 4
22
"""
33
The length that the positions in the encryption will have (in hex)
4-
1 = 0x0 - 0xF Max text length: 1
5-
2 = 0x00 - 0xFF Max text length: 105
6-
3 = 0x000 - 0xFFF Max text length: 2,024
7-
4 = 0x0000 - 0xFFFF Max text length: 32,443
8-
5 = 0x00000 - 0xFFFFF Max text length: 524,166
9-
6 = 0x000000 - 0xFFFFFF Max text length: 8,386,745
10-
7 = 0x0000000 - 0xFFFFFFF Max text length: 134,188,024
11-
8 = 0x00000000 - 0xFFFFFFFF Max text length: 2,147,329,539
12-
...
134
14-
This affects the maximum length of the message that can be encrypted
15-
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
5+
1 = 0x0 - 0xF Max text length: 2
6+
2 = 0x00 - 0xFF Max text length: 107
7+
3 = 0x000 - 0xFFF Max text length: 2,026
8+
4 = 0x0000 - 0xFFFF Max text length: 32,446
9+
5 = 0x00000 - 0xFFFFF Max text length: 524,169
10+
6 = 0x000000 - 0xFFFFFF Max text length: 8,386,749
11+
7 = 0x0000000 - 0xFFFFFFF Max text length: 134,188,028
12+
8 = 0x00000000 - 0xFFFFFFFF Max text length: 2,147,329,544
13+
...
1614
"""
41 Bytes
Binary file not shown.

constants/constants.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
HEX_SYMB = "0123456789abcdef"
1010

11-
IMG_SIZE = int(np.sqrt((16**POS_LEN)//6)) # Size that the image will have (the image is a square)
12-
ENC_LEN = (IMG_SIZE**2)*6 # Length that the encrypted text will have
13-
TXT_MAX_LEN = ENC_LEN//2-1-POS_LEN # Max length text (not encrypted) can have
11+
IMG_SIZE = int(np.sqrt((16**POS_LEN)//6)) # Size that the image will have (the image is a square)
12+
CIPHER_LEN = (IMG_SIZE**2)*6 # Length that the ciphertext will have
13+
TXT_E_MAX_LEN = CIPHER_LEN - len(format(CIPHER_LEN,"x")) # Max length text (encrypted) can have
14+
TXT_MAX_LEN = TXT_E_MAX_LEN//2 # Max length the input text can have (Because the encrypted text is twice the length of the input text)

0 commit comments

Comments
 (0)