Skip to content

Commit

Permalink
decrypts! 💪
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramb Memburg committed Jul 9, 2022
1 parent 5e44b1c commit a78f40e
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 4 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,24 @@ To decrypt an image you can run the following command:

## Results

Here are some comparisons of the same image being encrypted with a different number of iterations.

| **Original** | **Encrypted (I = 1000)** | **Encrypted (I = 2000)** | **Encrypted (I = 5000)** |
|:-------------------------------:|:------------------------------------:|:------------------------------------:|:------------------------------------:|
| ![](./docs/resources/lenna.png) | ![](./docs/resources/lenna_1000.png) | ![](./docs/resources/lenna_2000.png) | ![](./docs/resources/lenna_5000.png) |

Here the execution times are shown, both the generation of the key, as well as those of the encryption and decryption processes; for an image with a dimension of 640x350 (frame taken from the movie Like Minds).

| **Original** | **Encryption Key** | **Encrypted Image** | **Decrypted Image** |
|:------------------------------------:|:------------------:|:-----------------------------------------:|:------------------------------------:|
| ![](./docs/resources/like_minds.jpg) | NA | ![](./docs/resources/like_minds_3960.png) | ![](./docs/resources/like_minds.jpg) |
| NA | 0.692811 seconds | 1.623960 seconds | 0.024757 seconds |

## Documentation in different languages 🚧

This section is still under construction and it's gonna be released soon.

## External links

1. [Lenna (Wikipedia)](https://en.wikipedia.org/wiki/Lenna)
1. [Lenna (Wikipedia)](https://en.wikipedia.org/wiki/Lenna)
2. [Like Minds (Wikipedia)](https://en.wikipedia.org/wiki/Like_Minds)
Binary file added docs/resources/like_minds.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/resources/like_minds_3960.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 5 additions & 3 deletions index.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,21 @@
jsonConfig = jsondecode(fileread("./config.json"));
args.action = jsonConfig.("action");
args.inputFile = jsonConfig.("inputFile");
imageCPU = imread(args.inputFile);

if strcmp(args.action, "protect")
% Get required attributes to perform
% the protection process.
args.iterations = jsonConfig.("iterations");

% Create an image in the traditional way.
imageCPU = imread(args.inputFile);
% Proceed and encrypt the image
Erebus.protect(imageCPU, args.iterations);
elseif strcmp(args.action, "unprotect")
% Get required attributes to perform
% the unprotection process.
args.keyPath = jsonConfig.("keyPath");
encryptionKey = readmatrix(args.keyPath);

% TODO
% Proceed and decrypt the image
Erebus.unprotect(imageCPU, encryptionKey);
end
29 changes: 29 additions & 0 deletions src/Erebus.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,25 @@ function createKey(x, y, iterations)
end
end
end

function decryptedImage = decrypt(encryptedImage, encryptionKey)
decryptedImage = encryptedImage;

for i = size(encryptionKey, 1):-1:1
switch encryptionKey(i, 1)
case 0
%fprintf("Flipping row %d\n", encryptionKey(i, 2));
flipped = flip(decryptedImage(encryptionKey(i, 2), :, :));
decryptedImage(encryptionKey(i, 2), :, :) = flipped;
case 1
%fprintf("Flipping column %d\n", encryptionKey(i, 2));
flipped = flip(decryptedImage(:, encryptionKey(i, 2), :));
decryptedImage(:, encryptionKey(i, 2), :) = flipped;
otherwise
error("Unexpeceted error while decrypting the image");
end
end
end
end

methods (Static)
Expand All @@ -79,5 +98,15 @@ function protect(I, iterations)

imwrite(encryptedImage, Erebus.OUTPUT_PATH + "E" + Erebus.FILE_PREFIX + ".png");
end

function unprotect(I, k)
disp("Decrypting image...");

tic;
decryptedImage = Erebus.decrypt(I, k);
toc;

imwrite(decryptedImage, Erebus.OUTPUT_PATH + "D" + Erebus.FILE_PREFIX + ".png");
end
end
end

0 comments on commit a78f40e

Please sign in to comment.