Skip to content

Commit

Permalink
Add image shift example program
Browse files Browse the repository at this point in the history
  • Loading branch information
CameronLonsdale committed Jun 5, 2019
1 parent 07ed5a5 commit a8d1eb8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Binary file added examples/shift/example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions examples/shift/image_shift.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env python3

from lantern.modules import shift


shift_encrypt = lambda key, byte: (byte + key) % 255
shift_decrypt = lambda key, byte: (byte - key) % 255


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]}")

header_matcher = lambda value: 0 if value[:8] == [137, 80, 78, 71, 13, 10, 26, 10] else -1

# Decrypt the image by finding a matching PNG header
decryptions = shift.crack(encrypted_bytes, header_matcher, min_key=0, max_key=255, shift_function=shift_decrypt)

print(f"Decrypted Header: {decryptions[0].plaintext[:8]}")

0 comments on commit a8d1eb8

Please sign in to comment.