Skip to content

Commit

Permalink
encryption and decryption functionality implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
BALAVIGNESHDOSTRIX committed Jan 6, 2022
1 parent 71ac783 commit 922df53
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 38 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ Lib
Scripts
randtrix_db.sqlite
.idea
venv
venv
test.py
11 changes: 11 additions & 0 deletions randtrix_vault/assembler.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
"""
################################################################
# THE RANDTRIX VAULT #
# RANDOM MECHANISM WITH AES-256 ENCRYPTION FOR PASSWORD PROTECT #
# #
# DEVELOPER NAME: BALAVIGNESH M #
# LICENSE: MIT #
# VERSION: 0.1.0 #
#################################################################
"""

from .db import RandtrixDBManager
from .mechanic import *

Expand Down
13 changes: 13 additions & 0 deletions randtrix_vault/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""
################################################################
# THE RANDTRIX VAULT #
# RANDOM MECHANISM WITH AES-256 ENCRYPTION FOR PASSWORD PROTECT #
# #
# DEVELOPER NAME: BALAVIGNESH M #
# LICENSE: MIT #
# VERSION: 0.1.0 #
#################################################################
"""

ENCODE_RANGE = 16
KEY_SIZE = 32
73 changes: 48 additions & 25 deletions randtrix_vault/cryptix.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,49 @@
"""
################################################################
# THE RANDTRIX VAULT #
# RANDOM MECHANISM WITH AES-256 ENCRYPTION FOR PASSWORD PROTECT #
# #
# DEVELOPER NAME: BALAVIGNESH M #
# LICENSE: MIT #
# VERSION: 0.1.0 #
#################################################################
"""

import base64, pyaes
from typing import *
from .exceptions import *
from .config import *

class AES16256Codec:
def __init__(self, data:str, key:str) -> None:
def __init__(self, data: str, key: str, encode: bool=True) -> None:
if (str(data).endswith('.') and encode) or (str(data).startswith('.') and encode):
raise AESEncryptionException("Please do not enter the '.' endswith or '.' startswith passwords")
if '_rand_encode_sep_' in data and not encode:
data = ''.join(str(data).split('_rand_encode_sep_'))
self.data = []
self.key = key[:32]
self.key = key[:KEY_SIZE]
self.fernet = pyaes.AES(self.key.encode('utf-8'))


temp_data = [ord(c) for c in data]
if not encode:
self.data = [temp_data[i:i + ENCODE_RANGE] for i in range(0, len(temp_data), ENCODE_RANGE)]

if encode:
if len(temp_data) < ENCODE_RANGE:
self.data.append(AES16256Codec.safe_imputer(temp_data))
else:
for k in [temp_data[i:i + ENCODE_RANGE] for i in range(0, len(temp_data), ENCODE_RANGE)]:
if len(k) == ENCODE_RANGE:
self.data.append(k)
else:
self.data.append(AES16256Codec.safe_imputer(k))

if len(temp_data) < 16:
self.data.append(AES16256Codec.safe_imputer(temp_data))
else:
initial_size = 16
final_size = len(temp_data)
k = []
self.data.append(temp_data[:16])
i = 1
while i < 17 and initial_size <= final_size:
k.append(temp_data[initial_size: initial_size + 1][0])
initial_size += 1
i += 1
if i == 16 and len(k) == 16:
self.data.append(k)
k = []
i = 1
else:
self.data.append(AES16256Codec.safe_imputer(k))
break

@staticmethod
def safe_imputer(list_d:List=[]) -> List:
def safe_imputer(list_d: List) -> List:
initial_size = len(list_d)
while initial_size < 16:
while initial_size < ENCODE_RANGE:
list_d.append(ord('.'))
initial_size += 1
return list_d
Expand All @@ -44,8 +56,19 @@ def encrypt(self) -> str:
for enc_code in enc_code_l:
encrypted_string += chr(enc_code)
if index != size_of_enc_string:
encrypted_string += '_encode_sep_'
encrypted_string += '_rand_encode_sep_'
return encrypted_string

def decrypt(self) -> str:
return self.fernet.decrypt(self.data)
decrypted_string = ""
dec_lst = [self.fernet.decrypt(data_seq) for data_seq in self.data]
for index, dec_code_l in enumerate(dec_lst):
for a_index, dec_code in enumerate(dec_code_l):
decrypted_string += chr(dec_code)
decrypted_string = decrypted_string[::-1]
while True:
if decrypted_string.startswith('.'):
decrypted_string = decrypted_string[1:]
else:
break
return decrypted_string[::-1]
11 changes: 11 additions & 0 deletions randtrix_vault/db.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
"""
################################################################
# THE RANDTRIX VAULT #
# RANDOM MECHANISM WITH AES-256 ENCRYPTION FOR PASSWORD PROTECT #
# #
# DEVELOPER NAME: BALAVIGNESH M #
# LICENSE: MIT #
# VERSION: 0.1.0 #
#################################################################
"""

from .orm import Manager, Model, Database

class RandtrixManager(Manager):
Expand Down
11 changes: 11 additions & 0 deletions randtrix_vault/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@

"""
################################################################
# THE RANDTRIX VAULT #
# RANDOM MECHANISM WITH AES-256 ENCRYPTION FOR PASSWORD PROTECT #
# #
# DEVELOPER NAME: BALAVIGNESH M #
# LICENSE: MIT #
# VERSION: 0.1.0 #
#################################################################
"""

class AESEncryptionException(Exception):pass
class RandtrixException(Exception):pass

11 changes: 11 additions & 0 deletions randtrix_vault/mechanic.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
"""
################################################################
# THE RANDTRIX VAULT #
# RANDOM MECHANISM WITH AES-256 ENCRYPTION FOR PASSWORD PROTECT #
# #
# DEVELOPER NAME: BALAVIGNESH M #
# LICENSE: MIT #
# VERSION: 0.1.0 #
#################################################################
"""

from typing import *
from hashlib import sha256
import random
Expand Down
11 changes: 11 additions & 0 deletions randtrix_vault/tools.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
"""
################################################################
# THE RANDTRIX VAULT #
# RANDOM MECHANISM WITH AES-256 ENCRYPTION FOR PASSWORD PROTECT #
# #
# DEVELOPER NAME: BALAVIGNESH M #
# LICENSE: MIT #
# VERSION: 0.1.0 #
#################################################################
"""

from typing import *

class RandtrixTools:
Expand Down
25 changes: 13 additions & 12 deletions test.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
# from randtrix_mechanic import *
# from randtrix_db import *
# from mechanic import *
# from db import *

# hash_l = RandtrixPasswordMechanic(456790,"test123","test234","test567").pass_2_hash()
# hash_l = RandtrixPasswordMechanic(456790,"test123","test234","test567").randomize()
# hash_l = RandtrixPasswordMechanic(456790,"test123","test234","test567").hash_2_salt()
# hash_l_k = RandtrixPasswordMechanic(456709, "test123", "test234", "test567").encrypt_pass("Hello World")
# hash_l = AES16256Codec(456790,"test123","test234","test567").pass_2_hash()
# hash_l = AES16256Codec(456790,"test123","test234","test567").randomize()
# hash_l = AES16256Codec(456790,"test123","test234","test567").hash_2_salt()
# hash_l_k = AES16256Codec(456709, "test123", "test234", "test567").encrypt_pass("Hello World")
# print(hash_l_k)
#
# hash_l = RandtrixPasswordMechanic(638590, "test123", "test234", "test567").decrypt_pass(hash_l_k)
# hash_l = AES16256Codec(638590, "test123", "test234", "test567").decrypt_pass(hash_l_k)
# print(hash_l)
#
# hash_l = RandtrixPasswordMechanic(189463, "test123", "test234", "test567").decrypt_pass(hash_l_k)
# hash_l = AES16256Codec(189463, "test123", "test234", "test567").decrypt_pass(hash_l_k)
# print(hash_l)


# s = RandrixDBManager.create_rtrix("bala", "123", "test")
# print(s)

from randtrix_vault.cryptix import *

s = AES16256Codec('mercidus?wqertyum', 'bbdefa2950f49882f295b1285d4fa9dec45fc4144bfb07ee6acc68762d12c2e3').encrypt()
print(s)
# print(''.join([chr(i) for i in s]))
message = 'mercidus?wqertkumddddddddddddddddddddddd'
key = 'bbdefa2950f49882f295b1285d4fa9dec45fc4144bfb07ee6acc68762d12c2e'
s = AES16256Codec(message, key).encrypt()
decryped_message = AES16256Codec(s, key , encode=False).decrypt()
assert message == decryped_message

0 comments on commit 922df53

Please sign in to comment.