Classic ciphers package
Project description
SecretPy
Download:
https://pypi.org/project/secretpy
Documentation:
https://secretpy.readthedocs.io
Source code & Development:
https://github.com/tigertv/secretpy
Description
SecretPy is a cryptographic Python package. It uses the following classical cipher algorithms:
- ADFGX, ADFGVX
- Affine
- Atbash
- Autokey
- Beaufort
- Bifid
- Caesar
- Keyword
- Monoalphabet
- Polybius
- Rot13, Rot5, Rot18, Rot47
- Trifid
- Vigenere
- Zigzag
Installation
To install this library, you can use pip:
pip install secretpy
Alternatively, you can install the package using the repo's cloning and the make:
git clone https://github.com/tigertv/secretpy
cd secretpy
make install
Usage
#!/usr/bin/python
# -*- encoding: utf-8 -*-
from secretpy import Caesar
from secretpy import alphabet
alphabet = alphabet.GERMAN
plaintext = u"thequickbrownfoxjumpsoverthelazydog"
key = 3
cipher = Caesar()
print(plaintext)
enc = cipher.encrypt(plaintext, key, alphabet)
print(enc)
dec = cipher.decrypt(enc, key, alphabet)
print(dec)
print('=====================================')
print(plaintext)
# use default english alphabet
enc = cipher.encrypt(plaintext, key)
print(enc)
dec = cipher.decrypt(enc, key)
print(dec)
'''
Output:
thequickbrownfoxjumpsoverthelazydog
wkhtxlfneurzqirämxpsvryhuwkhodüögrj
thequickbrownfoxjumpsoverthelazydog
=====================================
thequickbrownfoxjumpsoverthelazydog
wkhtxlfneurzqiramxpsvryhuwkhodcbgrj
thequickbrownfoxjumpsoverthelazydog
'''
In the previous example plaintext contains letters only in the alphabet. To change the behaviour you can use CryptMachine and decorators(UpperCase, NoSpace, SaveCase and etc.):
#!/usr/bin/python
# -*- encoding: utf-8 -*-
from secretpy import Atbash
from secretpy import Caesar
from secretpy import CryptMachine
from secretpy.cmdecorators import *
from secretpy import alphabet
def encdec(machine, plaintext):
print(plaintext)
enc = machine.encrypt(plaintext)
print(enc)
dec = machine.decrypt(enc)
print(dec)
print("-----------------------------------")
plaintext = u"thequickbrownfoxjumpsoverthelazydog"
key = 3
cipher = Caesar()
cm = CryptMachine(cipher, key)
encdec(cm, plaintext)
cm.setAlphabet(alphabet.GERMAN)
encdec(cm, plaintext)
cm = SaveSpaces(cm)
cm.setKey(9)
plaintext = u"the quick brown fox jumps over the lazy dog"
encdec(cm, plaintext)
cm = NoSpaces(UpperCase(cm))
cm.setCipher(Atbash())
plaintext = u"Achtung Minen"
encdec(cm, plaintext)
'''
Output:
thequickbrownfoxjumpsoverthelazydog
wkhtxlfneurzqiramxpsvryhuwkhodcbgrj
thequickbrownfoxjumpsoverthelazydog
-----------------------------------
thequickbrownfoxjumpsoverthelazydog
wkhtxlfneurzqirämxpsvryhuwkhodüögrj
thequickbrownfoxjumpsoverthelazydog
-----------------------------------
the quick brown fox jumps over the lazy dog
üqn zßrlt käxbw oxc sßvyö xanä üqn ujed mxp
the quick brown fox jumps over the lazy dog
-----------------------------------
Achtung Minen
ßÖWKJQXRVQZQ
ACHTUNGMINEN
-----------------------------------
'''
Combining several ciphers to get more complex cipher, you can use CompositeMachine:
#!/usr/bin/python
# -*- encoding: utf-8 -*-
from secretpy import Rot13
from secretpy import Caesar
from secretpy import CryptMachine
from secretpy import CompositeMachine
from secretpy.cmdecorators import *
def encdec(machine, plaintext):
print("=======================================")
print(plaintext)
enc = machine.encrypt(plaintext)
print(enc)
dec = machine.decrypt(enc)
print(dec)
key = 5
plaintext = u"Dog jumps four times and cat six times"
print(plaintext)
cm1 = SaveSpaces(SaveCase(CryptMachine(Caesar(), key)))
enc = cm1.encrypt(plaintext)
print(enc)
cm2 = SaveSpaces(SaveCase(CryptMachine(Rot13())))
enc = cm2.encrypt(enc)
print(enc)
print("=======================================")
cm = CompositeMachine(cm1)
cm.addMachine(cm2)
enc = cm.encrypt(plaintext)
print(enc)
encdec(cm, plaintext)
cm.addMachine(cm1, cm2)
encdec(cm, plaintext)
'''
Output:
thequickbrownfoxjumpsoverthelazydog
wkhtxlfneurzqiramxpsvryhuwkhodcbgrj
thequickbrownfoxjumpsoverthelazydog
-----------------------------------
thequickbrownfoxjumpsoverthelazydog
wkhtxlfneurzqirämxpsvryhuwkhodüögrj
thequickbrownfoxjumpsoverthelazydog
-----------------------------------
the quick brown fox jumps over the lazy dog
üqn zßrlt käxbw oxc sßvyö xanä üqn ujed mxp
the quick brown fox jumps over the lazy dog
-----------------------------------
Achtung Minen
ßÖWKJQXRVQZQ
ACHTUNGMINEN
-----------------------------------
'''
Maintainers
- @tigertv (Max Vetrov)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file secretpy-0.4.0.tar.gz.
File metadata
- Download URL: secretpy-0.4.0.tar.gz
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/2.7.15rc1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f48d264b72724a00714468a5ea555149bde5e05411923240d19bfcdf318a9b23
|
|
| MD5 |
30f5090ebc12f08897842f7362af643a
|
|
| BLAKE2b-256 |
038932e19cd3d0eb910485277e8d8a9b5a6a9ddc6286176d3477bb11860801d3
|
File details
Details for the file secretpy-0.4.0-py2.py3-none-any.whl.
File metadata
- Download URL: secretpy-0.4.0-py2.py3-none-any.whl
- Upload date:
- Size: 30.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/2.7.15rc1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5c2157ca45c8a0e72a35ec1174f9f9d38b970b3939b8a957823ddaf42a2a36df
|
|
| MD5 |
03210fdc6d2bf6c5af2d912d3715443b
|
|
| BLAKE2b-256 |
abf57007bc2c285f9d901101e9d27db09cb5bbd896a557e54c6262d73db1979d
|