Ruby code for an SWHE Library Image Encryption
This code requires Ruby installed on your system. There are several options for downloading and installing Ruby.
This project uses mostly Ruby standard libraries, so once you have Ruby installed (version 2.4.0 and greater), you have everything required to run the code.
This project uses RMagick for handling image data read and write. Please check their repository for instructions on how to properly install RMagick on your system.
Once Ruby is installed on your machine, from the command line and in the root directory of the project, run the tests to check the code with the following command:
$ rake
You should get a result similiar to the following:
Run options: --seed 9109
# Running:
...........
Finished in 5.316182s, 2.0692 runs/s, 9.0290 assertions/s.
11 runs, 48 assertions, 0 failures, 0 errors, 0 skipsYou can also run code from the Ruby Interactive Shell (IRB). From the project's root directory, execute the following command on the terminal:
$ irb
You will see the IRB's prompt. Next, command snippets for specific cases that can be executed on IRB.
Require the file the will boot the entire project on IRB:
> require './x'
Create the 'x' object with the required secret and public variables by passing a configuration for depth (first argument) and security parameter (second argument):
> x = X::SWHE.new(8,128)
Encryt the number 231:
> c1 = x.encrypt(231)
Encryt the number 209:
> c2 = x.encrypt(209)
Add c1 e c2:
> c1_add_c2 = c1 + c2
Multiply c1 e c2:
> c1_mul_c2 = c1 * c2
Decrypt c1_add_c2:
> x.decrypt(c1_add_c2)
As a result you should get:
=> (440/1)
Decrypt c1_mul_c2:
> x.decrypt(c1_mul_c2)
As a result you should get:
=> (48279/1)
Although you can create your own script of encrypted image manipulation, we prepared few examples to illustrate the basic functions of our library.
All the command below consider you are on the project root folder, using a terminal.
$ ruby examples/increase_brightness.rb
$ ruby examples/decrease_brightness.rb
$ ruby examples/merge_images.rb
$ ruby examples/mask_image.rb
$ ruby examples/contrast_stretching.rb
$ ruby examples/logical_not.rb