You are on page 1of 7

DISTRIBUTED AND PARALLELIZED

IMAGE ENCRYPTION USING DES

J COMPONENT
REVIEW – 2

PARALLEL AND DISTRIBUTED


COMPUTING
CSE4001

SUBMITTED TO:
PROF. SAIRA BANU J
SLOT L47+L48

SUBMITTED BY
PATEL YASH VIJAYKUMAR 17BCE0335
CHINTAN PAMNANI 17BCE0471
ANURAJ SRIVASTAVA 17BCE2006
Description of Platform
Java Script
Back when JavaScript was developed as Mocha at Netscape Communications Corporation by
Brendan Eich in 1995, the language was meant for adding programmability on the web -
making the web more interactive for the user. Over the years, JavaScript has gained massive
prominence and has become one of the most important languages of the day. The rise of the
web has taken JavaScript places it was never conceived to be.

Anyone who has written considerable amount of code in JavaScript will not be surprised to
know that JavaScript was written in 10 days. As lovable as it may be, JavaScript has subtle
bug friendly features and lot of other things that programmers would rather not have. But it
is one of the essential programming(scripting?) languages in today’s web driven world.
Hence, it is imperative to implement the best of software programming techniques and
technologies in JavaScript.

As JavaScript grew out of its bounds, lots and lots of features were added on the go which
weren’t thought of initially. The addition of all these unanticipated features, from functional
programming to OOP, were pretty much work around of existing language features. One of
the cool features added to JS in the recent years was the ability to parallel compute
JavaScript and this what we will describe henceforth.

Why parallel processing in JS


One might ask why parallelize JavaScript, after all you use on the browser for small
scale scripting. Sure, if you using JavaScript for an onclick handler or for a simple
animation effect, you do not need parallelization. However, there are many
heavyweight JS applications on the web that do a lot of processing in JavaScript:

For example, Client-side image processing (in Facebook and Lightroom) is written in
JS; in-browser office packages such as Google Docs are written in JS; and
components of Firefox, such as the built-in PDF viewer, pdf.js, and the language
classifier, are written in JS.

The amount JavaScript in a webpage is steadily increasing over the years and the
reason to parallelize JS is same as the reason to parallelize any other language:

Moore’s law is dying and multi-core architecture is taking over the world.

Node JS
JavaScript was conceived as a single-threaded programming language that ran in a browser.
Being single-threaded means that only one set of instructions is executed at a time in the
same process (the browser in this case or just the current tab in modern browsers).
This made things easier for implementation and for developers using the language.
JavaScript was initially a language only useful for adding some interaction to web pages,
form validations, etc. Nothing that required the complexity of multithreading.

Ryan Dahl, the creator of Node.js, saw this limitation as an opportunity. He wanted to
implement a server-side platform based on asynchronous I/O, which means you don’t need
threads (which makes things a lot easier). Concurrency can be a very hard problem to solve.
Having many threads accessing the same memory can produce race conditions that are very
hard to reproduce and fix.

Node.js is an open-source, cross-platform JavaScript run-time environment that executes


JavaScript code outside of a browser. Typically, JavaScript is used primarily for client-side
scripting, in which scripts written in JavaScript are embedded in a webpage's HTML and run
client-side by a JavaScript engine in the user's web browser.

Node.js lets developers use JavaScript to write Command Line tools and for server-side
scripting—running scripts server-side to produce dynamic web page content before the page
is sent to the user's web browser. Consequently, Node.js represents a "JavaScript
everywhere" paradigm, unifying web application development around a single programming
language, rather than different languages for server side and client side scripts.

Express is a minimal and flexible Node.js web application framework that provides a robust
set of features to develop web and mobile applications. It facilitates the rapid development
of Node based Web applications. Following are some of the core features of Express
framework −

● Allows to set up middlewares to respond to HTTP Requests.

● Defines a routing table which is used to perform different actions based on HTTP Method
and URL.

● Allows to dynamically render HTML Pages based on passing arguments to templates.

Cluster
A single instance of Node.js runs in a single thread. To take advantage of multi-core systems,
the user will sometimes want to launch a cluster of Node.js processes to handle the load.
The cluster module allows easy creation of child processes that all share server ports.

NodeJs single-threaded nature is by default using a single core of a processor. Therefore,


NodeJs introduced a cluster module to spawn processes. “Cluster” was introduced to scale
an application execution on multiple processor cores by creating worker processes. Worker
processes share a single port, therefore, requests are routed through a single port.

The cluster module is a NodeJS module that contains a set of functions and properties that
help us forking processes to take advantage of multi-core systems. It is propably the first
level of scalability you must take care in your node application, specifally if you are working
in a HTTP server application, before going to a higher scalability levels. With the cluster
module a parent/master process can be forked in any number of child/worker processes and
communicate with them sending messages via IPC communication.
Why and when we need to fork another process?
 Forking multiple processes is essential for freeing up memory and unloading single
process.
 When we need to delegate tasks (run them in parallel ) to another process for the
sake of the speed.

How It Works
The worker processes are spawned using the child_process.fork() method, so that they
can communicate with the parent via IPC and pass server handles back and forth. The
cluster module supports two methods of distributing incoming connections:

The first one (and the default one on all platforms except Windows), is the round-robin
approach, where the master process listens on a port, accepts new connections and
distributes them across the workers in a round-robin fashion, with some built-in smarts
to avoid overloading a worker process.

The second approach is where the master process creates the listen socket and sends it
to interested workers. The workers then accept incoming connections directly.The
second approach should, in theory, give the best performance. In practice however,
distribution tends to be very unbalanced due to operating system scheduler vagaries.
Loads have been observed where over 70% of all connections ended up in just two
processes, out of a total of eight.

The worker (child) processes are spawned using the child_proces.fork() method, so that
they can communicate with the parent via IPC and pass server handles back and forth.
The child_process.fork() method is a special case of child_process.spawn() used
specifically to spawn new Node.js processes. Like child_process.spawn(), a ChildProcess
object is returned. The returned ChildProcess will have an additional communication
channel built-in that allows messages to be passed back and forth between the parent
and child, through the send() method.

Installation of Softwares Used


Node.js and NPM and package
 Download the nodejs installer from Nodejs.org.
 Run the installer (the .msi file you downloaded in the previous step.)
 Follow the prompts in the installer
 Restart your computer. Nodejs won’t run until the system is restarted.
 Test Node. To see if Node is installed, open the Windows Command Prompt,
Powershell or a similar command line tool, and type node -v . This should print
the version number so you’ll see something like this v0.10.35 .
 Test NPM. To see if NPM is installed, type npm -v in Terminal. This should print
the version number so you’ll see something like this 1.4.28
 Create a test file and run it. A simple way to test that node.js works is to create a
simple JavaScript file: name it pdc.js, and just add the code console.log ('Node is
installed!'); .To run the code simply open your command line program, navigate to
the folder where you save the file and type node pdc.js . This will start Node.js
and run the code in the hello.js file. You should see the output Node is installed!

Docker (For containerizing the server)


 Install Docker installer from docker hub.
 Double-click Docker Desktop Installer.exe to run the installer.

 Follow the instructions on the installation wizard to accept the license, authorize
the installer, and proceed with the install.

When prompted, authorize the Docker Desktop Installer with your system
password during the install process. Privileged access is needed to install
networking components, links to the Docker apps, and manage the Hyper-V VMs.

 Click Finish on the setup complete dialog and launch the Docker Desktop
application.

 Search for docker desktop on your pc and if the whale sign appears in the
notification area, docker is installed successfully on the pc.

Creating a docker swarm for orchestrating the containers.


• First of connect to docker on machine via ssh using following command.

$ docker-machine ssh <machine name>

• Swarm can be created by running the following command.

$ docker swarm init –advertise-addr <manager-IP>


Jimp package for image processing
Supported types:

 @jimp/jpeg
 @jimp/png
 @jimp/bmp
 @jimp/tiff
 @jimp/gif

Jimp can be installed by running the following command:


npm install –save jimp

Algorithm
DES Algorithm for Image Encryption
The Data Encryption Standard is a block cipher, meaning a cryptographic key and algorithm
are applied to a block of data simultaneously rather than one bit at a time. To encrypt a
plaintext message, DES groups it into 64-bit blocks.

The Data Encryption Standard (DES) is a symmetric-key block cipher published by the
National Institute of Standards and Technology (NIST). DES is an implementation of a Feistel
Cipher. It uses 16 round Feistel structure. The block size is 64-bit. Though, key length is 64-
bit, DES has an effective key length of 56 bits, since 8 of the 64 bits of the key are not used
by the encryption algorithm (function as check bits only).

Parallelism in the process:


Firstly, the leader node reads the image, divides it into two and assigns one image to the
server running in its own machine and other part to the other machine connected over LAN
(Local Area Network).

The stand-alone systems have multiple cores. We take one core and assigning it as the
master core. The rest of the cores are slave cores. Our master core takes the image part as
an input and divides it into different parts depending on the number of cores. The image is
split using the Jimp module in NPM. It feeds each part to the encryption algorithm. The
encryption algorithm is for a specific part and does not depend on the other parts and can
be encrypted independently. Thus there are no dependencies between the cores and
prevents the overhead of inter core communication. While encryption is under process the
master node waits for the response. The master node assigns id(s) to each encryption
subdivision for identification.

The use of this is that all cores will return the encrypted part in random sequence. Thus in
order to encrypt the image in same subdivisions as the original image these id(s) assigned by
the master node are used to join the encrypted messages.

Each sub-part of the image assigned to each machine is also provided with id’s. Once both
the machines complete their tasks, the sub-parts are joined based on the id’s received by
the leader node and save on its local storage. Thus the process is parallelized and
distributed.

You might also like