SecretPy
===========
[![Go to PyPi](https://badge.fury.io/py/secretpy.svg)](https://pypi.org/project/secretpy)
[![Go to PyPi](https://img.shields.io/pypi/pyversions/secretpy.svg)](https://pypi.org/project/secretpy)
[![Read the Docs](https://img.shields.io/readthedocs/secretpy.svg)](https://secretpy.readthedocs.io/en/latest)
***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:
```bash
pip install secretpy
```
Alternatively, you can install the package using the repo's cloning and the make:
```bash
git clone https://github.com/tigertv/secretpy
cd secretpy
make install
```
Usage
-----
```python
#!/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.):
```python
#!/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:
```python
#!/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](https://github.com/tigertv) (Max Vetrov)
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
共39个文件
py:32个
txt:3个
pkg-info:2个
资源分类:Python库 所属语言:Python 资源全名:secretpy-0.4.0.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源详情
资源评论
资源推荐
收起资源包目录
secretpy-0.4.0.tar.gz (39个子文件)
secretpy-0.4.0
PKG-INFO 8KB
secretpy
alphabet.py 450B
ciphers
trifid.py 2KB
atbash.py 481B
bifid.py 2KB
rot5.py 357B
affine.py 836B
monoalphabet.py 612B
vigenere.py 609B
beaufort.py 578B
adfgvx.py 2KB
caesar.py 705B
keyword.py 1KB
__init__.py 728B
zigzag.py 1KB
rot13.py 589B
rot18.py 384B
rot47.py 425B
polybius.py 1KB
adfgx.py 2KB
autokey.py 711B
cryptmachine.py 655B
__init__.py 272B
abstractmachine.py 261B
cmdecorators
uppercase.py 349B
savecase.py 625B
lowercase.py 281B
__init__.py 262B
decorator.py 502B
savespaces.py 598B
nospaces.py 350B
compositemachine.py 562B
secretpy.egg-info
PKG-INFO 8KB
SOURCES.txt 1KB
top_level.txt 9B
dependency_links.txt 1B
setup.cfg 38B
setup.py 1KB
README.md 5KB
共 39 条
- 1
挣扎的蓝藻
- 粉丝: 13w+
- 资源: 15万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0