From a2fe54203940f45b9f92eec13a65f668d3024589 Mon Sep 17 00:00:00 2001 From: Pranjal1804 Date: Mon, 7 Oct 2024 19:48:38 +0530 Subject: [PATCH 1/2] Pixel_Decoder script added issue no. #198 --- Cybersecurity_Tools/Pixel_Decoder/Readme.md | 0 .../Pixel_Decoder/pixel_decoder.py | 45 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 Cybersecurity_Tools/Pixel_Decoder/Readme.md create mode 100644 Cybersecurity_Tools/Pixel_Decoder/pixel_decoder.py diff --git a/Cybersecurity_Tools/Pixel_Decoder/Readme.md b/Cybersecurity_Tools/Pixel_Decoder/Readme.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/Cybersecurity_Tools/Pixel_Decoder/pixel_decoder.py b/Cybersecurity_Tools/Pixel_Decoder/pixel_decoder.py new file mode 100644 index 0000000000..805c534ce9 --- /dev/null +++ b/Cybersecurity_Tools/Pixel_Decoder/pixel_decoder.py @@ -0,0 +1,45 @@ +import random +import numpy +from PIL import Image + +def derandomize(img, seed, original_shape): + random.seed(seed) + + # Recreate the shuffled indices for both x and y + new_y = list(range(original_shape[0])) + new_x = list(range(original_shape[1])) + random.shuffle(new_y) + random.shuffle(new_x) + + # Create an empty array to store the reconstructed image + reconstructed = numpy.empty_like(img) + + # Reverse the shuffling by mapping randomized positions back to the original positions + for i, y in enumerate(new_y): + for j, x in enumerate(new_x): + reconstructed[y][x] = img[i][j] + + return numpy.array(reconstructed) + +if __name__ == "__main__": + # Open the scrambled (encrypted) image + scrambled_img = Image.open("encrypted.png") + scrambled_array = numpy.array(scrambled_img) + + original_shape = scrambled_array.shape + + # Define a range of potential seed values (assuming timestamp or a fixed range) + start_seed = int(input("Enter the starting seed to brute-force: ")) + end_seed = int(input("Enter the ending seed to brute-force: ")) + + for seed in range(start_seed, end_seed): + reconstructed_img = derandomize(scrambled_array, seed, original_shape) + + # Save the reconstructed image + image = Image.fromarray(reconstructed_img) + image.save(f"decrypted_{seed}.png") + + # Optionally, display the reconstructed image to see if it's correct + image.show() + print(f"Tried seed: {seed}") + From 5b33f161e47d8edd694f91c5d2c655b61a796ec7 Mon Sep 17 00:00:00 2001 From: Pranjal1804 Date: Mon, 7 Oct 2024 19:50:15 +0530 Subject: [PATCH 2/2] Removed Readme --- Cybersecurity_Tools/Pixel_Decoder/Readme.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 Cybersecurity_Tools/Pixel_Decoder/Readme.md diff --git a/Cybersecurity_Tools/Pixel_Decoder/Readme.md b/Cybersecurity_Tools/Pixel_Decoder/Readme.md deleted file mode 100644 index e69de29bb2..0000000000