Vous êtes sur la page 1sur 15

Implementation of Blowfish Algorithm in image encryption and

decryption

J component

CSE 4003

Prepared by

Sushma Gadepalli 16BCE2269


Ayush Maria 16BCE0400

Project Report

Submitted to

Prof. Anand M
1. Abstract

With the progress in data exchange by electronic system, the need of information security has become
a necessity. Information security is used for the protection of information. It protects its availability,
privacy and integrity. Access to stored information on computer databases has increased greatly. More
companies store business and individual information on computer than ever before. Much of the
information stored is highly confidential and not for public viewing. Cryptography is the science of
writing in secret message and is an ancient art. In data and telecommunications, cryptography is
necessary when communicating over any untrusted medium, which includes just about any network,
particularly over the Internet. In this project, Blow Fish algorithm, which is a symmetric block cipher
that can be used for both encryption and decryption is analysed and its applications are determined.
Blowfish algorithm was used as an alternative to existing algorithms.

2. Keywords

Blowfish, encryption, decryption, Key, DES, DES3, Block cipher, Cryptography.

3. Motivation

File inputs such as audio, video, images, or even messages are easily broken down and available to
anyone over the internet. It doesn’t have high security and hence are easily accessible. Images
uploaded on the internet can be accessed by anyone anywhere. Hence through this paper, we
encrypted images using Blowfish algorithm.

4. Objective
1) To encrypt and decrypt images using the Blowfish algorithm.
2) To compare the Blowfish algorithm to that of the DES algorithm.

5. Introduction

Security is a huge concern when it comes to sharing any file over the web. This paper focuses on
addressing this issue. Cybercrimes are committed on a daily basis. Half the crimes committed are not
even recognised by people. Millions of crimes are committed every day. It is hard to find the people
committing such crimes. Stealing information on the internet, in any form is a cybercrime.
Images are used in our daily lives. An image can range from anything, it may be just an object to a
person’s face or information. There have been many cases where a person’s identity has been stolen
due to just an image being leaked. This may be for any sort of file; it isn’t limited to just images. This
then leads to a cybercrime.

But images can be protected from being stolen. The content present in the picture can be hidden. This
is what is known as encryption. This prevents hackers from seeing any information present in an
image. The image is sent from the receiver. A key is provided with which the image is encrypted.
When the image is received by the receiver, the image is decrypted using the same key. This is called
an encryption algorithm.

The Blowfish algorithm is a symmetric encryption algorithm. This implies that it uses the same secret
key to encrypt and decrypt messages. It is also a block cipher. This means that it that it divides the
entire message into fixed length blocks during encryption and decryption. The block length for the
Blowfish algorithm is bits. Blowfish consists of two parts: key-expansion and data encryption.
Blowfish was designed as a general-purpose algorithm, intended as an alternative to the aging DES
and free of the problems and constraints associated with other algorithms. At the time Blowfish was
released, many other designs were proprietary, encumbered by patents or were commercial or
government secrets. Schneier has stated that, "Blowfish is unpatented, and will remain so in all
countries. The algorithm is hereby placed in the public domain and can be freely used by anyone."
Notable features of the design include key-dependent S-boxes and a highly complex key schedule.
Blowfish is a fast block cipher, except when changing keys. Each new key requires pre-processing
equivalent to encrypting about 4 kilobytes of text, which is very slow compared to other block
ciphers. This prevents its use in certain applications but is not a problem in others.

The blowfish algorithm is used as a great application in many fields of study. It can be used for the
encryption and decryption of various types of data. It could be a message, image, audio etc. Through
this paper we have researched the encryption and decryption of an image. To make the data secure
from various attacks and for the integrity of data we must encrypt the data before it is transmitted or
stored. Government, military, financial institution, hospitals and private business deals with
confidential images about their patient (in Hospitals), geographical areas (in research), enemy
positions (in defence), product, financial status. Most of this information is now collected and stored
on electronic computers and transmitted across network to another computer. If these confidential
images about enemy positions, patient and geographical areas fall into the wrong hands, then such a
breach of security could lead to declination of war, wrong treatment etc.
6. Literature Review

Many studies have been conducted on the Blowfish algorithm and its applications in various fields of
study. There have been many recent trends in various fields and applications. One of the most recent
application of Blowfish algorithms was in information security. Various encryption algorithms such
as AES, DES, Blowfish etc, are being studied in detail to determine which one of these is the most
efficient.

These days securing data is that of a very difficult task. To reduce the complexity of that,
cryptography is in use. However securing images is that of a more difficult task. According to a
research conducted, images are easily available to the public. To prevent this, Blowfish Algorithm
was used to encrypt and decrypt images to increase security of the image.

A study conducted showed that using any medium to hide information is called steganography. When
images are used to hide information, it’s called image steganography. An algorithm that was followed
for this process was Least Bit Algorithm where each and every bit of the image is taken, and
information is hidden in it. However, this method is easily breakable. Hence Blowfish algorithm was
used to make the image more secure and unavailable to the hackers.

A project was developed wherein the Blowfish algorithm was used to encrypt and decrypt an image.
In the aforementioned study, an analysis was conducted between the Blowfish algorithm and the DES
algorithm. Through this it was concluded that the Blowfish algorithm is faster than that of the DES
algorithm. A few images were taken into consideration and the speed taken for the encryption and
decryption of the image was observed. Through this they could safely say that the Blowfish algorithm
is faster.

In a study conducted, it was determined that the Blowfish algorithm cannot be broken even if an
intrusion takes place more than 28r+1 time where r is the number of rounds. If the number of rounds
is increased, the algorithm becomes stronger. Various factors were taken into consideration and
compared with that of AES and DES. Through this it was concluded that Blowfish is more powerful
and efficient compared to the other encryption algorithms.

Research has been done on image encryption and decryption using MATLAB. A code was developed
on MATLAB. Images were taken and tested. The images taken were encrypted and decrypted. The
size of the encrypted image was reduced a little, but the size of the decrypted image was the same as
that of the original image.

A comparative study has been conducted on the DES, AES, Blowfish and the DES3 algorithms.
Through this it was determined that the Blowfish algorithm is faster and more efficient when it came
to both DES and AES algorithms. It showed that even though more intrusion attacks were conducted,
the algorithm worked every single time. It was also concluded that if the number of rounds are
increased the security of the algorithm becomes stronger and harder to break or intrude by any kind of
attackers.

Another study conducted on AES, DES and Blowfish algorithm showed that AES is the fastest
symmetric key encryption algorithm out of the three. The coding was done through java in this this
paper.

A study was conducted on the Blowfish Algorithm at the B.P.Poddar Institute of Management &
technology, in West Bengal. In this study various cryptographic key algorithms were compared baaed
on a certain set factor. The algorithms compared were DES, 3DES, AES, RC6. These algorithms were
then compared to that of the Blowfish algorithm. It was then concluded that the Blowfish algorithm is
faster than that of the DES and DES3 algorithms. This was observed by comparing and observing the
speed for different packet sizes.

7. Existing Work

Many studies and experiments have been conducted on the previously existing algorithms such as
DES and DES3.

DES:

DES is a 64-bit block cipher under 56-bit key. The algorithm processes with an initial permutation,
sixteen rounds block cipher and a final permutation. DES application has been very popular in
commercial, military, and other domains in the last few decades. The DES standard is very public.
But there are still a few design criteria that are kept hidden and private. It is classified and hence not
known by the public. There has been considerable controversy over the design, particularly in the
choice of a 56-bit key.

DES3:

Due to advances in key searching in the DES algorithm, the triple DES algorithm was required to be
developed. It uses three different round messages. This makes the algorithm very strong to break since
its very hard to break 2^168 possible combinations. There is another option in this algorithm. That is
to use two encryption keys. It reduces the memory requirement of keys in the triple DES.

Both of these algorithms have their advantages as well as disadvantages. Many studies have been
conducted on these algorithms. But not as many have been conducted with Blowfish. Hence in this
paper we have chosen to implement encryption and decryption using the Blowfish Algorithm.
8. Methodology

We have implemented a code which encrypts and decrypts any image of our choice. The secret key is
given at the beginning. The image name of the image to be encrypted is given. The path of the image
stored must also be specified. The image on running the code is encrypted first and then immediately
decrypted. The encrypted image is not visible to us. It is a private image which just states that the file
is not found. In our paper we have used blowfish algorithm rather than the encryption algorithms
because as compared to the other encryption algorithms such as AES or DES, Blowfish has more
robustness. This makes it stronger against any intrusions.

Source Code:

import java.io.File;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.InputStream;

import java.io.OutputStream;

import java.security.InvalidKeyException;

import java.security.NoSuchAlgorithmException;

import javax.crypto.BadPaddingException;

import javax.crypto.Cipher;

import javax.crypto.IllegalBlockSizeException;

import javax.crypto.KeyGenerator;

import javax.crypto.NoSuchPaddingException;

import javax.crypto.SecretKey;

public class EncryptFile {

KeyGenerator keyGenerator = null;


SecretKey secretKey = null;

Cipher cipher = null;

public EncryptFile() {

try {

keyGenerator = KeyGenerator.getInstance("Blowfish");

secretKey = keyGenerator.generateKey();

cipher = Cipher.getInstance("Blowfish");

} catch (NoSuchPaddingException ex) {

System.out.println(ex);

} catch (NoSuchAlgorithmException ex) {

System.out.println(ex);

public static void main(String[] args) {

String fileToEncrypt = "forest.jpg";

String encryptedFile = "encryptedFile.jpg";

String decryptedFile = "decryptedFile.jpg";

String directoryPath = "E:/My stuff/Semesters/Semester 6/Cyber Security/Project/image/";

EncryptFile encryptFile = new EncryptFile();

System.out.println("Starting Encryption...");

encryptFile.encrypt(directoryPath + fileToEncrypt,

directoryPath + encryptedFile);

System.out.println("Encryption completed...");

System.out.println("Starting Decryption...");

encryptFile.decrypt(directoryPath + encryptedFile,
directoryPath + decryptedFile);

System.out.println("Decryption completed...");

/**

* @param srcPath

* @param destPath

*/

private void encrypt(String srcPath, String destPath) {

File rawFile = new File(srcPath);

File encryptedFile = new File(destPath);

InputStream inStream = null;

OutputStream outStream = null;

try {

cipher.init(Cipher.ENCRYPT_MODE, secretKey);

inStream = new FileInputStream(rawFile);

outStream = new FileOutputStream(encryptedFile);

byte[] buffer = new byte[1024];

int len;

while ((len = inStream.read(buffer)) > 0) {

outStream.write(cipher.update(buffer, 0, len));

outStream.flush();

outStream.write(cipher.doFinal());

inStream.close();

outStream.close();
} catch (IllegalBlockSizeException ex) {

System.out.println(ex);

} catch (BadPaddingException ex) {

System.out.println(ex);

} catch (InvalidKeyException ex) {

System.out.println(ex);

} catch (FileNotFoundException ex) {

System.out.println(ex);

} catch (IOException ex) {

System.out.println(ex);

/**

* @param srcPath

* @param destPath

*/

private void decrypt(String srcPath, String destPath) {

File encryptedFile = new File(srcPath);

File decryptedFile = new File(destPath);

InputStream inStream = null;

OutputStream outStream = null;

try {

cipher.init(Cipher.DECRYPT_MODE, secretKey);

inStream = new FileInputStream(encryptedFile);

outStream = new FileOutputStream(decryptedFile);

byte[] buffer = new byte[1024];


int len;

while ((len = inStream.read(buffer)) > 0) {

outStream.write(cipher.update(buffer, 0, len));

outStream.flush();

outStream.write(cipher.doFinal());

inStream.close();

outStream.close();

} catch (IllegalBlockSizeException ex) {

System.out.println(ex);

} catch (BadPaddingException ex) {

System.out.println(ex);

} catch (InvalidKeyException ex) {

System.out.println(ex);

} catch (FileNotFoundException ex) {

System.out.println(ex);

} catch (IOException ex) {

System.out.println(ex);

The image we had given for encryption was named forest. It is a jpg file stored in the path E:/My
stuff/Semesters/Semester 6/Cyber Security/Project/image/.
9. Screenshots

Input image:
The encrypted file does not open. This is because all the pixels are hidden through the encryption
process.

Encrypted file:

Decrypted file:
The best part of the blowfish algorithm is that the quality of the image is still the same. It still
maintains the quality of the image even after decryption of the image.

10. Issues With project

We weren’t able to implement the Blowfish algorithm to locate an image from any destination.

11. Conclusion

In this paper to transmit scrambling pictures over the web we have utilized the blowfish algorithm.
Recently utilized algorithm like AES, DES thus more has been supplanted by the blowfish algorithm,
due to creating fruitful adequacy on security. Blowfish algorithm can't be effectively broken by the
programmers until they locate the right mixes. This is increasingly hard to shape the accurate blends of
the lock. To make the algorithm more grounded number of rounds has been expanded. It requires less
investment to scramble and decode the picture than some other calculations. It has also been concluded
that the Blowfish algorithm works faster than that of DES algorithm.

12. Future work

In this paper we have only implemented the encryption and decryption of an image. For future
improvement propelled algorithms can be design for better security and scrambles increasingly
convoluted picture. The security of the image can be increased by developing more algorithms that
conduct better encryption and decryption than that of the Blowfish algorithm.

The Blowfish algorithm can be implemented with more than just an image. Audio files, video files and
more such files can be encrypted and decrypted using Blowfish algorithm. This can increase the security
of any sort of file and not just images.

13. References

[1] Blowfish Algorithm, Neha Khatri Valmik, V. K Kshirsagar.

[2] Blowfish algorithm for information security, Saikumar Manku, K. Vasanth.

[3] A Study of New Trends in Blowfish Algorithm, Gurjeevan Singh, Ashwani Kumar, K. S. Sandha.
[4] A Review on Cryptography in Image Using Blowfish Algorithm, Smruti M. Patole, Seema S.
Patil.

[5] A Study of New Trends in Blowfish Algorithm, Gurjeevan Singh, Ashwani Kumar, K.S. Sandha.

[6] Cryptography in Image Using Blowfish Algorithm S. S. Sudha, S. Divya.

[7] Using Blowfish encryption to enhance security feature of an image, Shreyank N Gowda.

[8] Enhanced Blowfish Algorithm for Image Encryption and Decryption with Supplementary Key, K.
Kanagalakshm, M. Mekala.

[9] Image encryption and decryption using Blowfish algorithm in MATLAB, Pia Singh, Karamjeet
Singh.

[10] Image encryption and decryption using blowfish algorithm, Rajeshwari Patil.

[11] Image encryption and decryption using Blowfish algorithm, Mrs. Smita Desai, Chetan A.
Mudholkar, Rohan Khade, Prashant Chilwant.

[12] Superiority of Blowfish Algorithm, Pratap Chnadra Mandal.

[13] DES, AES and Blowfish: Symmetric Key Cryptography Algorithms Simulation Based
Performance Analysis, Jawahar Thakur, Nagesh Kumar.

Vous aimerez peut-être aussi