Skip to content

Commit

Permalink
MIS-6 - update PEP8 standard #6
Browse files Browse the repository at this point in the history
PEP8 - Making column line to < 80 characters
  • Loading branch information
princenyeche authored Aug 23, 2022
2 parents 5f667cc + c1c3d8f commit a2fb801
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 44 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Mistyfy change log

**Release 2.0.6** - 2022-08-23
### Update
* Reduced code column to less than 80 characters according to PEP8


**Release 2.0.5** - 2022-06-04
### Patch
* Patches
Expand Down
3 changes: 2 additions & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ Below shows the list of supported version for the mistyfy library

| Version | Supported |
|---------|--------------------|
| 2.0.6 | :white_check_mark: |
| 2.0.5 | :white_check_mark: |
| 2.0.4 | :white_check_mark: |
| 2.0.4 | :x: |
| 2.0.3 | :x: |
| 2.0.2 | :x: |
| 2.0.1 | :x: |
Expand Down
2 changes: 1 addition & 1 deletion mistyfy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
from mistyfy.misty import encode, decode, ciphers, signs, verify_signs, generator

__all__ = ["encode", "decode", "ciphers", "signs", "verify_signs", "generator"]
__version__ = "v2.0.5"
__version__ = "v2.0.6"
__author__ = "Prince Nyeche"
__copyright__ = "MIT License"
116 changes: 75 additions & 41 deletions mistyfy/misty.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# -*- coding: utf-8 -*-
"""
This is a simple algorithm that provides you the option
to encrypt a series of strings in your own way, pass that string encoded up to 2 layers,
send the data over the internet and decrypt the original data.
to encrypt a series of strings in your own way, pass that string encoded
up to 2 layers, send the data over the internet and decrypt the original data.
The wonderful part of this module is that you can have a vast amount of
text which is of little object size.
"""
Expand Down Expand Up @@ -86,8 +86,8 @@ def generator(
if not os.path.exists('../data/config.json'):
gen = generator(ciphers, -400, 13931283)
json.dump(gen, open('../data/config.json', mode='w+', encoding='utf-8'),
indent=4, sort=True)
json.dump(gen, open('../data/config.json', mode='w+',
encoding='utf-8'), indent=4, sort=True)
if __name__ == "__main__":
Expand All @@ -97,15 +97,17 @@ def generator(
.. versionadded:: 2.0.0
fmt argument - Exports the cipher format in string if true, dictionary if false.
fmt argument - Exports the cipher format in string if true,
dictionary if false.
:param cipher: A pseudo series of text
:param start: An integer to begin our randomization from
:param stop: An integer to our stop randomization
:param fmt: Exports the cipher format in string if true, dictionary if false.
:param fmt: Exports the cipher format in string if true,
dictionary if false.
:return: A dictionary having unique numbers for your cipher
"""
Expand Down Expand Up @@ -139,21 +141,26 @@ def encode(
gn = generator(ciphers, -400, 138192812)
secret = b'somesecretkey' # create any secret key, easier if you use os.urandom(n)
# create any secret key, easier if you use os.urandom(n)
secret = b'somesecretkey'
# secret = os.urandom(16)
a = "This is a secret message or password"
b = encode(a, secret, gn)
# output is a string base64, encoded with a signature, and mistyfied with the cipher.
# output is a string base64, encoded with a signature,
# and mistyfied with the cipher.
# eyJtaXN0eWZ5IjogWzQ5Nxxxxxx...
The generator function helps to create a cipher. Ciphers is a dictionary containing ascii or utf-8 characters,
you can change this at will using the generator function to create your own unique cipher. The first argument is
the cipher block, second & third argument is the start and stop counter.
The generator function helps to create a cipher. Ciphers is a dictionary
containing ascii or utf-8 characters, you can change this at will using
the generator function to create your own unique cipher.
The first argument is the cipher block, second & third argument is the
start and stop counter.
.. versionadded:: 2.0.0
expire argument - The number of seconds an encoded data can last for. This timestamp is in UTC. By default
it is set to 1 hour from the initial encoded time.
expire argument - The number of seconds an encoded data can last for.
This timestamp is in UTC. By default it is set to 1 hour from the
initial encoded time.
:param data: a string value
Expand All @@ -167,14 +174,17 @@ def encode(
*options*
auth_size: integer - If used in encode, the same size must be used for decode
taken from arguments from blake2b
auth_size: integer - If used in encode, the same size must be
used for decode, taken from arguments from blake2b
key: Union[bytes, bytearray, memoryview, array, mmap, mmap] = ...,
key: Union[bytes, bytearray, memoryview,
array, mmap, mmap] = ...,
salt: Union[bytes, bytearray, memoryview, array, mmap, mmap] = ...,
salt: Union[bytes, bytearray, memoryview,
array, mmap, mmap] = ...,
person: Union[bytes, bytearray, memoryview, array, mmap, mmap] = ...,
person: Union[bytes, bytearray, memoryview,
array, mmap, mmap] = ...,
fanout: int = ...,
Expand All @@ -193,17 +203,20 @@ def encode(
usedforsecurity: bool = ...
:return: string with signature and the data in bs64(when decrypted returns list of numbers)
:return: string with signature and the data in
bs64(when decrypted returns list of numbers)
"""
_secret = str(secret)
secret = _secret
try:
if not isinstance(data, str):
raise TypeError("Expected `data` argument to strings got {} instead".format(type(data)))
raise TypeError("Expected `data` argument to strings "
"got {} instead".format(type(data)))
else:
gain = []
if cipher is None:
raise TypeError("Expecting a series of cipher for each character.")
raise TypeError("Expecting a series of cipher for "
"each character.")
# do a loop through the strings and interchange it with numbers
if isinstance(cipher, str):
_cipher = jo.loads(cipher)
Expand All @@ -218,21 +231,26 @@ def encode(
f = jo.dumps(transform) # change the list into a string
s = f.encode("utf-8") # encode the string into bytes
_encode = b.b64encode(s) # bs64 encode the bytes
decode_ = _encode.decode("utf-8") # make the bytes a string instead
# make the bytes a string instead
decode_ = _encode.decode("utf-8")
# put a timestamp to the request, default is 3600 seconds
make_time = datetime.datetime.utcnow()
future = make_time + datetime.timedelta(seconds=expire)
str_fmt = future.strftime("%Y-%m-%d %H:%M:%S.%f") # format the time into strings
# format the time into strings
str_fmt = future.strftime("%Y-%m-%d %H:%M:%S.%f")
# this will contain a signed signature of the data
sig = signs(decode_, secret, **kwargs)
# return a string of the encoded data
encode_export = jo.dumps({"data": decode_, "expire": str_fmt, "signature": sig})
results = b.b64encode(encode_export.encode("utf-8")) # bs64 the data again
encode_export = jo.dumps({"data": decode_, "expire": str_fmt,
"signature": sig})
# bs64 the data again
results = b.b64encode(encode_export.encode("utf-8"))
_do_results = results.decode("utf-8") # ensure its in strings
return _do_results
except Exception as error:
if isinstance(error, ValueError):
return "You seem to be using some wrong data format. Check your entered data."
return "You seem to be using some wrong data format. " \
"Check your entered data."
return "Failure encrypting data."


Expand All @@ -242,7 +260,8 @@ def decode(
cipher: t.Optional[str] = None,
**kwargs: t.Any) -> str:
"""
Decrypts a data and sends output as string. Usually the original form of an encoded data.
Decrypts a data and sends output as string. Usually the original form of
an encoded data.
.. code-block:: python
Expand Down Expand Up @@ -270,14 +289,17 @@ def decode(
*options*
auth_size: integer - If used in encode, the same size must be used for decode
taken from arguments from blake2b
auth_size: integer - If used in encode, the same
size must be used for decode taken from arguments from blake2b
key: Union[bytes, bytearray, memoryview, array, mmap, mmap] = ...,
key: Union[bytes, bytearray, memoryview,
array, mmap, mmap] = ...,
salt: Union[bytes, bytearray, memoryview, array, mmap, mmap] = ...,
salt: Union[bytes, bytearray, memoryview,
array, mmap, mmap] = ...,
person: Union[bytes, bytearray, memoryview, array, mmap, mmap] = ...,
person: Union[bytes, bytearray, memoryview,
array, mmap, mmap] = ...,
fanout: int = ...,
Expand All @@ -301,28 +323,37 @@ def decode(
secret = _secret
try:
if not isinstance(data, str):
raise TypeError("Expected your `data` argument to be strings got {} instead".format(type(data)))
raise TypeError("Expected your `data` argument to be "
"strings got {} instead".format(type(data)))
else:
if cipher is None:
raise TypeError('Expecting a series of cipher for each character.')
# validate that the signature is indeed correct with the data that was received.
raise TypeError('Expecting a series of cipher for '
'each character.')
# validate that the signature is indeed correct with
# the data that was received.
if isinstance(cipher, str):
_cipher = jo.loads(cipher)
cipher = _cipher
_decode_result = data.encode("utf-8") # encode into bytes
results = b.b64decode(_decode_result).decode("utf-8") # decode into strings
# decode into strings
results = b.b64decode(_decode_result).decode("utf-8")
get_dict = jo.loads(results)
validate_signature = verify_signs(get_dict['data'], get_dict['signature'], secret=secret, **kwargs)
validate_signature = verify_signs(get_dict['data'],
get_dict['signature'],
secret=secret, **kwargs)
if validate_signature is True:
# check if the time has expired
if get_dict["expire"]:
current_time = datetime.datetime.utcnow()
if datetime.datetime.strptime(get_dict["expire"], "%Y-%m-%d %H:%M:%S.%f") > current_time:
if datetime.datetime. \
strptime(get_dict["expire"],
"%Y-%m-%d %H:%M:%S.%f") > current_time:
pass
else:
return "Unable to validate data as token has expired."

port = b.b64decode(get_dict['data']) # decode bs64 encrypted data
# decode bs64 encrypted data
port = b.b64decode(get_dict['data'])
key = port.decode("utf-8") # decode from bytes
parse = []
j = jo.loads(key).get('mistyfy')
Expand All @@ -332,7 +363,9 @@ def decode(
if x == v:
parse.append(k)
# return a string output
return "".join(parse)
return "".join(parse) \
if len(parse) != 0 else "Empty value " \
"detected. Decryption failed."
else:
return "Unable to decrypt data, incorrect value detected."
except Exception as error:
Expand Down Expand Up @@ -411,6 +444,7 @@ def verify_signs(
_data = str(data)
data = _data
if "secret" not in kwargs:
raise NameError("You're missing the `secret` keyword argument. E.g secret='somesecrete'")
raise NameError("You're missing the `secret` keyword argument. "
"E.g secret='somesecrete'")
confirm = signs(data, **kwargs)
return hmac.compare_digest(confirm, signature)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="mistyfy",
version="2.0.5",
version="2.0.6",
author="Prince Nyeche",
author_email="support@elfapp.website",
description="A package that helps encrypt any given string and returns an encrypted string with a signed hash."
Expand Down

0 comments on commit a2fb801

Please sign in to comment.