Question
Asked 21st Feb, 2018

Can anyone provide me the Matlab code for image encryption -decryption using Scan Pattern?

I am working on project in which I need to further encrypt carrier image with G Scan pattern algorithm and I do not know how to proceed?

All Answers (1)

Certainly! Here's an example MATLAB code for image encryption-decryption using the Scan Pattern algorithm:
```matlab
% Image Encryption-Decryption using Scan Pattern
% Encrypt function
function encryptedImage = encryptImage(originalImage, key)
[rows, cols] = size(originalImage);
encryptedImage = zeros(rows, cols);
scanPattern = generateScanPattern(rows, cols, key);
for i = 1:rows
for j = 1:cols
encryptedImage(scanPattern(i, j)) = originalImage(i, j);
end
end
end
% Decrypt function
function decryptedImage = decryptImage(encryptedImage, key)
[rows, cols] = size(encryptedImage);
decryptedImage = zeros(rows, cols);
scanPattern = generateScanPattern(rows, cols, key);
for i = 1:rows
for j = 1:cols
decryptedImage(i, j) = encryptedImage(scanPattern(i, j));
end
end
end
% Generate Scan Pattern function
function scanPattern = generateScanPattern(rows, cols, key)
rng(key); % Set the random number generator seed
scanPattern = reshape(1:(rows*cols), rows, cols);
scanPattern = scanPattern(randperm(rows), :);
end
% Usage example
originalImage = imread('input_image.png'); % Replace with the path to your input image
key = 123; % Replace with your desired encryption key
encryptedImage = encryptImage(originalImage, key);
decryptedImage = decryptImage(encryptedImage, key);
imwrite(uint8(encryptedImage), 'encrypted_image.png'); % Save the encrypted image
imwrite(uint8(decryptedImage), 'decrypted_image.png'); % Save the decrypted image
```
This code defines three functions: `encryptImage`, `decryptImage`, and `generateScanPattern`. The `encryptImage` function takes an original image and a key as input, generates a scan pattern based on the key, and encrypts the image using the scan pattern. Similarly, the `decryptImage` function takes an encrypted image and the same key, generates the scan pattern, and decrypts the image. The `generateScanPattern` function creates a random scan pattern based on the provided key. You can replace `'input_image.png'` with the path to your own input image and adjust the key as needed. The encrypted and decrypted images are saved as `encrypted_image.png` and `decrypted_image.png`, respectively.
1 Recommendation

Similar questions and discussions

Related Publications

Code
In this mini project, image encryption and decryption using Matlab are implemented. The technique used for encryption is the blurring technique, where a Wiener filter is used to decrypt the blurred image. The mini-project involves introductory pieces of Matlab codes that help better understand image (pixel) value assignment. B) The second part dea...
Got a technical question?
Get high-quality answers from experts.