Skip to main content

A python package that include commonly used cryptographic algorithm and tools.

Project description

MyCrptool


A python package that include commonly used cryptographic algorithm and tools.

This package is designed as a teaching tool, written in pure python. It means that it probably won't be as efficient as other similar python libraries which use C for low-level implementation and provide the same if not more functions. However, the author try to write clean and simple code to demonstrate how a cryptography algorithm works.

GitHub repository (and newest documentation) : https://github.com/ChopperCP/MyCryptool

Install


pip install mycrptool

Problem with bitarray

This package use bitarray as an external library. When installing this library, you may fail to compile.

If that's the case, you can go to https://www.lfd.uci.edu/~gohlke/pythonlibs/ to download a pre-compiled version of bitarray, and then simply run:

pip install downloaded-precompiled-file.whl

Dependencies


Here are external libraries that is used in this package.

bitarray

Usage


This package consists of 4 parts: symmetric, asymetric, hash, and tools.

To import all modules, it is recommanded to run from mycryptool import *

symmetric


This module includes 2 symmetric algorithms: AES128 and DES.

AES128

The Default scheme is CBC. if you want to try other schemes, welcome to explore the AES class (in symmetric.aes128).

Encrypt:

data = b'Jessie Pinkman in the house'
key = 'key'
cipher = symmetric.aes128.encrypt(key, data)

Decrypt:

symmetric.aes128.decrypt(key, cipher)

DES

DES only supports 2 schemes: CBC and ECB. Supported Features: encrypt and decrypt.

Encrypt:

key = b'chopperc'
iv = b'66666666'
data = b'Yo Yo Yo, Jessie Pinkman in the house!!!'

cipher = symmetric.des.des_cbc(data, iv, key, True)  # CBC

cipher = symmetric.des.des_ecb(data, key, True)  # ECB

Decrypt:

deciphered = symmetric.des.des_cbc(cipher, iv, key, False)  # CBC
deciphered = symmetric.des.des_ecb(cipher, key, False)  # ECB

asymmetric


This module includes 2 asymmetric algorithms: RSA and Elliptic Curve.

Supported Features: encrypt, decrypt, generate signature, and validate signature.

RSA

Encrypt:

data = b'Jessie Pinkman in the house'
# Warning: it takes a while to generate key pairs ( large prime numbers).
pub, pri = asymmetric.rsa.generate_key_pair()
cipher = asymmetric.rsa.encrypt(data, pub)

Decrypt:

asymmetric.rsa.decrypt(cipher, pri)

Generate signature:

signature = asymmetric.rsa.get_signature(hash.md5.md5(data), pri)
print(signature)

Validate signature:

asymmetric.rsa.is_valid_signature(hash.md5.md5(data), signature, pub)

Elliptic Curve

As for now, this module only supports 1 curve: ecp256k1.

However, you can Implement your own curve derived from the EllipticCurve class.

Implement customize curve:

class ecp256k1(EllipticCurve):
	# ecp256k1 https://www.secg.org/sec2-v2.pdf
	def __init__(self):
		a = 0
		b = 7
		p = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F
		Gx = 0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798
		Gy = 0x483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8
		n = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141

		super(ecp256k1, self).__init__(a, b, p, (Gx, Gy), n)

Encrypt:

ec = asymmetric.elliptic_curve.ecp256k1()
pri = ec.get_private_key()
pub = ec.get_public_key(pri)
ec_cipher = ec.encrypt(data, pub)
print(ec_cipher)

Decrypt:

ec.decrypt(ec_cipher, pri)

Generate signature:

signature = ec.get_signature(hash.sha1.sha1(data), pri)

Validate signature:

ec.is_valid_signature(hash.sha1.sha1(data), signature, pub)

hash


md5

This module provide 2 hashing algorithm: MD5 and SHA-1.

    hash.md5.md5(b'basdfasdfadsf')

sha1

    hash.sha1.sha1(b'basdfasdfadsf')

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mycryptool-1.1.1.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mycryptool-1.1.1-py3-none-any.whl (16.9 kB view details)

Uploaded Python 3

File details

Details for the file mycryptool-1.1.1.tar.gz.

File metadata

  • Download URL: mycryptool-1.1.1.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.5

File hashes

Hashes for mycryptool-1.1.1.tar.gz
Algorithm Hash digest
SHA256 734c7273e973782938b57ca80359a5484f40e08d7914adbf25a8273049b10733
MD5 40c96f4cb63b65ee2440de6a4700985b
BLAKE2b-256 a95255c8a045df2de6becc824c6a37dd50814ab9584f127fffb685e84f24f57a

See more details on using hashes here.

File details

Details for the file mycryptool-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: mycryptool-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 16.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.5

File hashes

Hashes for mycryptool-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1725b42a7f703f321b7c7f5a1993382098188a696422e23076c073373d705fa9
MD5 ff02a72ccde4600abe754cedef1dc962
BLAKE2b-256 9d9830429359a053af99743773df97306f8600c8a5e70a08c0ad9e16e4c11e30

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page