# Path: lantern/modules/shift.py
# def make_shift_function(alphabet: Iterable, operator: ShiftOperator = subtract) -> ShiftFunction:
#     def shift_case_sensitive(shift, symbol):
# def crack(ciphertext: Iterable, *fitness_functions: Iterable,
#           min_key: int = 0, max_key: int = 26,
#           shift_function: ShiftFunction = shift_decrypt_case_english) -> List[Decryption]:
# def decrypt(key: int, ciphertext: Iterable, shift_function: ShiftFunction = shift_decrypt_case_english) -> Iterable:
# def encrypt(key: int, plaintext: Iterable, shift_function: ShiftFunction = shift_encrypt_case_english) -> Iterable:


from lantern.modules import shift
from typing import Iterable
#!/usr/bin/env python3




def shift_encrypt(key: int, byte: int) -> int:
    return (byte + key) % 255


def shift_decrypt(key: int, byte: int):
    return (byte - key) % 255


def header_matcher(value: Iterable) -> int:
    return 0 if value[:8] == [137, 80, 78, 71, 13, 10, 26, 10] else -1


with open("example.png", "rb") as image:
    image_bytes = bytearray(image.read())

KEY = 144
encrypted_bytes = shift.encrypt(KEY, image_bytes, shift_encrypt)

print(f"Encrypted header: {encrypted_bytes[:8]}")

# Decrypt the image by finding a matching PNG header

# Path: lantern/modules/shift.py
# def make_shift_function(alphabet: Iterable, operator: ShiftOperator = subtract) -> ShiftFunction:
#     def shift_case_sensitive(shift, symbol):
# def crack(ciphertext: Iterable, *fitness_functions: Iterable,
#           min_key: int = 0, max_key: int = 26,
#           shift_function: ShiftFunction = shift_decrypt_case_english) -> List[Decryption]:
# def decrypt(key: int, ciphertext: Iterable, shift_function: ShiftFunction = shift_decrypt_case_english) -> Iterable:
# def encrypt(key: int, plaintext: Iterable, shift_function: ShiftFunction = shift_encrypt_case_english) -> Iterable:


# Path: examples/shift/image_shift.py
from lantern.modules import shift
from typing import Iterable

#!/usr/bin/env python3




def shift_encrypt(key: int, byte: int) -> int:
    return (byte + key) % 255


def shift_decrypt(key: int, byte: int):
    return (byte - key) % 255


def header_matcher(value: Iterable) -> int:
    return 0 if value[:8] == [137, 80, 78, 71, 13, 10, 26, 10] else -1


with open("example.png", "rb") as image:
    image_bytes = bytearray(image.read())

KEY = 144
encrypted_bytes = shift.encrypt(KEY, image_bytes, shift_encrypt)

print(f"Encrypted header: {encrypted_bytes[:8]}")

# Decrypt the image by finding a matching PNG header

decryptions = shift.crack(