Skip to content

MahdiBaghbani/mersad-py

Repository files navigation


Mersad Cryptography Library

Mersad Cryptography Library

A side project of a (bad) Telecommunication student who loves ciphers.

Open Source License: AGPL v3 Language counter Top language
CodeFactor CodeClimate rating CodeClimate technical debt CodeClimate issues
pipeline status CodeClimate
PyPI version PyPI downloads Supported Python versions

Despite the fancy name "Cryptography Library"! this Project isn't anything close to real industry (ehem ... I mean military) level cryptography library.

Mersad? what does it mean?

In Persian (and Arabic) language, "Mersad" means "Hidden", which makes it a perfect choice for my cryptography library.

Why is Gamora (yes, I'm a Marvel fan)?

In summer 2019 I had decided to practice Python and DevOps tasks like: continuous integration and automated releasing software to packaging sources like PYPI, I don't know how I ended up here writing this for you! (even like if there is any "you" out there looking at this little side project of mine.)

So if you want to send unbreakable messages to your friends with ancient algorithms without using pen and paper, Mersad can help you. (but seriously, 😂 unbreakable? c'mon!)

Oh and I ❤️ codes and ciphers!

Quick start

I'm sure you have worked with Python before and you are familiar with how to download and install packages using pip, so here is how to install this totally (not at all 💩) secure package:

# 1. if you are an uncivilised savage living in a hell of dependency conflicts who doesn't 
# even heard of virtual environments and always install packages in sudo mode, here you go:
sudo -H pip3 install mersad

# 2. another option is a non-sudo thing like:
pip3 install --user mersad

# 2. if you are a man of culture, activate your virtual environment and type this:
pip3 install mersad

# 3. pipenv is also a good thing to manage virtual environments and packages to use (I prefer this :smiley:):
pipenv install mersad

Wait a second, What's Cryptography?

Honestly? I don't know either ... 😬. seems a group of smart guys are inventing ways (or what they call them "algorithms") to hide messages from others, and those "others" somehow are finding ways to break their algorithms and read their messages.

Apparently people are calling the work of first group (designing encryption algorithms) "Cryptography" and the work of second group (breaking those stupid ciphers) "Cryptanalysis".

How does this package work?

Good question, it doesn't.

But if you are so smart and managed to make it work for you, here is some explanation about the mess that is going on:

Mersad is divided into two main sub-packages, classical and modern, I'm currently developing classical algorithms but in future I will start working on modern ones.

I'm also planning to add cryptanalysis module, this module will contains programs to break ciphers.

Each cipher has a class and a translator function, you can use any of them or both of them together.

the translator function has no memory and requires every argument in each call but class have memory and can store key, alphabet sequence and etc.

Example

It is a very simple example of using Shift cipher (aka Caesar cipher) :

from mersad.classical.shift_cipher import ShiftCipher, shift_cipher_translator

MESSAGE = "Hail Caesar!"
ALPHABET = "abcdefghijklmnopqrstuvwxyz"
KEY = 4

# example 1: using translator function:

CIPHER = shift_cipher_translator(MESSAGE, key=KEY, letter_sequence=ALPHABET)
print(CIPHER)
# Out: Hemp Ceiwev!

# with translator function you need to pass all arguments
# in each call again and again.

# example 2: using cipher class.
# now the  second way of using shift cipher is using the class instead of function.

# create object without any keyword arguments so agent will use
# default values for all the settings. defaults are predefined in class.
agent = ShiftCipher()

# override defaults.
agent.config(key=3453, letter_sequence=ALPHABET)

# also you can do it at the time yu creat object:
# agent = ShiftCipher(key=3453, letter_sequence=ALPHABET)

# config usage is to override any existing properties with 
# new values at any time after creating the object.

# encrypt a string:
print(agent.encrypt("Hail Julius Caesar."))
# Out:  'Hvdg Jpgdpn Cvznvm.'

# with this object approach you don't need to pass every thing in each call to
# encrypt or decrypt.

# another one:
print(agent.encrypt("This method is not secure :0 but it is funny."))
# Out: Tcdn hzocjy dn ijo nzxpmz :0 wpo do dn apiit.

# for decryption simply call decrypt method on agent:
print(agent.decrypt("Tcdn hzocjy dn ijo nzxpmz :0 wpo do dn apiit."))
# Out: This method is not secure :0 but it is funny.

for more examples look at: snippets.

Can I use this package in terminal?

Yes! 🤘

Each cipher module have a corresponding cli program with name convention of: mcl+ModuleName. For example to run Shift cipher module in terminal just type mclShift. To learn how to work with cli programs type --help after program name (e.g. mclShift --help).

Contribution

If you want to contribute to this project, please read CONTRIBUTING.

Code of Conduct

Visit the Code of Conduct.

Roadmap

Visit the Roadmap to keep track of which features we are currently working on and which futures will come at future.

License

Licensed under the AGPLv3.

Attribution