Classical cryptography, enhanced by chemistry !
This package allows you to encrypt and decrypt messages by the mean of Vigenere Cipher and Periodic Table of Elements.
Here is a quick example :
from periodicencryption import vc, en # importing the vigenerecipher and encryption modules
message = "Hello, World!"
row = vc.generate_row() #table row (i.e. which characters are allowed to be encrypted)
encrypted, puk, prk = en.encrypt_keys_auto(row, message)
print(encrypted)
print(f"public key : {puk}")
print(f"private key : {prk}")
decrypted = en.decrypt(row, encrypted, puk, prk)
print(decrypted)AeVvco6q&q0kWwXj!FNyskRjlq
public key : 74.921595HafniumArsenic178.486
private key : HafniumAsHfArsenic
Hello, World!
- Installation
- In a nutshell how does it work
- Package Documentation
Enter the following command :
pip install periodicencryptionThen import the package :
import periodicencryptionStrings are made up of characters, those characters have a unique code (generally called ASCII code). As it turns out, elements of the periodic table have number linked to them. So this package basicaly retrieve the chemical elements that share the same numbers as the characters. Then that list of element is encoded using a Vigenere Cipher
Also don't worry, characters code that exceed 118 (the highest number amongst the periodic table) are handled using a custom element
The main package is structured like that :
periodicencryption
- encryption
- element
- vigenerecipher
And there are aliases :
| Sub-package | Alias |
|---|---|
| encryption | en |
| element | el |
| vigenerecipher | vc |
Which mean you could either use from periodicencryption import element or from periodicencryption import el
This sub-package contain everything related to the Vigenere cipher.
It can be accessed via those two methods :
from periodicencryption import en
from periodicencryption import encryptiongenerate_keys(string: str) -> tuple[str, str]Generates public and private keys from a string.
string(str): The string to generate the keys from.
ValueError: If the element list is empty.
tuple[str, str]: The public and private keys.
encrypt_keys_manual(row: str, message: str, public_key: str, private_key: str) -> strEncrypts a message using the Vigenère cipher and the periodic table elements, with the specified keys.
row(str): The row of characters to use (i.e. which characters are allowed to be encrypted).message(str): The message to encrypt.public_key(str): The public key.private_key(str): The private key.
ValueError: If the message is empty.
str: The encrypted message.
encrypt_keys_auto(row: str, message: str) -> tuple[str, str, str]Encrypts a message using the Vigenère cipher and the periodic table elements, with automatically generated keys.
row(str): The row of characters to use (i.e. which characters are allowed to be encrypted).message(str): The message to encrypt.
ValueError: If the message is empty.
tuple[str, str, str]: The encrypted message, the public key, and the private key.
decrypt(row: str, encoded: str, public_key: str, private_key: str) -> strDecrypts a message using the Vigenère cipher and the periodic table elements.
row(str): The row of characters to use (i.e. which characters are allowed to be encrypted).encoded(str): The encoded message.public_key(str): The public key.private_key(str): The private key.
ValueError: If the message is empty.
str: The decrypted message.
This sub-package contain everything related to chemical elements.
It can be accessed via those two methods :
from periodicencryption import el
from periodicencryption import elementclass CounterElement(pt.core.Element)A custom element class to handle elements with codes out of the periodic table range.
It stores the mass (900 + <loop counter>) to track how many times the code looped out of the periodic table, and stores the final element used to fit the ASCII code in the table.
cnt(int): The loop counter (i.e., how many times we looped out of range over the periodic table).el(pt.core.Element): The element that we are able to fit into after looping.
split_symbol(symbol: str) -> tuple[str, int]: Splits a symbol into the element symbol and the counter.
get_el_by_number(number: int) -> pt.core.ElementReturns the element by its number.
number(int): The number of the element.
pt.core.Element: The element.
get_el_by_name(name: str) -> pt.core.ElementReturns the element by its name.
name(str): The name of the element.
pt.core.Element: The element.
get_el_by_symbol(symbol: str) -> pt.core.ElementReturns the element by its symbol.
symbol(str): The symbol of the element.
pt.core.Element: The element.
get_last_el() -> pt.core.ElementReturns the last element of the periodic table.
pt.core.Element: The last element.
turn_chr_into_el(character: chr) -> pt.core.ElementConverts a character into an element.
character(chr): The character to convert.
pt.core.Element: The resulting element.
turn_str_into_el(string: str) -> list[pt.core.Element]Converts a string into a list of elements.
string(str): The string to convert.
list[pt.core.Element]: The resulting list of elements.
turn_el_into_chr(element: pt.core.Element) -> chrConverts an element into a character.
element(pt.core.Element): The element to convert.
chr: The resulting character.
turn_el_into_str(element_list: list[pt.core.Element]) -> strConverts a list of elements into a string.
element_list(list[pt.core.Element]): The list of elements to convert.
str: The resulting string.
This sub-package contain everything related to the Vigenere cipher.
It can be accessed via those two methods :
from periodicencryption import vc
from periodicencryption import vigenereciphergenerate_row() -> strGenerates a row for the Vigenère table.
str: A string containing letters, digits, special characters, whitespace, and letters with diacritics.
generate_table(row: str, public_key: str) -> pd.DataFrameGenerates a Vigenère table.
row(str): The row to be used in the table.public_key(str): The public key to be used in the table.
ValueError: If every character of the public key is not in the row.
pd.DataFrame: The Vigenère table.
vigenere_encode(row: str, message: str, public_key: str, private_key: str) -> strEncodes a message using the Vigenère cipher.
row(str): The row to be used in the table.message(str): The message to be encoded.public_key(str): The public key to be used in the table.private_key(str): The private key to be used in the table.
str: The encoded message.
vigenere_decode(row: str, encoded_message: str, public_key: str, private_key: str) -> strDecodes a message using the Vigenère cipher.
row(str): The row to be used in the table.encoded_message(str): The message to be decoded.public_key(str): The public key to be used in the table.private_key(str): The private key to be used in the table.
str: The decoded message.