Simple cryptanalysis library
Project description
etao is a simple Python library that assists in the creation of cryptanalysis tools. It takes care of common low-level tasks such as converting letters to numeric values or splitting a buffer into a bit stream or series of fixed-size blocks, as well as higher-level things like frequency analysis.
Installation
Install with pip:
pip install etao
As of version 1.0.0 this library switched from Python 2 to Python 3; for Python 2 use version 0.6.0.
Example Application
The following is a Caesar cipher solving tool that uses etao’s frequency analysis functions and built-in ciphers.
#!/usr/bin/env python
# Caesar cipher solver
import argparse
from etao import CaesarCipher, NgramFrequencyScorer
from etao.freq import ENGLISH_DIGRAMS
def main():
parser = argparse.ArgumentParser(description="Caesar cipher solver")
parser.add_argument('ciphertext', type=str, help='text to decipher')
args = parser.parse_args()
scorer = NgramFrequencyScorer(freq=ENGLISH_DIGRAMS)
# Get every Caesar shift of the ciphertext
shifts = [CaesarCipher(n).decrypt(args.ciphertext) for n in range(26)]
# Score each shift according to English character frequency.
# Get tuples that pair the score with the text.
scored_shifts = [(scorer.score(shift), shift) for shift in shifts]
# Sort by score, descending order
scored_shifts.sort(reverse=True)
# Print the top 3 results
for result in scored_shifts[0:3]:
print('"%s" (%02d%%)' % (result[1], int(result[0] * 100)))
if __name__ == "__main__":
main()
Here’s what it looks like in action:
$ ./caesar_solver.py "O GQFSOAWBU QCASG OQFCGG HVS GYM. WH VOG VODDSBSR PSTCFS, PIH HVSFS WG BCHVWBU HC QCADOFS WH HC BCK."
"A SCREAMING COMES ACROSS THE SKY. IT HAS HAPPENED BEFORE, BUT THERE IS NOTHING TO COMPARE IT TO NOW." (75%)
"U MWLYUGCHA WIGYM UWLIMM NBY MES. CN BUM BUJJYHYX VYZILY, VON NBYLY CM HINBCHA NI WIGJULY CN NI HIQ." (36%)
"P HRGTPBXCV RDBTH PRGDHH IWT HZN. XI WPH WPEETCTS QTUDGT, QJI IWTGT XH CDIWXCV ID RDBEPGT XI ID CDL." (35%)
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
File details
Details for the file etao-1.1.0.tar.gz
.
File metadata
- Download URL: etao-1.1.0.tar.gz
- Upload date:
- Size: 25.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf0a8d1bc6c38d3236d4197d5d8efa6a3fcf47e7460f4e976f9ebaa18930d9f8 |
|
MD5 | 297c87c52589c64890b15440783664d3 |
|
BLAKE2b-256 | 18aa6cd7e6ba017dce228c7570fea70aa760001c0a43dc883bd6ec8a86b7b0c8 |