0% found this document useful (0 votes)
197 views14 pages

Blowfish Image Encryption Guide

This code implements encryption and decryption of an image using the Blowfish algorithm. It takes the image file to encrypt as input, along with the file paths. A secret key is generated. The image is encrypted using the Blowfish cipher initialized in encryption mode with the secret key. It is then immediately decrypted using the cipher initialized in decryption mode with the same key. The encrypted image cannot be viewed as it will report as not found, showing the original has been securely encrypted.

Uploaded by

Ayush Maria
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
197 views14 pages

Blowfish Image Encryption Guide

This code implements encryption and decryption of an image using the Blowfish algorithm. It takes the image file to encrypt as input, along with the file paths. A secret key is generated. The image is encrypted using the Blowfish cipher initialized in encryption mode with the secret key. It is then immediately decrypted using the cipher initialized in decryption mode with the same key. The encrypted image cannot be viewed as it will report as not found, showing the original has been securely encrypted.

Uploaded by

Ayush Maria
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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
Abstract

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.
Introduction

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.

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.

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.

In one application Blowfish's slow key changing is actually a benefit: the password-hashing
method used in OpenBSD uses an algorithm derived from Blowfish that makes use of the slow
key schedule; the idea is that the extra computational effort required gives protection against
dictionary attacks.

Through this paper we have researched the encryption and decryption of an image.
Literature Review

Many studies have been conducted on the Blowfish algorithm and its applications in various
fields of study.

[1]Blowfish is a popular security algorithm that was developed by Bruce Schneier in the
advent of the year 1994. The algorithm works on the same line as DES and it consumes block
coding with blocks of a size of 64 bit. Blowfish became quite popular after its advent, just
because Bruce Schneier himself is one of the most famous cryptology expert and above this
the algorithm is non patented, open source freely and freely available for use and
modifications. Blowfish is a 64-bit block cipher with a variable-length key. It defines 2
distinct boxes: S boxes, a P box and four S boxes [3]. Taking into consideration the P box P
is a one-dimensional field with 18 32-bit values. The boxes contain variable values; those can
be implemented in the code or generated during each initialization. The S boxes S1, S2, S3,
and S4 each contain 256 32-bit values.

[2]In this paper, a Blowfish encryption algorithm for information security is designed and
analyzed. The work is done for networking and communication application for enhanced
network security and defense applications. In the proposed Blowfish algorithm reduce rounds
of algorithm and proposed single blowfish round. The design simulation is done by Xilinx
ISE software using the language of VHDL. Cryptography is the one of the main categories of
computer security that converts information from its normal form into an unreadable form. Its
ability to secure the protected data against attacks and its speed and efficiency in doing so.

[3]With the progress in communication technology, the necessity of information security has
become a global issue. Due to advancement in multimedia application, security becomes an
important issue of communication and storage of data. This paper is about cryptographic
analysis of data using 64-bits Blowfish which is a secret key block cipher having a variable
key size up to 448 bits designed in order to secure communication and improve its
performance. It iterates simple function 16 times by employing Feistel network. The blowfish
algorithm runs faster and prevents unauthorized attack than the popular existing algorithms.
Working environment for proposed system is MATLAB.

[4]Wired and wireless networks are becoming popular day by day. Due to rapid growth of
networks, information security becomes more important to protect commerce secrecy and
privacy. Encryption algorithm plays a crucial role in information security but securing data
also consumes a significant amount of resources such as CPU time and battery power. In this
paper we try to present a fair comparison between the most common four encryption
algorithms namely; AES, DES, 3DES and Blowfish in terms of security and power
consumption. Experiment results of comparison are carried out over different data types like
text, image, audio and video. This paper briefly describes a new method to enhance the
security of Blowfish algorithm; this can be possible by replacing the pre-defined XOR
operation by new operation ‘#’. When we are adding additional key and replacing old XOR
by new operation ‘#’, Blowfish will provides better results against any type of intrusion.

[5]Cryptography is the art of secrete writing; cryptography is the science of encrypting the
image. The study of encrypting is converting the original information from its normal form to
incomprehensible format. These days securing the data’s has become difficult, to reduce the
complexity, cryptography has been used. Image data security is the indispensable portion in
communication, defence and networks and so many. Providing security is more important for
the image. In this paper securing the image is executed with a “Blowfish algorithm” from the
perspective of cryptology. Blowfish is used for the applications, where the key doesn’t
change often and has a larger space to store the data. Encryption and decryption is performed
to obtain the original hiding information from the image.
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.

Code:
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class EncryptFile {

KeyGenerator keyGenerator = null;


SecretKey secretKey = null;
Cipher cipher = null;

public EncryptFile() {
try {
keyGenerator = [Link]("Blowfish");
secretKey = [Link]();
cipher = [Link]("Blowfish");
} catch (NoSuchPaddingException ex) {
[Link](ex);
} catch (NoSuchAlgorithmException ex) {
[Link](ex);
}
}
public static void main(String[] args) {
String fileToEncrypt = "[Link]";
String encryptedFile = "[Link]";
String decryptedFile = "[Link]";
String directoryPath = "E:/My stuff/Semesters/Semester 6/Cyber
Security/Project/image/";
EncryptFile encryptFile = new EncryptFile();
[Link]("Starting Encryption...");
[Link](directoryPath + fileToEncrypt,
directoryPath + encryptedFile);
[Link]("Encryption completed...");
[Link]("Starting Decryption...");
[Link](directoryPath + encryptedFile,
directoryPath + decryptedFile);
[Link]("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 {
[Link](Cipher.ENCRYPT_MODE, secretKey);
inStream = new FileInputStream(rawFile);
outStream = new FileOutputStream(encryptedFile);
byte[] buffer = new byte[1024];
int len;
while ((len = [Link](buffer)) > 0) {
[Link]([Link](buffer, 0, len));
[Link]();
}
[Link]([Link]());
[Link]();
[Link]();
} catch (IllegalBlockSizeException ex) {
[Link](ex);
} catch (BadPaddingException ex) {
[Link](ex);
} catch (InvalidKeyException ex) {
[Link](ex);
} catch (FileNotFoundException ex) {
[Link](ex);
} catch (IOException ex) {
[Link](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 {
[Link](Cipher.DECRYPT_MODE, secretKey);
inStream = new FileInputStream(encryptedFile);
outStream = new FileOutputStream(decryptedFile);
byte[] buffer = new byte[1024];
int len;
while ((len = [Link](buffer)) > 0) {
[Link]([Link](buffer, 0, len));
[Link]();
}
[Link]([Link]());
[Link]();
[Link]();
} catch (IllegalBlockSizeException ex) {
[Link](ex);
} catch (BadPaddingException ex) {
[Link](ex);
} catch (InvalidKeyException ex) {
[Link](ex);
} catch (FileNotFoundException ex) {
[Link](ex);
} catch (IOException ex) {
[Link](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/.
Screenshots
Input image:
The encrypted file does not open.
Decrypted file:

Now 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.
Conclusion

In this paper to transmit scrambling picture over the web we have utilized the blowfish
calculation. 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. For future improvement propelled algorithms can be design for
better security and scrambles increasingly convoluted picture.
References:

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

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

[3] A Review on Cryptography in Image Using Blowfish Algorithm, Smruti M. Patole,


Seema S. Patil.

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

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

You might also like