0% found this document useful (0 votes)
25 views36 pages

CRP PBL

Uploaded by

Vishnu M
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)
25 views36 pages

CRP PBL

Uploaded by

Vishnu M
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
You are on page 1/ 36

Cryptography Project Based Learning (PBL) Report on

IMAGE ENCRYPTION AND DECRYPTION (DES)


Submitted in partial fulfillment of the

Requirements for the award of the degree of

BACHELOR OF TECHNOLOGY
in

Computer Science and Engineering (Cyber Security)

Submitted by
M. Sai Kiran [22R11A6229]
P. Sai Charan [22R11A6233]
M. Vishnu [22R11A6227]
R. Sandeep [22R11A6235]
Under the esteemed guidance of

Mr. Vikram Sindhu


Senior Assistant Professor, CSE (Cyber Security) Department

Geethanjali College of Engineering and Technology

Geethanjali College of Engineering and Technology


Department of Computer Science and Engineering (Cyber Security)
(UGC AUTONOMOUS INSTITUTION)

Accredited by NAAC with ‘A+’ Grade & NBA, Approved by AICTE and Affiliated to JNTUH
Cheeryal (V), Keesara (M), Medchal (Dist), Telangana – 501 301

NOVEMBER - 2024
Geethanjali College of Engineering and Technology
Department of Computer Science and Engineering (Cyber Security)
(UGC AUTONOMOUS INSTITUTION)
Accredited by NAAC with ‘A+’ Grade & NBA, Approved by AICTE and Affiliated to JNTUH

Cheeryal (V), Keesara (M), Medchal (Dist), Telangana – 501 301.

November – 2024
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CYBER SECURITY)

CERTIFICATE
This is to certify that the Cryptography Project Based Learning (PBL) Report entitled “Image
Encryption and Decryption (DES)” is a bonafide work done and submitted by
M.SaiKiran[22R11A6229],P.SaiCharan[22R11A6233],M.Vishnu[22R11A627],
R.Sandeep[22R11A6235] during the academic year 2023 – 2024, in partial
fulfilment of the requirement for the award of Bachelor of Technology degree in
“Computer Science and Engineering (Cyber Security)” from Geethanjali College of
Engineering and Technology (Accredited by NAAC with ‘A+’ Grade & NBA,
Approved by AICTE and Affiliated to JNTUH), is a bonafide record of work
carried out by them under guidance and supervision.
Certified further that to the best of my knowledge, the work in this project has not been
submitted to any other institution for the award of any degree or diploma.
FACULTY GUIDE Dr. G. Kalyani

Mr. Vikram Sindhu Professor & HOD

Senior Assistant Professor CSE (Cyber Security) Department

CSE (Cyber Security) Department


HEAD OF THE DEPARTMENT

i
DECLARATION

We hereby declare that the project report entitled “Password Strength Checker” is an original
work done and submitted to the CSE (Cyber Security) Department, from Geethanjali College of
Engineering and Technology (Accredited by NAAC with ‘A+’ Grade & NBA, Approved by
AICTE and Affiliated to JNTUH), in partial fulfilment of the requirement for the award of
Bachelor of Technology in “Computer Science and Engineering (Cyber Security)” and it is a
record of bonafide project work carried out by us under the guidance of Mr. Vikram Sindhu,
Senior Assistant Professor, Department of CSE (Cyber Security).

We further declare that the work reported in this project has not been submitted, either in part or
in full, for the award of any other degree or diploma in this institute or any other Institute or
University.

Signature of the Student


M. Sai Kiran
(22R11A6229)

Signature of the Student


P. Sai Charan
(22R11A6233)

Signature of the Student


M. Vishnu
(22R11A6227)

Signature of the Student


R.Sandeep
(22R11A6235)

ii
ACKNOWLEDGEMENT

The satisfaction of completing this project would be incomplete without mentioning our gratitude
towards all the people who have supported us. Constant guidance and encouragement have been
instrumental in the completion of this project.
First and foremost, we thank the Chairman, Principal, and Vice Principal for availing
infrastructural facilities to complete the project on time.
We offer our sincere gratitude to our faculty guide Mr. Vikram Sindhu, Senior Assistant
Professor, CSE (Cyber Security) Department, from Geethanjali College of Engineering and
Technology (Accredited by NAAC with ‘A+’ Grade & NBA, Approved by AICTE and Affiliated
to JNTUH), for his immense support, timely cooperation, and valuable advice throughout the
course of our project work.
We would like to thank the Head of the Department, Dr. G. Kalyani, for her meticulous care and
cooperation throughout the project work.
We are thankful to all the project coordinators for their supportive guidance and for having
provided the necessary help to carry forward this project without any obstacles or hindrances.

iii
ABSTRACT

This project focuses on the development and implementation of an image encryption and
decryption system using the Data Encryption Standard (DES) algorithm, aimed at enhancing the
security of digital images during transmission and storage. With the increasing reliance on digital
imagery in various fields, including healthcare, finance, and personal communications,
safeguarding these images from unauthorized access and tampering has become essential.

The DES algorithm, a widely recognized symmetric key encryption technique, operates on 64-bit
blocks of data and employs a 56-bit key for both encryption and decryption processes. In this
project, images are first converted into a binary format and segmented into 64-bit blocks. Each
block undergoes a series of transformations, including initial permutation, key generation, and 16
rounds of substitution and permutation, ensuring a high level of security through confusion and
diffusion principles.

iv
TABLE OF CONTENTS

CERTIFICATE
i
DECLARATION
ii
ACKNOWLEDGEMENT
iii
ABSTRACT
i
TABLE OF FIGURES
v

1. INTRODUCTION
1
1.1 Introduction
1
1.2 Advantages of Password Strength Checker
2
2. AIM AND OBJECTIVE
3
3. BACKGROUND
4
4. LITERATURE REVIEW
5
5. SOFTWARE REQUIREMENT SPECIFICATION
7
5.1 Functional Requirements
7
5.2 Non-Functional Requirements
8
5.3 System Requirements
9
5.4 Performance Requirements
10
5.5 Documentation Requirements
11
6. MODELS APPLIED
12
6.1 Password Strength Evaluation Model
12
6.2 Real-time Feedback Model 6.3 User Interface Model
12
14

7. DATASETS AND PREPROCESSING 14

7.1 Datasets 14

7.2 Pre-processing 15

8. IMPLEMENTATION 17

9. TRAINING AND TESTING 17

9.1 Testing 17

9.2 Deployment and Performance Evaluation 19

10. SOURCE CODE 23

11. OUTPUT 26

12. CONCLUSION 27

13. FUTURE SCOPE 14. REFERENCES 28

vii
1. INTRODUCTION

1.1 Project-Based Learning (PBL) is an educational approach that emphasizes learning


through the completion of real-world, meaningful projects. Unlike traditional classroom
learning, which often focuses on theoretical knowledge, PBL allows students to actively
engage with a problem or challenge, develop practical skills, and apply their knowledge in a
hands-on context. This approach encourages critical thinking, collaboration, and
problemsolving, making it a powerful method for fostering deeper understanding and long-
term retention of concepts.

In the digital era, the proliferation of image data across various platforms has raised
significant concerns regarding privacy and security. Images are frequently shared and
transmitted over the internet, making them vulnerable to unauthorized access, manipulation,
and theft. As a result, there is an urgent need for robust encryption methods to protect
sensitive visual information from potential threats. This project addresses these concerns by
implementing an image encryption and decryption system based on the Data Encryption
Standard (DES) algorithm.

The Data Encryption Standard, developed in the 1970s, is one of the most widely used
symmetric key cryptographic algorithms. Although it has been largely replaced by more
advanced encryption standards, DES remains relevant for educational purposes and certain
applications where speed and simplicity are paramount. DES operates on fixed-size blocks of
data, utilizing a 56-bit key for both encryption and decryption processes. Its structure
involves multiple rounds of substitution and permutation, which enhance the security of the
encrypted data.

This project aims to explore the practical application of the DES algorithm in securing
images. It begins with the conversion of digital images into a binary format, followed by the
segmentation of the image data into 64-bit blocks suitable for DES processing. Each block is
then encrypted using the DES algorithm, producing ciphertext that is unintelligible without
the corresponding decryption key. The decryption process reverses the encryption steps,
allowing for the recovery of the original image.

1
1.2 Advantages

1. Data Security: The primary advantage of image encryption is the protection it


provides against unauthorized access. Encrypted images can only be viewed or
processed by individuals who possess the correct decryption key, thereby safeguarding
sensitive information.
2. Privacy Protection: In contexts such as healthcare, legal, or personal data sharing,
image encryption ensures that private and confidential images remain secure from
prying eyes, thus protecting individuals' privacy rights.
3. Integrity Assurance: Encryption helps maintain the integrity of the image data. Any
unauthorized alteration of the encrypted image can be detected during the decryption
process, ensuring that the original content remains intact.
4. Secure Transmission: Encrypted images can be safely transmitted over insecure
networks (like the internet) without the risk of interception or tampering. This is
particularly important for applications involving sensitive data, such as telemedicine
or financial transactions.
5. Compliance with Regulations: Many industries are subject to regulations that
mandate the protection of sensitive data. Image encryption helps organizations comply
with laws such as the Health Insurance Portability and Accountability Act (HIPAA) or
the General Data Protection Regulation (GDPR).
6. Prevention of Intellectual Property Theft: For artists, photographers, and
businesses that rely on visual content, encryption can help protect intellectual property
from theft or unauthorized use.
7. Access Control: Encryption allows for the implementation of access controls,
enabling organizations to restrict who can view or edit images based on their roles and
permissions.
8. Enhanced Trust: By utilizing encryption, organizations can build trust with their
clients and customers, assuring them that their sensitive information is being handled
securely.
9. Data Recovery: In the event of a data breach, encrypted images provide an additional
layer of security. Even if an attacker gains access to the encrypted files, they cannot
easily access the original content without the decryption key.

2
2. AIM AND OBJECTIVE

Aim:
The primary aim of the image encryption and decryption project is to develop a robust and
efficient system that secures digital images through encryption techniques, thereby ensuring
the confidentiality, integrity, and authenticity of visual data during storage and transmission.

Objectives:

Implementation of Encryption Algorithm: To implement a reliable encryption algorithm,


specifically the Data Encryption Standard (DES), for encrypting and decrypting digital
images. This includes understanding the algorithm's structure and functionality.

Image Processing: To convert digital images into a suitable format for encryption, which
involves transforming images into binary data and segmenting them into blocks compatible
with the DES algorithm.

Performance Evaluation: To evaluate the performance of the encryption and decryption


processes in terms of speed, efficiency, and resource utilization, ensuring that the system
operates effectively without significant delays.

Quality Assessment: To assess the quality of the encrypted images and the decrypted output,
ensuring that the original image can be accurately restored without loss of critical information
or significant degradation.

Security Analysis: To analyze the security of the encrypted images against various
cryptographic attacks, such as brute force attacks, and to evaluate the effectiveness of the key
management strategy used in the encryption process.

3
3. BACKGROUND

The rapid advancement of digital technology has transformed the way images are created,
shared, and stored. With the proliferation of digital cameras, smartphones, and social media
platforms, vast amounts of visual data are generated daily. While this has made it easier to
communicate and share information, it has also raised significant concerns regarding the
security and privacy of digital images. Unauthorized access, data breaches, and malicious
manipulation of images are pressing issues that necessitate effective security measures.

The need for image encryption can be traced back to the broader field of cryptography, which
has been used for centuries to protect sensitive information. Traditional cryptographic
techniques focused primarily on text data, but as digital imaging became more prevalent in
the late 20th century, the need for specialized encryption methods for images emerged. Early
efforts in image encryption primarily adapted existing text-based algorithms, but these
methods often proved inadequate due to the unique characteristics of image data, such as its
high dimensionality and the need for perceptual quality.

4
4. LITERATURE REVIEW

The field of image encryption and decryption has garnered significant attention due to the
increasing need for securing digital images in various applications, including healthcare, finance,
and personal privacy. This literature review explores key methodologies, algorithms, and
advancements in image encryption and decryption, highlighting their effectiveness and
limitations.

1.Traditional Cryptographic Algorithms

Early research in image encryption often employed traditional cryptographic algorithms, such as
the Data Encryption Standard (DES) and the Advanced Encryption Standard (AES).

1. Zhang et al. (2006) demonstrated the application of AES for image encryption,
emphasizing its strong security features. They noted that while AES is computationally
efficient, its performance could be improved when applied to large images by optimizing
block processing.
2. Khan et al. (2015) explored the use of DES in image encryption, highlighting its
simplicity and ease of implementation. However, they noted vulnerabilities to brute-force
attacks, prompting the need for stronger algorithms.

2.Chaos-based Encryption Techniques

Chaos theory has been extensively applied to image encryption due to its inherent randomness
and sensitivity to initial conditions.

1. Fridrich et al. (1998) introduced chaos-based image encryption methods that utilize
chaotic maps for pixel permutation and substitution. Their work demonstrated that chaotic
systems could produce highly secure encryption keys, making it difficult for attackers to
predict the encrypted output.
2. B. S. Manjunath et al. (2010) further refined chaos-based techniques, proposing a hybrid
approach that combined chaotic encryption with traditional methods. Their findings
indicated that such hybrid systems significantly enhance security while maintaining high
image quality.

3. Pixel Permutation and Substitution Techniques

Pixel permutation and substitution are fundamental components of many image encryption
schemes.

1. Liu et al. (2010) proposed a novel encryption scheme that combined pixel permutation
with substitution, achieving a high level of security while preserving the visual quality of

5
the encrypted image. They emphasized the importance of randomness in key generation to
prevent predictable patterns.
2. Zhou et al. (2016) developed a pixel-based encryption algorithm that utilized a
combination of substitution and diffusion techniques. Their results showed that the
proposed method effectively mitigated vulnerabilities associated with statistical attacks.

4.Block-based Encryption Methods

Block-based encryption methods have gained traction due to their efficiency and adaptability to
image data.

1. M. A. Al-Mamun et al. (2015) explored block cipher techniques for image encryption,
demonstrating that dividing images into smaller blocks allows for efficient processing
while enhancing security. They highlighted the need for a balance between computational
efficiency and security levels.
2. B. S. Manjunath et al. (2016) proposed a block-based encryption scheme that utilized a
combination of pixel scrambling and diffusion techniques. Their work indicated that
block-based methods could effectively reduce redundancy in images and enhance security.

6
5. SOFTWARE REQUIREMENTS SPECIFICATION

5.1 Functional Requirements

1. Image Input:
o The system must allow the user to input the path of an image file to be
encrypted.
2. Key Input:
o The system must require the user to enter an 8-character key for the encryption
process.
3. Image Encryption:
o The system must encrypt the input image using the DES algorithm and the
provided key.
o The encrypted image must be saved in a binary format (e.g., .dat file).
4. Image Decryption:
o The system must allow the user to input the path of an encrypted image file for
decryption.
o The system must decrypt the encrypted image using the same DES algorithm
and the provided key.
5. Output of Decrypted Image:
o The system must save the decrypted image in a standard format (e.g., .jpg file).
6. Error Handling:
o The system must handle errors gracefully, providing meaningful error
messages when issues occur (e.g., invalid key length, file not found).
7. User Interaction:
o The system must interact with the user via console input and output, guiding
them through the encryption and decryption processes.
5.2 Non-Functional Requirements

1. Performance:
o The encryption and decryption processes should be completed in a reasonable
time frame, particularly for images of varying sizes.

7
2. Security:
o The system must ensure that the encryption process provides a level of security
that protects the image data from unauthorized access.
o The key management should be handled securely, ensuring that keys are not
hard-coded or exposed unnecessarily.
3. Usability:
o The user interface (console prompts) should be clear and easy to understand,
allowing users to navigate the encryption and decryption processes without
confusion.
4. Scalability:
o The system should be able to handle images of various sizes and formats, with
consideration for future enhancements (e.g., supporting other encryption
algorithms).
5. Compatibility:
o The system should be compatible with various operating systems that support
Java, ensuring that it can run on different platforms without modification.
6. Reliability:
o The system should consistently perform encryption and decryption accurately
without data loss or corruption.
7. Maintainability:
o The code should be structured in a way that allows for easy updates and
maintenance, including clear documentation and adherence to coding
standards.
8. Portability:
o The application should be portable, allowing it to be executed on any system
with a compatible Java Runtime Environment (JRE).
5.3 System Requirements

1. Hardware Requirements:

Processor (CPU): A dual-core processor (e.g., Intel Core i5 or equivalent) for better
performance, especially when processing larger images or running multiple applications
simultaneously.

8
Memory (RAM):4 GB of RAM or more. This will allow for smoother multitasking and
better performance when handling larger image files.

Storage: At least 500 MB of free disk space to accommodate the JRE, application files, and
additional space for images and encrypted files.

Graphics: While the application does not require a dedicated graphics card, having a decent
integrated graphics solution can help with rendering images if you decide to extend the
application with a GUI in the future.

Operating System: A 64-bit operating system is recommended for better performance with
Java applications, especially when dealing with larger memory allocations.

2. Software Requirements:

1. Java Runtime Environment (JRE):


o Version: The application requires a Java Runtime Environment (JRE) version 8 or
later. It is recommended to use the latest stable version of Java to ensure
compatibility and security.
o Installation: The JRE must be installed on the system to run Java applications. Users
can download it from the official Oracle website or adopt OpenJDK, which is an
open-source implementation of the Java Platform.
2. Java Development Kit (JDK) (Optional):
o If you plan to modify the code or develop further applications, it is advisable to
install the Java Development Kit (JDK) version 8 or later. The JDK includes
development tools such as the Java compiler (javac), which is necessary for
compiling Java programs.
3. Integrated Development Environment (IDE) (Optional):
o IntelliJ IDEA: A powerful IDE for Java development with many features.
o Eclipse: A widely used open-source IDE for Java and other programming
languages.
o NetBeans: Another popular open-source IDE that supports Java.
4. Image Processing Library:
o The code relies on the built-in Java libraries for image processing
(javax.imageio.ImageIO), so no additional libraries are needed for basic
functionality. Apache Commons Imaging: For handling various image formats.
o ImageJ: A powerful image processing library.
5. Operating System:
o Windows (Windows 7 or later)
o macOS (macOS 10.10 or later)
o Linux (various distributions such as Ubuntu, Fedora, etc.)
6. File System Access:

9
o The application requires access to the file system to read the input image, save the
encrypted file, and save the decrypted image. Ensure that the user running the
application has the necessary permissions to perform these actions.

7. Optional Libraries for Enhanced Functionality:


o Cryptography: Libraries like Bouncy Castle can provide additional cryptographic
algorithms beyond DES.
o User Interface: If you want to create a graphical user interface (GUI), libraries like
JavaFX or Swing can be used

5.4 Performance Requirements

1. Computational Requirements
Encryption/Decryption Complexity:
 The DES algorithm operates on 64-bit blocks and involves 16 rounds of
encryption, each requiring key-dependent operations like permutation and
substitution.
 The runtime is linear with respect to the size of the image data in bytes, as the DES
algorithm processes all bytes of the image data sequentially.
 Impact: Larger images result in higher encryption/decryption times due to the
block-by-block processing.
2. Key Generation:
 The DESKeySpec creation and SecretKeyFactory.generateSecret() operations are
lightweight and involve only key material preparation, which is negligible
compared to encryption/decryption.
3. BufferedImage Memory:
 The BufferedImage object stores the entire image in memory. The memory usage
scales with the resolution and color depth of the image.
 Example: A 1920x1080 image with 24-bit color depth requires about 6 MB of
memory.
4. Byte Array Conversion:
 During encryption, the image is converted to a byte array using a
ByteArrayOutputStream. This byte array can consume significant memory if the
image size is large.

10
 The encrypted byte array adds additional memory overhead.
5. Decryption:
 Similarly, decryption produces a byte array before reconstructing the
BufferedImage. This step temporarily duplicates the memory required for the
image data.

5.4 Documentation Requirements

in a Project-Based Learning (PBL) setup, the documentation requirements should cover both
technical and functional aspects.

Project Overview: Purpose, significance, and objectives (evaluate password strength and
suggest improvements).

Requirements:

Hardware: Basic system specs.

Software: Programming language (e.g., Java), libraries , IDEs.

Functional Specifications:

• Input: User-entered image path and key.


• Output: Saving the encrypted image in the given location.

Testing: Test cases for different image inputs.

Conclusion: Summary of the project's benefits and potential enhancements.

11
6. MODELS APPLIED

6.1 Block Cipher Model


DES is a block cipher, meaning it processes fixed-size blocks of data (64 bits or 8 bytes) at a
time. Images, being larger than the block size, require block cipher modes to handle the entire
dataset.
Block Cipher Modes of Operation:
DES encryption uses one of the following modes for secure and efficient encryption of the
image:
 ECB (Electronic Codebook):
o Each block is encrypted independently.
o Advantages: Simple to implement.
o Disadvantages: Repetitive patterns in the image can be exposed in the
ciphertext, making it insecure for image encryption. For example, large areas
of uniform color produce visible patterns in the encrypted image.
 CBC (Cipher Block Chaining):
o Each block of plaintext is XORed with the previous ciphertext block before
being encrypted.
o Advantages: Provides better security by ensuring that identical plaintext
blocks produce different ciphertext blocks.
o Disadvantages: Requires an Initialization Vector (IV), adding complexity.
 CFB (Cipher Feedback) and OFB (Output Feedback):
o Convert DES into a stream cipher for continuous encryption.
o Advantages: Suitable for scenarios where data sizes are irregular.
o Disadvantages: Can be slower due to the feedback mechanism.
 CTR (Counter Mode):

12
o A counter value is used to generate unique key streams for each block.
o Advantages: Allows parallel processing of blocks, improving performance.
o Disadvantages: Requires careful management of counter values.
2. Image-to-Byte Transformation Model
 Images must be converted to a byte array before encryption, as DES operates on
binary data.
 This transformation typically involves:
1. Image Encoding: Using formats like JPEG or PNG to generate a compressed
byte stream.
2. Memory Buffering: Storing the byte data in memory for DES processing.
Design Considerations:
 The compression level (e.g., for JPEG) can impact the size and quality of the image,
which indirectly affects encryption performance.
 The image's color depth (e.g., grayscale vs. 24-bit RGB) impacts the byte array size
and processing time.
3. Symmetric Key Management Model
 DES uses a single, symmetric key for both encryption and decryption.
 In image encryption:
o The key must be exactly 8 bytes long (64 bits).
o Key management is critical for security. If the key is exposed, the image can
easily be decrypted.
Key Models:
 Static Key Model: The same key is used for all images, which is simpler but less
secure.
 Dynamic Key Model: A unique key is generated for each image or session, enhancing
security but requiring secure key distribution.
4. Performance Optimization Model
Efficient image encryption using DES involves balancing encryption speed, memory usage,
and security:
 Chunk-based Encryption:
o Large images are divided into smaller chunks, with each chunk encrypted
sequentially.
o Reduces memory overhead and enables streaming.

13
 Parallel Processing:
o For modes like CTR, blocks can be processed in parallel to improve speed.

7. DATASETS AND PREPROCESSING

7.1 Datasets for Image Encryption

Types of Images:

Grayscale Images:

 Single channel, simpler structure.


 Smaller in size compared to RGB images.
 Useful for performance benchmarking due to reduced data complexity.

Color Images (RGB):

 Three channels (Red, Green, Blue).


 Larger data size and complexity.
 Common in real-world scenarios where images contain rich color information.

High-Resolution Images:

 Higher resolutions (e.g., 1920x1080 or 4K) increase the encryption workload.


 Useful for testing performance and scalability.

Compressed vs. Uncompressed Images:

 Compressed: Formats like JPEG and PNG are often used for storage efficiency.
 Uncompressed: Formats like BMP or TIFF retain original pixel data, providing a
more direct mapping for encryption.

7.2 Preprocessing

Image Resizing:
 Resize images to a manageable resolution to reduce encryption overhead.
 Example: Downscale large images to 256x256 or 512x512 if high resolution is
unnecessary.
Format Conversion:
 Convert the image into a supported format (e.g., JPEG, PNG).
 If using formats like BMP or TIFF, ensure proper handling of larger file sizes.

14
Color Space Conversion:
 For color images, you can process each channel (R, G, B) independently or combine
them into a single byte array.
 Alternatively, convert RGB images to grayscale to simplify the encryption process.
Flattening Image Data:
 Convert the image into a one-dimensional byte array.
 This is necessary because DES operates on binary data rather than structured image
formats.
Padding:
 Ensure that the image byte array size is a multiple of the DES block size (8 bytes or 64
bits).
 Common padding schemes:
 PKCS#5/PKCS#7 Padding: Adds extra bytes to fill the block.
 Zero Padding: Adds zeros to the end of the data.
Normalization (Optional):
 Normalize pixel values (e.g., scaling them to the range [0, 1] or [0, 255]) if needed for
specific encryption schemes.

15
8. IMPLEMENTATION

1. Set Up the Environment


 Install Java Development Kit (JDK):
o Ensure JDK (version 8 or later) is installed on your system.
o Verify by running java -version and javac -version in your terminal/command
prompt.
 Prepare an IDE or Text Editor:
o Use an IDE like IntelliJ IDEA, Eclipse, or a text editor like VS Code with a
Java plugin.
 Add Required Libraries:
o The program uses only standard Java libraries, so no external dependencies are
required.
2. Prepare an Image File
 Select an image for encryption and ensure it is in a readable format (e.g., JPG, PNG).
 Place the image in an accessible directory and note its file path.
3. Code Implementation
Step 1: Write the Java Program
 Copy the provided code into a new Java file, e.g., DESImageEncryption.java.
Step 2: Verify the Code
 Ensure the key logic components are implemented correctly:
1. Image Reading: Uses ImageIO.read to load the image.
2. Key Validation: Checks if the encryption key is exactly 8 characters (8 bytes
for DES).
3. Encryption and Decryption: Uses the Cipher class for DES
encryption/decryption.
4. File Writing: Saves the encrypted and decrypted files.
Step 3: Compile the Program
 Open the terminal/command prompt.
 Navigate to the folder containing the DESImageEncryption.java file.
4. Run the Program
Step 1: Start the Program

16
 Execute the compiled Java program:
Step 2: Provide Inputs
 Input Image Path:
o Enter the full path to the image you want to encrypt, e.g., C:\images\
sample.jpg.
 Encryption Key:
o Enter an 8-character key for encryption (e.g., myp@sswd).
o Ensure the key meets the DES requirement of being exactly 8 bytes long.
Step 3: Encrypted File
 The program will generate an encrypted binary file named encrypted_image.dat in the
current directory.
Step 4: Decrypt the Image
 Enter the path to the encrypted_image.dat file when prompted.
 The program will generate a decrypted image, decrypted_image.jpg, in the same
directory.
5. Verify Output
 Encrypted File:
o Open the encrypted_image.dat file in a text editor or binary viewer. It should
appear as unreadable binary data.
 Decrypted Image:
o Open the decrypted_image.jpg file in an image viewer.
o Verify that it matches the original image.
6. Debugging and Testing
Common Issues:
1. Key Length Validation:
o If the key is not exactly 8 characters, the program will terminate with a
message.
2. File Not Found:
o Ensure the paths provided for input files exist and are correct.
3. Image Format Issues:
o Ensure the image format is supported by ImageIO.
Test Cases:
 Use various image formats (JPG, PNG, BMP).

17
 Test with different image sizes and resolutions.
 Test with valid and invalid keys.
7. Modify and Extend
Enhancements:
1. Use AES Instead of DES:
o Replace DES with AES for better security.
2. Dynamic Key Management:
o Add functionality to generate and store keys securely.
3. Error Handling:
o Improve exception messages for better debugging.
4. GUI Integration:
o Create a graphical interface for selecting files and entering keys.

18
9. TRAINING AND TESTING

9.1 TESTING

Case 1: Valid Inputs


 Description: Test with a valid image file and an 8-character key.
 Steps:
1. Place a test image (e.g., test.jpg) in the folder.
2. Run the program and provide:
 Path to the image: test.jpg
 Key: myp@sswd
3. Verify:
 The file encrypted_image.dat is created.
 The decrypted image (decrypted_image.jpg) matches the original.
Case 2: Invalid Key Length
 Description: Test with keys that are not exactly 8 characters.
 Steps:
1. Provide a key shorter than 8 characters (e.g., short).
2. Provide a key longer than 8 characters (e.g., toolongkey).
3. Verify:
 The program exits with the message: "Key must be exactly 8 characters
long."
Case 3: Invalid File Path
 Description: Test with an invalid or nonexistent file path.
 Steps:
1. Enter an incorrect file path (e.g., invalid_path.jpg).
2. Verify:
 The program catches the exception and prints a descriptive error
message, e.g., "FileNotFoundException".

19
Case 4: Non-Image File
 Description: Test with a non-image file as input.
 Steps:
1. Use a text file (e.g., test.txt) as input.
2. Verify:
 The program fails with an appropriate error, such as "IOException".

9.2 DEPLOYMENT AND PERFORMANCE EVALUATION

Deployment

1. Compile the Code:


 Use javac to compile the program:
2. Create a Runnable JAR:
 Use jar to package the program into a runnable JAR file.
 Include any dependencies if needed.
3. Prepare for Execution:
 Provide the JAR file to users.
 Ensure the target system has a compatible Java Runtime Environment (JRE).

Performance Evaluation

 Encryption Time: Time taken to encrypt an image.


 Decryption Time: Time taken to decrypt an encrypted file.
 Memory Usage: Amount of memory consumed during encryption and decryption.
 Output Quality: Ensure the decrypted image matches the original.

20
10. SOURCE CODE

file:DesImageEncryption.java

import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.nio.file.Files;
import java.util.Base64;
import java.util.Scanner;

public class DESImageEncryption {

private static final String ALGORITHM = "DES";

// Encrypts the image using DES


public static byte[] encryptImage(BufferedImage image, String key) throws Exception {
// Convert BufferedImage to byte array
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(image, "jpg", baos);
byte[] imageBytes = baos.toByteArray();

// Encrypt the byte array


SecretKey secretKey
=SecretKeyFactory.getInstance(ALGORITHM).generateSecret(new
DESKeySpec(key.getBytes()));
Cipher cipher = Cipher.getInstance(ALGORITHM);
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
byte[] encryptedBytes = cipher.doFinal(imageBytes);

return encryptedBytes;
}

// Decrypts the image using DES


public static BufferedImage decryptImage(byte[] encryptedImage, String key) throws
Exception {
// Decrypt the byte array
SecretKey secretKey
=SecretKeyFactory.getInstance(ALGORITHM).generateSecret(new
DESKeySpec(key.getBytes()));

21
Cipher cipher = Cipher.getInstance(ALGORITHM);
cipher.init(Cipher.DECRYPT_MODE, secretKey);
byte[] decryptedBytes = cipher.doFinal(encryptedImage);

// Convert byte array back to BufferedImage


ByteArrayInputStream bais = new ByteArrayInputStream(decryptedBytes);
return ImageIO.read(bais);
}

public static void main(String[] args) {


Scanner scanner = new Scanner(System.in);
try {
System.out.println("Enter the path of the image to encrypt:");
String imagePath = scanner.nextLine();
BufferedImage image = ImageIO.read(new File(imagePath));

// Define a key (must be exactly 8 bytes for DES)


System.out.println("Enter an 8-character key for encryption:");
String key = scanner.nextLine();
if (key.length() != 8) {
System.out.println("Key must be exactly 8 characters long.");
return;
}

byte[] encryptedImage = encryptImage(image, key);


// Save the encrypted image to a file (binary format)
File encryptedFile = new File("encrypted_image.dat");
Files.write(encryptedFile.toPath(), encryptedImage);
System.out.println("Encrypted image saved as: " + encryptedFile.getAbsolutePath());

// Decrypt the image


System.out.println("Enter the path of the encrypted image to decrypt:");
String encryptedImagePath = scanner.nextLine();
byte[] encryptedBytes = Files.readAllBytes(new File(encryptedImagePath).toPath());

BufferedImage decryptedImage = decryptImage(encryptedBytes, key);


// Save the decrypted image
File decryptedFile = new File("decrypted_image.jpg");
ImageIO.write(decryptedImage, "jpg", decryptedFile);
System.out.println("Decrypted image saved as: " + decryptedFile.getAbsolutePath());

} catch (Exception e) {
e.printStackTrace();
} finally {
scanner.close();
}

22
}
}

11.OUTPUTS

Fig-1: Output from the code

Fig-2: Encrypted Image

23
Fig-3: Decrypted Image

24
12. CONCLUSION
In conclusion, image encryption and decryption using DES has been an important milestone
in the evolution of cryptographic techniques. While it laid the foundation for securing digital
data, its limitations, such as a small key size and vulnerability to brute-force attacks, have
rendered it unsuitable for modern high-security applications. DES can still serve as a valuable
educational tool and may find limited use in low-security or resource-constrained
environments. However, with the growing need for robust and efficient encryption methods,
DES has largely been replaced by more advanced algorithms like AES. As technology
advances, the focus will continue to shift toward quantum-resistant and AI-integrated
encryption systems, ensuring stronger protection for sensitive visual data in an increasingly
interconnected world.

25
13. FUTURE SCOPE

The future scope of image encryption and decryption using DES is limited due to its inherent
vulnerabilities, such as susceptibility to brute-force attacks and relatively small key size (56
bits). However, DES can still find applications in low-security environments or for
educational purposes to demonstrate cryptographic principles. In the future, advancements
may focus on hybrid approaches, combining DES with more robust algorithms like AES to
balance simplicity and security in resource-constrained environments. Additionally,
optimizing DES-based encryption for lightweight IoT devices or embedding it within
steganographic systems could offer niche applications. Nevertheless, for high-security
demands, DES will likely be replaced by modern, quantum-resistant encryption techniques.

26
14. REFERENCES

1. https://www.geeksforgeeks.org/encrypt-and-decrypt-image-using-java/

2. https://www.tutorialspoint.com/cryptography/data_encryption_standard.htm

27

You might also like