# Encryption/decryption algorithms

## Substitution

### Encryption

ChaoticEncryption.substitution_encryptionMethod
substitution_encryption(image, keys; path_for_result="./encrypted.png")

Performs substitution encryption on a given image with the given keys.

Algorithm

Iterates simulataneously over each pixel and key, and XORs the pixel value (all R, G, and B) with the given key. Hence, the order of the keys matter.

Arguments

• image::Array{RGB{N0f8},2}: A loaded image.
• keys::Array{Int64, 1}: Keys for encryption.
• save_img::Bool=false: Save the resultant image.
• path_for_result::String: The path for storing the encrypted image.
• debug::Bool: Print debug output.

Returns

• image::Array{RGB{N0f8}, 2}: Encrypted image.

Example

julia> using Images, TestImages

julia> img = testimage("mandrill");

julia> height, width = size(img)
(512, 512)

julia> keys = logistic_key(0.01, 3.97, height * width);

julia> keys |> size
(262144,)

julia> enc = substitution_encryption(img, keys);

julia> enc |> size
(512, 512)

julia> enc != img
true
ChaoticEncryption.substitution_encryption!Method
substitution_encryption!(image, keys; path_for_result="./encrypted.png")

Performs substitution encryption on a given image with the given keys.

Algorithm

Iterates simulataneously over each pixel and key, and XORs the pixel value (all R, G, and B) with the given key. Hence, the order of the keys matter.

Arguments

• image::Array{RGB{N0f8},2}: A loaded image.
• keys::Array{Int64, 1}: Keys for encryption.
• save_img::Bool=false: Save the resultant image.
• path_for_result::String: The path for storing the encrypted image.
• debug::Bool: Print debug output.

Returns

• image::Array{RGB{N0f8}, 2}: Encrypted image.

Example

julia> using Images, TestImages

julia> img = testimage("mandrill");

julia> height, width = size(img)
(512, 512)

julia> keys = logistic_key(0.01, 3.97, height * width);

julia> keys |> size
(262144,)

julia> orig = copy(img);

julia> substitution_encryption!(img, keys);

julia> img != orig  # inplace
true

### Decryption

ChaoticEncryption.substitution_decryptionMethod
substitution_decryption(image, keys; path_for_result="./decrypted.png")

Performs substitution decryption on a given image with the given keys.

Algorithm

Iterates simulataneously over each pixel and key, and XORs the pixel value (all R, G, and B) with the given key. Hence, the keys provided must be the same as the ones provided during encryption.

Arguments

• image::Union{String,Array{RGB{N0f8},2}}: The path to the image or the loaded image to be decrypted.
• keys::Array{Int64, 1}: Keys for decryption.
• save_img::Bool=false: Save the resultant image.
• path_for_result::String: The path for storing the encrypted image.
• debug::Bool: Print debug output.

Returns

• image::Array{RGB{N0f8}, 2}: Decrypted image.

Example

julia> using Images, TestImages

julia> img = testimage("mandrill");

julia> height, width = size(img)
(512, 512)

julia> keys = logistic_key(0.01, 3.97, height * width);

julia> keys |> size
(262144,)

julia> dec = substitution_decryption(img, keys);

julia> dec |> size
(512, 512)

julia> dec != img
true
ChaoticEncryption.substitution_decryption!Method
substitution_decryption!(image, keys; path_for_result="./decrypted.png")

Performs substitution decryption on a given image with the given keys.

Algorithm

Iterates simulataneously over each pixel and key, and XORs the pixel value (all R, G, and B) with the given key. Hence, the keys provided must be the same as the ones provided during encryption.

Arguments

• image::Union{String,Array{RGB{N0f8},2}}: The path to the image or the loaded image to be decrypted.
• keys::Array{Int64, 1}: Keys for decryption.
• save_img::Bool=false: Save the resultant image.
• path_for_result::String: The path for storing the encrypted image.
• debug::Bool: Print debug output.

Returns

• image::Array{RGB{N0f8}, 2}: Decrypted image.

Example

julia> using Images, TestImages

julia> img = testimage("mandrill");

julia> height, width = size(img)
(512, 512)

julia> keys = logistic_key(0.01, 3.97, height * width);

julia> keys |> size
(262144,)

julia> orig = copy(img);

julia> substitution_decryption!(img, keys);

julia> img != orig  # inplace
true