37 lines
839 B
Python
37 lines
839 B
Python
#!/usr/bin/env python3
|
||
|
||
from substitution import Substitution
|
||
|
||
|
||
def get_signature(filename):
|
||
with open(filename, 'rb') as fobj:
|
||
raw_bytes = fobj.read()
|
||
print(raw_bytes)
|
||
|
||
|
||
def detect_cipher(filename):
|
||
sub = Substitution()
|
||
with open(filename, 'r') as fobj:
|
||
try:
|
||
for line in fobj.readlines():
|
||
sub.detectCipher(line)
|
||
except UnicodeDecodeError:
|
||
print(f"Cannot read the file {filename}")
|
||
|
||
|
||
get_signature("test.txt")
|
||
|
||
|
||
# Try with an RSA file encrypted
|
||
detect_cipher("tests/ciphertext.rsa")
|
||
|
||
"""
|
||
Encrypting with RSA
|
||
$ openssl genrsa -out private.key 2048
|
||
$ openssl rsa -in private.key -out public.pem -pubout
|
||
$ openssl rsautl -encrypt -inkey public.pem -pubin -in plaintext.txt > ciphertext
|
||
"""
|
||
|
||
# Try with a ASCII file
|
||
detect_cipher("test.txt")
|