cryptanalysis/src/raw_file.py
2026-03-01 21:07:14 +01:00

37 lines
839 B
Python
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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")