Thesies Stealthy Talk - Enhance Cybersecurity Using Image Steganography
Thesies Stealthy Talk - Enhance Cybersecurity Using Image Steganography
Steganography
Submitted by
Mahmodul Hasan Arif
Registration No. 18502003875
Session: 2018 - 2019
Supervised by
Md. Imran Hossain
Head, Department of CSE
Daffodil Institute of IT (DIIT)
I declare that the project work titled “Stealthy Talk: Enhance Cybersecurity
Using Image Steganography” being submitted in partial fulfillment for the degree
of B.Sc. (Hon’s) in Computer Science & Engineering is the original work carried
out by me. It has not found any part of other project work submitted for any
degree or diploma, either in this or any other university.
i
CERTIFICATE
BOARD OF EXAMINERS
Examiner 1
Examiner 2
ii
ACKNOWLEDGMENT
Despite my efforts, the success of this project depends largely on the encourage-
ment and guidance of my mentors. I would like to take this opportunity to express
my gratitude to the people who are playing a vital role in the successful completion
of this project.
iii
ABSTRACT
iv
List of Tables
v
List of Figures
vi
Contents
DECLARATION i
CERTIFICATE ii
ACKNOWLEDGMENT iii
ABSTRACT iv
LIST OF TABLES v
LIST OF FIGURES vi
Chapter 1. Introduction 1
1.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Motivation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.3 Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.4 Expected Outcome . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.5 Project Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
vii
3.5 System Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.5.1 Work Flow . . . . . . . . . . . . . . . . . . . . . . . . 15
3.5.2 Flow Chart . . . . . . . . . . . . . . . . . . . . . . . 16
3.5.3 Database Design . . . . . . . . . . . . . . . . . . . . 17
3.5.4 Data Flow Diagram . . . . . . . . . . . . . . . . . . . 17
3.5.5 Use Case Diagram . . . . . . . . . . . . . . . . . . . . 19
Chapter 5. Conclusion 30
5.1 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
5.2 Scope of Further Work . . . . . . . . . . . . . . . . . . . . . . . . 30
viii
Chapter 1
Introduction
1.1 Overview
In the digital age, securing sensitive communication is crucial, particularly for defense
systems where confidentiality is vital. Traditional encryption methods, while effective,
may still draw attention if intercepted. Steganography offers an alternative by concealing
the existence of messages within seemingly harmless data, such as images, providing an
additional layer of security and discretion in transmission.
This project, Stealthy Talk – Enhance Cyber Security Using Image Steganog-
raphy, employs the Least Significant Bit (LSB) algorithm to hide confidential messages
within images. Unlike encryption, which makes data unreadable without a key, steganog-
raphy embeds the message directly into the image, making it nearly undetectable. This
technique is especially useful in military and defense operations, where covert communi-
cation can be essential to protect critical information from adversaries.
The system involves two types of users: Admins and Users. Admins can create
and manage users, encrypt images, and send stego images to users, who can then decrypt
and extract the hidden message.
1.2 Motivation
In today’s digital age, the need for secure communication is more pressing than ever.
While technological advancements have enabled rapid data exchange and connectivity,
they have also increased the risks of cyber-attacks, data breaches, and digital espionage.
For defense systems, the stakes are especially high, with sensitive information such as
military strategies and classified intelligence at risk. Traditional encryption methods are
widely used to secure communications, but they can inadvertently attract attention, sig-
naling to adversaries that sensitive information is being transmitted. In scenarios where
the existence of communication must remain undetected, encryption alone may not be
sufficient.
1
Steganography is particularly valuable in military and defense operations, where
covert communication is essential for maintaining strategic advantage. The system al-
lows for a dual-user setup: an admin who can encrypt, manage, and send stego images,
and users who can receive and decrypt them. The admin can also share stego images
externally, providing flexibility in how secure information is transmitted. This project
addresses the need for an advanced communication method that goes beyond encryption,
offering protection not only for the message content but also for the fact that a message
is being sent.
Although this project is primarily designed for defense applications, the potential
uses of steganography extend to other industries like finance, healthcare, and law enforce-
ment, where data security is critical. Stealthy Talk not only strengthens communication
security for military operations but also paves the way for broader applications in en-
hancing cybersecurity across various sectors.
1.3 Objective
The primary objective of Stealthy Talk – Enhance Cyber Security Using Image
Steganography is to develop a robust and secure communication platform specifically
for the defense sector. By leveraging image steganography, the project aims to ensure
the confidentiality and integrity of sensitive information, making it nearly impossible for
external parties to detect.
The platform will enable effective user management and access control, allowing
the admin to oversee user accounts and roles, ensuring only authorized personnel have ac-
cess to critical information. The system will facilitate seamless encryption and decryption
of messages within images, making secure communication is efficient and user-friendly.
2
Stego images will be distributed securely both within and outside the application,
giving admins flexibility in sharing confidential information across different communica-
tion channels. Users will have access to an organized inbox system for receiving and
decrypting stego images, ensuring timely access to crucial messages.
A robust database infrastructure will manage user data, stego images, and mes-
sages, ensuring secure and efficient data handling. The application is expected to stream-
line operational efficiency by enabling quick and secure transmission of sensitive informa-
tion, improving decision-making and coordination within defense operations.
Moreover, the platform will be scalable and adaptable to meet evolving security
needs and operational scenarios, ensuring long-term effectiveness. By promoting the
adoption of advanced cybersecurity practices, the project will contribute to the overall en-
hancement of national security, providing a secure communication system that strength-
ens the defense sector’s ability to safeguard the nation.
At the back-end, essential functions include user management, where the system
validates credentials and permissions, and stego image processing, which employs the
Least Significant Bit (LSB) algorithm for embedding and extracting messages. The
back-end also manages message storage and ensures that stego images are linked to their
corresponding secret messages. A robust database underpins the project, securely storing
user data, stego images, and messages. Key tables include user information, stego images,
roles, and message links, ensuring data integrity and access control.
In summary, the project layout integrates advanced front-end and back-end systems
with secure database management, allowing Admins and Users to communicate discreetly.
By leveraging steganography through the LSB algorithm, Stealthy Talk enables covert and
secure information exchange, essential for high-stakes defense operations.
3
Chapter 2
Literature Review
2.1 Introduction
The literature survey is a vital part of research, providing a comprehensive overview of
existing studies and methodologies relevant to a specific domain. As cyber threats be-
come increasingly sophisticated, innovative solutions to protect sensitive information are
more essential than ever. Digital communication has transformed the way information
is shared, but it has also exposed organizations to risks like data breaches and unau-
thorized access. To counter these challenges, various secure communication techniques
have been explored, with steganography emerging as a powerful method for concealing
sensitive data. This chapter will provide a detailed review of key concepts and techniques
in steganography, with an emphasis on the Least Significant Bit (LSB) algorithm. This
widely used technique allows secret messages to be embedded in digital images without
significantly altering their appearance, making it effective for covert communication.
4
not only improves the security of hidden data but also preserves the visual quality of the
original image, making it a promising solution for secure communication in digital media
[4].
Additionally, Alam et al. (2020) presented a new 8-directional pixel selection tech-
nique for LSB-based image steganography. Their method allows for a more strategic
selection of pixels, increasing the embedding capacity and security of the hidden mes-
sages while minimizing visual artifacts. This approach aims to enhance the robustness of
steganographic techniques against detection [3].
2.2.2 Encryption
Encryption plays a critical role in steganography, as it converts plaintext into ciphertext,
thereby protecting hidden messages. This process adds an additional layer of security,
ensuring that even if the stego image is detected, the hidden information remains inde-
cipherable. Common encryption algorithms include symmetric key encryption methods,
such as the Advanced Encryption Standard (AES) and Data Encryption Standard (DES),
which use the same key for both encryption and decryption. While efficient, they require
secure key management. Asymmetric key encryption, exemplified by RSA, uses a pair
of keys (public and private) for the encryption and decryption processes, providing en-
hanced security at the cost of increased computational complexity.
Hashim et al. (2018) demonstrated the integration of AES encryption with LSB
modification techniques in audio steganography, highlighting the versatility of stegano-
graphic methods across different media types. Their work emphasizes the importance of
robust encryption in maintaining data confidentiality within steganography [5].
2.2.3 Cybersecurity
Cybersecurity encompasses practices, technologies, and processes designed to protect
computer systems, networks, and data from cyber threats. This field is integral to safe-
guarding information integrity, confidentiality, and availability. Key concepts that inter-
sect with steganography include data integrity, which ensures that information remains
accurate and unaltered during transmission or storage; confidentiality, ensuring access is
restricted to authorized users; and authentication and authorization, which verify user
identities and permissions, respectively.
5
2.2.4 Steganalysis
Steganalysis refers to the detection of hidden information within media files, particu-
larly digital images. This practice involves analyzing the statistical properties of media
to uncover anomalies indicating the presence of a hidden message. Key methods of
steganalysis include visual inspection, where analysts look for visible artifacts or dis-
tortions in the image; statistical analysis, which employs models to detect deviations
from normal image properties; and machine learning, where algorithms identify patterns
and anomalies indicative of steganography by training on datasets of steganographic and
non-steganographic images.
• Least Significant Bit (LSB) Insertion: A simple method that embeds messages
by modifying the least significant bits of image pixels, balancing ease of implemen-
tation and visual imperceptibility. Least Significant Bit (LSB) is a common and
popular technique for steganographic images, especially when the spatial domain
of an image is considered.[2]
6
• Adaptive Steganography: Embeds messages based on the content of the im-
age, focusing on areas where changes are less noticeable, such as noisy or textured
regions.
These techniques provide a strong foundation for secure and efficient communica-
tion, ensuring the robustness and confidentiality of hidden messages within the applica-
tion.
Two researchers, Dr. Thomas Ernst and Dr Jim Reeds were convinced that the
third book contained hidden code. Dr Ernst, while a graduate student at the University
of Pittsburgh published a 200page paper, but it attracted little attention . Dr. Reeds,
a mathematician at AT T Labs independently began delving into this matter. As he
searched for information on Trithemius’ works, he discovered Dr. Ernst paper.These two
researchers discovered in relatively short order, that there were hidden messages con-
tained in the third book. The messages contained in the tables were of minor interest.
One message contained the Latin equivalent of “The quick brown fox jumps over the lazy
dog.” A second message was “The bearer of this letter is a rogue and a thief. Guard
yourself against him. He wants to do something to you.” And, the third message was the
beginning of the 23rd Psalm.
1. Microdots developed by the Nazis are essentially microfilm chips created at high
magnification(usually over 200X). These microfilm chips are the size of periods on
a standard typewriter. These dots could contain pages of information, drawings,
etc.
7
2. The Nazis also employed invisible inks and null ciphers.
3. Currently, the emphasis has been on various forms of digital steganography. Com-
monly there are a number of digital technologies that the community is concerned
with, namely text files.After the events of September 11, 2001, there was imme-
diate concern voiced regarding the possible use of steganography by the al Queda
network.
8
Chapter 3
3.1 Introduction
In this project book presents a comprehensive approach to design and implementing to
specify the encryption and embedding techniques to ensure secure and imperceptible data
hiding. the authors used 5 phase to describe the procedure. These phase are planning,
requirement analysis, implementation, testing, maintenance.
3.2 Methodology
The chosen approach for this research article is a well-justified decision to address the
current problem of data security inside organisations. It includes the five essential steps
of planning, requirement analysis, proposed algorithm, implementation, testing, and out-
comes. This technique demonstrates its applicability in a time of constantly changing
cyber threats by providing an organised and methodical approach. It guarantees a thor-
ough examination of all facets of data security, data integrity, confidentiality, and au-
thentication. Crucially, this technique is flexible, enabling adjustments to match certain
requirements and situations, and it fits in well with the research objective of produc-
ing data that is steganographically safe. Overall, the selected technique is a strong and
practical strategy that is ideal for tackling the urgent problems with data security.
3.3.1 Planning
The initial phase is crucial for a successful study. The authors developed a comprehensive
plan outlining the study topic and operational procedures. They began with a thorough
review of numerous studies on related subjects, which helped identify gaps in existing
literature. This informed their choice of title and guided the design of their study to
address the limitations observed in previous works while ensuring the originality of their
findings.
9
requirements encompass what users expect from the system, emphasizing data security,
including payload capacity, resilience, and imperceptibility. The key functionalities iden-
tified for LSB XOR with Peewit edge detection in video steganography include seamless
embedding of secret data without noticeable visual distortions, secure encryption of the
data to safeguard confidentiality, and reliable extraction of hidden data from stego images
without compromising integrity.
3.3.3 Maintenance
Maintaining information hiding in steganography software is essential for ensuring the
security and effectiveness of data concealment techniques. The principles of embedding
efficiency, robustness, and security are vital for safeguarding embedded messages from
unauthorized detection and extraction. To achieve this, developers should implement
regular algorithm updates, performance monitoring, and periodic security assessments.
User education on the importance of information hiding principles and best practices for
secure data concealment is crucial. Keeping abreast of the latest developments in ste-
ganalysis techniques will help ensure that the steganography software remains effective.
10
higher frequencies, where modifications are less noticeable. This approach offers greater
robustness against image manipulations such as compression, cropping, or scaling, com-
monly applied during storage or transmission. Since the embedding occurs in the fre-
quency domain, the visual quality of the image is preserved, and the hidden message
becomes more resilient to detection and attack. The Transform Method is particularly
effective in applications requiring high imperceptibility and security.
The Human visual system (HVS) cannot detect changes in the colour or intensity
of a pixel when the LSB bit is modified. This is psycho-visual redundancy since this
can be used as an advantage to store information in these bits and yet notice no major
difference in the image. Algorithm of LSB method of steganography.There might be two
different phases of LSB method, embedding phase and extracting phase. Algorithms of
both of the phases are given below:
2. Extract all the characters from the given text file(message file) and store it in the
array called (messagearray).
3. Retrieve the characters from the Stego key and store them in a array called Ke-
yarray. A stego- key is used to control the hiding process so as to restrict detection
and/or recovery of the embedded data.
4. Take first pixel and characters from Key- array and place it in first component
of pixel. If there are more characters in Key array, then place rest in the first
component of next pixels.
5. Place some terminating symbol to indicate end of the key. 0 has been used as a
terminating symbol in this algorithm.
6. Place characters of message Array in each component of next pixels by replacing it.
11
8. Again place some terminating symbol to indicate end of data.
4. Retrieve the characters stored in the least significant bits (LSBs) of the pixel’s
components, starting from the first pixel.
6. After the terminating symbol for the key, start extracting characters from the LSBs
of the next pixel components and append them to (extractedMessageArray).
7. Continue this process until the terminating symbol indicating the end of the message
is encountered.
9. The extracted key and message are now retrieved from the stego image.
The simplest steganography techniques embed the bits of the message directly into
least significant bit plane of the cover image in a deterministic sequence. Modulating the
least significant bit does not result in human-perceptible difference because the amplitude
of the change is small. To hide a secret message inside an image, a proper cover image
is needed. Because this method uses bits of each pixel in the image, it is necessary to
use a lossless compression format, otherwise the hidden information will get lost in the
transformations of a lossy compression algorithm. When using a 24-bit color image, a bit
of each of the red, green and blue color components can be used, so a total of 3 bits can
be stored in each pixel. For example, the following grid can be considered as 3 pixels of
a 24-bit color image, using 9 bytes of memory:
(00100111 11101001 11001000)
(00100111 11001000 11101001)
(11001000 00100111 11101001)
When the character A, which binary value equals 10000001, is inserted, the follow-
ing grid results:
(00100111 11101000 11001000)
(00100110 11001000 11101000)
(11001000 00100111 11101001)
In this case, only three bits needed to be changed to insert the character success-
fully. On average, only half of the bits in an image will need to be modified to hide a
secret message using the maximal cover size.
12
3.4.3 Least Significant Bit (LSB) Algorithm
The Least Significant Bit (LSB) algorithm is a widely used method for embedding hidden
messages within digital images.
2. Extraction Module:
13
Figure 3.2: LSB Extraction Algorithm
In our system, we are using Spatial Methods, specifically the Least Significant
Bit (LSB) technique. These methods directly modify the pixel values of the image to
embed the secret message. Although less robust against image manipulations like com-
pression or filtering compared to transform-based techniques, spatial methods are simple
to implement and offer high payload capacity, making them suitable for our application’s
requirements.
14
3.5.1 Work Flow
The workflow of ”Stealthy Talk” outlines the steps a user or admin takes when interacting
with the system. The application enables users to securely hide and extract messages
within images using steganography, while admins oversee user activity and manage the
application settings.
15
3.5.2 Flow Chart
The workflow of ”Stealthy Talk” outlines the steps a user or admin takes when interacting
with the system.
16
3.5.3 Database Design
The database design for the ’Stego Image – Enhance Cyber Security Using Image Steganog-
raphy’ application is crucial to ensure efficient data storage, retrieval, and management.
This section outlines the database schema, detailing the structure and relationships be-
tween various tables to support the application’s functionalities. Pictorial representation
of database is in fig 3.5 The database design for the ’Stego Image’ application is structured
to efficiently manage user data, stego images, roles, and messages.
17
Figure 3.6: DFD Level 0
uploading a cover image, which is then passed to the embedding module where hidden
data is inserted using the Least Significant Bit (LSB) technique. This stego image is
saved in the system and sent to the user through Stealthy Talk. The user, upon re-
ceiving the stego image, decrypts it to extract the hidden message. The system manages
the entire workflow, ensuring secure data embedding, transmission, and decryption, while
maintaining the confidentiality of the communication.
18
3.5.5 Use Case Diagram
The Use Case Diagram visually represents interactions between users (Actors) and the
system (Admins). In the ”Stealthy Talk” application, the primary actors are Users and
Admins.
Users include captains and soldiers who utilize the application for secure messag-
ing. Their main responsibilities involve registering and logging into the system, uploading
cover images for embedding hidden messages, decoding stego images to retrieve secret
messages, and managing their profiles.
Admins, representing the chief of defense, oversee application operations. They are
responsible for approving user registrations, monitoring activity, embedding messages in
images, and managing system settings.
19
Chapter 4
4.1 Introduction
The design specification is the foundation of the design concept and describes the exact
operation and attributes of a system. Creating a clear and unambiguous design speci-
fication for tiny designs is a relatively simple undertaking. Design Specification, on the
other hand, is a description of how a design is created. We try to display the design of
our web application in the Analysis of Design and Specification area. We also reviewed
a variety of tools that we employ in the development of our applications. And we will
explain step by step how we have implemented these tools in our project.
Upon logging in, users see a personalized dashboard that shows recent activities,
embedded images, and quick links to start embedding or extracting messages. The dash-
board also includes easy access to account settings and logout options, ensuring that
users can manage their profiles efficiently. Notifications for successful operations and sys-
tem updates are integrated into the dashboard, keeping users informed. The embedding
interface allows users to upload an image and type the message they wish to hide. Clear
buttons like ”Embed Message” guide them through the process and provide real-time
feedback on embedding progress. After embedding, users can easily download the modi-
fied image, with an option to preview it before saving.
Similarly, the extraction interface lets users upload a steganographic image and
click ”Extract Message.” The extracted message is displayed securely in a designated
text box, ensuring confidentiality and data integrity. Users can also copy the extracted
message directly from the interface for convenience.
20
For admins, the dedicated admin panel provides a comprehensive overview of sys-
tem activities, user management options, and security monitoring tools. Admins can
monitor logs, track user actions, and manage system configurations efficiently. The panel
also features user analytics, allowing admins to assess user engagement and identify any
unusual patterns that may require attention.
This intuitive design not only ensures a robust and user-friendly experience but
also prioritizes security in both message embedding and extraction processes, making it
suitable for users ranging from novices to advanced professionals in the field.
21
Figure 4.2: Admin & User Log
22
Figure 4.4: User Requests
23
Figure 4.6: Embedding Image
24
4.2.10 User Dashboard
The user dashboard displays the user’s activity, including previously embedded images,
message extractions, and account settings. It provides easy access to the main features
of the application.
25
Figure 4.11: Decrypt Image
As shown in Table 4.1, the system successfully embedded and extracted messages
of varying sizes in both JPEG and PNG formats. The application was able to handle
high-resolution images with larger message sizes without performance degradation.
26
Table 4.2: Performance Benchmarking
Operation Image Format Message Size (Bytes) Time Taken (ms)
Embedding JPEG (1024x768) 512 150
Embedding PNG (800x600) 1024 190
Embedding JPEG (1280x720) 2048 230
Extraction PNG (1920x1080) 4096 250
Extraction JPEG (640x480) 8192 300
Extraction PNG (1024x768) 16384 350
Here in the following figure 4.12a we can see some difference between cover im-
age and embedded image. If tester have access of the cover image then the tester can
differentiate cover image and embedded image otherwise tester can’t get the difference.
As shown in Table 4.3, the system demonstrates high resistance to common ste-
ganalysis methods. The detection success rate of hidden messages remained at 96.67% for
all test cases, indicating that the system effectively conceals messages without introducing
noticeable artifacts or patterns that would compromise security.
27
4.3.4 Error Handling and Robustness
The system was tested for its robustness in handling erroneous inputs, such as incompat-
ible image formats or oversized messages. The system successfully detected and handled
these errors without crashing, providing appropriate error messages to users.
Table 4.4 shows that the system effectively handles errors and provides meaningful
feedback to users. This demonstrates the reliability and robustness of the system in
real-world scenarios.
4.3.5 Conclusion
In conclusion, the Stealthy Talk system exhibits strong performance, high security, and
excellent usability across multiple testing phases. Its ability to handle various image
formats and message sizes efficiently makes it a versatile tool for secure communication.
The comparative analysis shows that the system outperforms similar tools in terms of
embedding capacity and security. User feedback further reinforces the system’s success
in meeting its objectives of enhancing cybersecurity using image steganography.
28
4.4.2 Operational Feasibility Study
This term evaluates if the project is solving all the functionality effectively. How well it
performs the functionality to avoid error and how efficiently it easily replaced the paper-
basedsystem. My system can easily utilize, support and perform all the functionality
efficiently.
29
Chapter 5
Conclusion
5.1 Summary
The Stealthy Talk – Enhance Cyber Security Using Image Steganography ap-
plication represents a significant step forward in leveraging steganographic techniques to
enhance the security of communication within the defense system. By embedding secret
messages within digital images, the application ensures that sensitive information can be
transmitted covertly, reducing the risk of interception and unauthorized access.
30
References
[2] Ahmed A,, A Secure Image Steganography using LSB and Double XOR Op-
erations,International Journal of Computer Science and Network Security , 2020
May;20(5):139.
[3] Alam ST, Jahan N, Hassan MM, A New 8-Directional Pixel Selection Technique
of LSB Based Image Steganography, InInternational Conference on Cyber Security
and Computer Science, 2020 Feb 15 (pp. 101-115).
[5] Hashim J, Hameed A, Abbas MJ, Awais M, Qazi HA, Abbas S, LSB
Modification based audio steganography using advanced encryption standard (AES-
256) technique. 12th International Conference on Mathematics, Actuarial Science,
Computer Science and Statistics (MACS), 2018 Nov 24 (pp. 1-6). IEEE.
[6] Astuti Y.P., Setiadi D.R.I.M., Rachmawanto E.H., Sari C.A., Simple and se-
cure image steganography using LSB and triple XOR operation on MSB. 2018 Inter-
national Conference on Information and Communications Technology (ICOIACT),
2018. doi:10.1109/icoiact.2018.8350661.
31
Appendix
Embedding Process
The embedding process is a critical component of the steganography application, where
secret messages are concealed within cover images.
32
54 t h i s . imageUrl = e . t a r g e t . r e s u l t ;
55 c o n s o l e . l o g ( t h i s . imageUrl )
56 };
57 r e a d e r . readAsDataURL ( f i l e ) ;
58 }
59
60 customAdapterPlugin ( e d i t o r ) {
61 e d i t o r . p l u g i n s . g e t ( ’ F i l e R e p o s i t o r y ’ ) . c r e a t e U p l o a d A d a p t e r = ( l o a d e r ) => {
62 r e t u r n new Adapter ( l o a d e r , e d i t o r . c o n f i g ) ;
63 };
64 }
65
66 onReady ( e d i t o r ) {
67 e d i t o r . p l u g i n s . g e t ( ’ F i l e R e p o s i t o r y ’ ) . c r e a t e U p l o a d A d a p t e r = ( l o a d e r ) => {
68 r e t u r n new Adapter ( l o a d e r , e d i t o r . c o n f i g ) ;
69 };
70 }
71
72 encryptImage ( ) {
73 c o n s t { s u b j e c t , i m a g e d a t a , msg , u s e r i d } = t h i s . HFormGroup1 . v a l u e ;
74 i f ( i m a g e d a t a && i m a g e d a t a . f i l e s && i m a g e d a t a . f i l e s . l e n g t h > 0 ) {
75 const f i l e = image data . f i l e s [ 0 ] ;
76 c o n s t r e a d e r = new F i l e R e a d e r ( ) ;
77 r e a d e r . o n l o a d = ( ) => {
78 c o n s t img = new Image ( ) ;
79 img . o n l o a d = ( ) => {
80 c o n s t c a n v a s = document . c r e a t e E l e m e n t ( ’ canvas ’ ) ;
81 const ctx = canvas . getContext ( ’ 2 d ’ ) ;
82 c a n v a s . width = img . width ;
83 c a n v a s . h e i g h t = img . h e i g h t ;
84 c t x . drawImage ( img , 0 , 0 ) ;
85 c o n s t imageData = c t x . getImageData ( 0 , 0 , c a n v a s . width , c a n v a s . h e i g h t ) ;
86 c o n s t data = imageData . data ;
87
88 l e t binaryMsg = msg . s p l i t ( ’ ’ ) . map( c h a r => c h a r . charCodeAt ( 0 ) . t o S t r i n g ( 2 ) .
padStart (8 , ’0 ’) ) . j o i n ( ’ ’ ) ;
89 binaryMsg += ’ 0 0 0 0 0 0 0 0 ’ ;
90
91 c o n s o l e . l o g ( ” Binary Message t o e nc od e : ” , binaryMsg ) ; // Debug
92
93 l e t msgIndex = 0 ;
94 f o r ( l e t i = 0 ; i < data . l e n g t h && msgIndex < binaryMsg . l e n g t h ; i += 4 ) {
95 i f ( msgIndex < binaryMsg . l e n g t h ) {
96 data [ i ] = ( data [ i ] & 0xFE) | p a r s e I n t ( binaryMsg [ msgIndex ] , 2 ) ; // Red
channel
97 msgIndex++;
98 }
99 i f ( msgIndex < binaryMsg . l e n g t h ) {
100 data [ i + 1 ] = ( data [ i + 1 ] & 0xFE) | p a r s e I n t ( binaryMsg [ msgIndex ] , 2 ) ; //
Green c h a n n e l
101 msgIndex++;
102 }
103 i f ( msgIndex < binaryMsg . l e n g t h ) {
104 data [ i + 2 ] = ( data [ i + 2 ] & 0xFE) | p a r s e I n t ( binaryMsg [ msgIndex ] , 2 ) ; //
Blue c h a n n e l
105 msgIndex++;
106 }
107 }
108
109 c t x . putImageData ( imageData , 0 , 0 ) ;
110 c a n v a s . t o B l o b ( b l o b => {
111 t h i s . addStegoImage ( b l o b ) ;
112 } , ’ image / j p e g ’ ) ;
113 };
114 img . s r c = r e a d e r . r e s u l t a s s t r i n g ; // S e t t h e image s o u r c e from t h e F i l e R e a d e r
result
115 };
116 r e a d e r . readAsDataURL ( f i l e ) ; // Read t h e image f i l e
117 } else {
118 c o n s o l e . e r r o r ( ’ No f i l e s e l e c t e d ’ ) ;
119 }
120 }
121 addStegoImage ( imageData : Blob ) {
33
122 c o n s t f i l e = new F i l e ( [ imageData ] , ’ u p l o a d e d i m a g e . png ’ , { t y p e : imageData . t y p e } ) ;
123 console . log ( f i l e )
124 c o n s t formData = new FormData ( ) ;
125 formData . append ( ’ s u b j e c t ’ , t h i s . HFormGroup1 . v a l u e . s u b j e c t ) ;
126 formData . append ( ’ u s e r i d ’ , t h i s . u s e r I n f o . u s e r . u s e r i d ) ;
127 formData . append ( ’ image ’ , f i l e ) ;
128 c o n s o l e . l o g ( formData )
129 t h i s . a p i S e r v i c e . postAPI ( ‘ a d d s t e g o i m a g e . php ‘ , formData ) . s u b s c r i b e ( ( data ) => {
130 c o n s t path : any = data
131 c o n s o l e . l o g ( path . i m a g e i d )
132 t h i s . HFormGroup2 . v a l u e . i m a g e i d = path . i m a g e i d
133 t h i s . HFormGroup2 . v a l u e . message = t h i s . HFormGroup1 . v a l u e . msg
134 t h i s . a p i S e r v i c e . postAPI ( ‘ a d d s t e g o s . php ‘ , t h i s . HFormGroup2 . v a l u e ) . s u b s c r i b e ( (
f i n a l D a t a ) => {
135 console . log ( finalData )
136 t h i s . r o u t e r . n a v i g a t e ( [ ’ . / admin / s t e g o / a l l −e n c r y p t e d −image ’ ] )
137 })
138 }) ;
139
140 }
141 getImage ( ) {
142 l e t imageName = ’ u p l o a d e d i m a g e . png ’
143 t h i s . a p i S e r v i c e . getAPIIMG ( ‘ g e t i m a g e . php ? imagename=$ {imageName } ‘ ) . s u b s c r i b e ( ( data :
any ) => {
144 c o n s t imageUrl = URL. createObjectURL ( data ) ;
145 t h i s . imageUrl = t h i s . s a n i t i z e r . b y p a s s S e c u r i t y T r u s t U r l ( imageUrl ) ;
146 })
147 }
148 previewEncodeImage ( e v e n t : any ) : v o i d {
149 const f i l e = event . t a r g e t . f i l e s [ 0 ] ;
150 c o n s t r e a d e r = new F i l e R e a d e r ( ) ;
151 c o n s t image = new Image ( ) ;
152 c o n s t c a n v a s = t h i s . previewCanvas . n a t i v e E l e m e n t ;
153 const context = canvas . getContext ( ’ 2 d ’ ) ;
154 r e a d e r . o n l o a d e n d = ( ) => {
155 image . s r c = r e a d e r . r e s u l t a s s t r i n g ;
156 image . o n l o a d = ( ) => {
157 c a n v a s . width = image . width ;
158 c a n v a s . h e i g h t = image . h e i g h t ;
159 c o n t e x t . drawImage ( image , 0 , 0 ) ;
160 };
161 };
162
163 if ( file ) {
164 r e a d e r . readAsDataURL ( f i l e ) ;
165 }
166 }
167 encodeMessage ( ) {
168 const t e x t = t h i s . messageTextarea . nativeElement . value ;
169 const o r i g i n a l C o n t e x t = t h i s . originalCanvas . nativeElement . getContext ( ’2 d ’ ) ;
170 const nulledContext = t h i s . nulledCanvas . nativeElement . getContext ( ’2 d ’ ) ;
171 c o n s t messageContext = t h i s . messageCanvas . n a t i v e E l e m e n t . g e t C o n t e x t ( ’ 2 d ’ ) ;
172 c o n s t width = t h i s . o r i g i n a l C a n v a s . n a t i v e E l e m e n t . width ;
173 const height = t h i s . originalCanvas . nativeElement . height ;
174 i f ( ( t e x t . l e n g t h ∗ 8 ) > ( width ∗ h e i g h t ∗ 3 ) ) {
175 c o n s o l e . e r r o r ( ” Text t o o l o n g f o r c h o s e n image . . . . ” ) ;
176 return ;
177 }
178 t h i s . n u l l e d C a n v a s . n a t i v e E l e m e n t . width = width ;
179 t h i s . nulledCanvas . nativeElement . height = height ;
180
181 t h i s . messageCanvas . n a t i v e E l e m e n t . width = width ;
182 t h i s . messageCanvas . n a t i v e E l e m e n t . h e i g h t = h e i g h t ;
183 c o n s t o r i g i n a l = o r i g i n a l C o n t e x t . getImageData ( 0 , 0 , width , h e i g h t ) ;
184 l e t p i x e l = o r i g i n a l . data ;
185 f o r ( l e t i = 0 , n = p i x e l . l e n g t h ; i < n ; i += 4 ) {
186 f o r ( l e t o f f s e t = 0 ; o f f s e t < 3 ; o f f s e t ++) {
187 i f ( p i x e l [ i + o f f s e t ] % 2 !== 0 ) {
188 p i x e l [ i + o f f s e t ]−−;
189 }
190 }
191 }
192 n u l l e d C o n t e x t . putImageData ( o r i g i n a l , 0 , 0 ) ;
34
193
194 l e t binaryMessage = ” ” ;
195 f o r ( l e t i = 0 ; i < t e x t . l e n g t h ; i ++) {
196 l e t binaryCha r = t e x t [ i ] . charCodeAt ( 0 ) . t o S t r i n g ( 2 ) ;
197 w h i l e ( bi naryChar . l e n g t h < 8 ) {
198 bina ryChar = ”0” + bin aryChar ;
199 }
200
201 b i n a r y M e s s a g e += binar yChar ;
202 }
203 c o n s t message = n u l l e d C o n t e x t . getImageData ( 0 , 0 , width , h e i g h t ) ;
204 p i x e l = message . data ;
205 l e t counter = 0;
206 f o r ( l e t i = 0 , n = p i x e l . l e n g t h ; i < n ; i += 4 ) {
207 f o r ( l e t o f f s e t = 0 ; o f f s e t < 3 ; o f f s e t ++) {
208 i f ( counter < binaryMessage . length ) {
209 p i x e l [ i + o f f s e t ] += p a r s e I n t ( b i n a r y M e s s a g e [ c o u n t e r ] ) ;
210 c o u n t e r ++;
211 } else {
212 break ;
213 }
214 }
215 }
216 messageContext . putImageData ( message , 0 , 0 ) ;
217 t h i s . downloadEncodedImage ( )
218 }
219 downloadEncodedImage ( ) : v o i d {
220 c o n s t l i n k = document . c r e a t e E l e m e n t ( ’ a ’ ) ;
221 l i n k . download = ’ e n c o d e d i m a g e . png ’ ;
222 l i n k . h r e f = t h i s . messageCanvas . n a t i v e E l e m e n t . toDataURL ( ’ image /png ’ ) ;
223 link . click () ;
224 }
225
226 }
Decryption Process
The decryption process is essential for retrieving the hidden message from the stegano-
graphic image.
35
27 magic : any ;
28
29 constructor (
30 p r i v a t e f b : FormBuilder ,
31 private apiService : ApiService ,
32 p r i v a t e http : HttpClient ,
33 p r i v a t e s a n i t i z e r : DomSanitizer ,
34 p r i v a t e act Ro ute : A c t i v a t e d R o u t e
35 ) {
36 t h i s . i m a g e i d = t h i s . act Ro ute . s n a p s h o t . params . i d ;
37 t h i s . getImageData ( t h i s . i m a g e i d ) ;
38 }
39
40 ngOnInit ( ) : v o i d {
41 t h i s . u s e r I n f o = JSON . p a r s e ( l o c a l S t o r a g e . g e t I t e m ( ” c u r r e n t U s e r ” ) ) ;
42 t h i s . HFormGroup1 = t h i s . f b . group ( {
43 s u b j e c t : [ ” ” , [ V a l i d a t o r s . r e q u i r e d , V a l i d a t o r s . maxLength ( 3 0 ) ] ] ,
44 i m a g e d a t a : [ ” ” , [ V a l i d a t o r s . r e q u i r e d ] ] , // Remove maxLength v a l i d a t i o n f o r
image data
45 msg : [ ” ” ] ,
46 user id : [ this . userInfo . user . user id ] ,
47 }) ;
48 }
49 getImageData ( i d ) {
50 this . apiService
51 . getAPI ( ‘ g e t s t e g o i m a g e s b y i m a g e i d . php ? i m a g e i d=$ { i d } ‘ )
52 . s u b s c r i b e ( ( data ) => {
53 l e t path : any = data ;
54 t h i s . HFormGroup1 . pat ch Val ue ( {
55 s u b j e c t : path . s u b j e c t ,
56 }) ;
57 t h i s . imagePath = path . imagePath . r e p l a c e ( ” s t e g o u p l o a d s / ” , ” ” ) ;
58 t h i s . getImage ( t h i s . imagePath ) ;
59 }) ;
60 t h i s . a p i S e r v i c e . getAPI ( ‘ g e t s t e g o s . php ? i m a g e i d=$ { i d } ‘ ) . s u b s c r i b e ( ( data ) => {
61 l e t temp : any = data ;
62 t h i s . magic = temp . message ;
63 c o n s o l e . l o g ( t h i s . magic ) ;
64 t h i s . HFormGroup1 . pat ch Val ue ( {
65 msg : t h i s . magic ,
66 }) ;
67 }) ;
68 }
69
70 customAdapterPlugin ( e d i t o r ) {
71 e d i t o r . p l u g i n s . g e t ( ” F i l e R e p o s i t o r y ” ) . c r e a t e U p l o a d A d a p t e r = ( l o a d e r ) => {
72 r e t u r n new Adapter ( l o a d e r , e d i t o r . c o n f i g ) ;
73 };
74 }
75
76 onReady ( e d i t o r ) {
77 e d i t o r . p l u g i n s . g e t ( ” F i l e R e p o s i t o r y ” ) . c r e a t e U p l o a d A d a p t e r = ( l o a d e r ) => {
78 r e t u r n new Adapter ( l o a d e r , e d i t o r . c o n f i g ) ;
79 };
80 }
81
82 getImage ( f i l e n a m e ) {
83 l e t imageName = f i l e n a m e ;
84 this . apiService
85 . getAPIIMG ( ‘ g e t i m a g e . php ? imagename=$ {imageName } ‘ )
86 . s u b s c r i b e ( ( data : any ) => {
87 c o n s t imageUrl = URL. createObjectURL ( data ) ;
88 t h i s . imageUrl = t h i s . s a n i t i z e r . b y p a s s S e c u r i t y T r u s t U r l ( imageUrl ) ;
89 }) ;
90 t h i s . a p i S e r v i c e . getAPIIMG ( ‘ g e t i m a g e . php ? imagename=$ {imageName } ‘ ) . s u b s c r i b e (
91 ( data : Blob ) => {
92 t h i s . d e c r y p t I m a g e ( data )
93 . then ( ( decryptedMsg ) => {
94 c o n s o l e . l o g ( ” Decrypted Message : ” , decryptedMsg ) ;
95 t h i s . decryptedMsg = decryptedMsg ;
96 })
97 . c a t c h ( ( e r r o r ) => {
98 c o n s o l e . e r r o r ( ” E r r o r d e c r y p t i n g image : ” , e r r o r ) ;
36
99 }) ;
100 },
101 ( e r r o r ) => {
102 c o n s o l e . e r r o r ( ” E r r o r f e t c h i n g image : ” , e r r o r ) ;
103 }
104 );
105 }
106 d e c r y p t I m a g e ( encryptedImageData : Blob ) : Promise<s t r i n g > {
107 r e t u r n new Promise ( ( r e s o l v e , r e j e c t ) => {
108 c o n s t img = new Image ( ) ;
109 img . o n l o a d = ( ) => {
110 c o n s t c a n v a s = document . c r e a t e E l e m e n t ( ” c a n v a s ” ) ;
111 const ctx = canvas . getContext (”2d ”) ;
112 c a n v a s . width = img . width ;
113 c a n v a s . h e i g h t = img . h e i g h t ;
114 c t x . drawImage ( img , 0 , 0 ) ;
115 c o n s t imageData = c t x . getImageData ( 0 , 0 , c a n v a s . width , c a n v a s . h e i g h t ) ;
116 c o n s t data = imageData . data ;
117
118 l e t binaryMsg = ” ” ;
119 f o r ( l e t i = 0 ; i < data . l e n g t h ; i += 4 ) {
120 binaryMsg += ( data [ i ] & 1 ) . t o S t r i n g ( ) ; // Red c h a n n e l
121 binaryMsg += ( data [ i + 1 ] & 1 ) . t o S t r i n g ( ) ; // Green c h a n n e l
122 binaryMsg += ( data [ i + 2 ] & 1 ) . t o S t r i n g ( ) ; // Blue c h a n n e l
123 }
124
125 c o n s o l e . l o g ( ” E x t r a c t e d Binary Message : ” , binaryMsg ) ; // Debug
126
127 l e t decryptedMsg = ” ” ;
128 f o r ( l e t i = 0 ; i < binaryMsg . l e n g t h ; i += 8 ) {
129 c o n s t b y t e = binaryMsg . s u b s t r ( i , 8 ) ;
130 i f ( b y t e === ” 0 0 0 0 0 0 0 0 ” ) {
131 b r e a k ; // Stop a t t h e t e r m i n a t i o n c h a r a c t e r
132 }
133 c o n s t charCode = p a r s e I n t ( byte , 2 ) ;
134 decryptedMsg += S t r i n g . fromCharCode ( charCode ) ;
135 }
136
137 c o n s o l e . l o g ( ” Decrypted Message : ” , decryptedMsg ) ; // Debug
138
139 r e s o l v e ( decryptedMsg ) ;
140 };
141
142 img . o n e r r o r = ( ) => r e j e c t ( ” E r r o r l o a d i n g image ” ) ;
143
144 c o n s t r e a d e r = new F i l e R e a d e r ( ) ;
145 r e a d e r . o n l o a d = ( ) => {
146 img . s r c = r e a d e r . r e s u l t a s s t r i n g ; // S e t t h e image s o u r c e from t h e F i l e R e a d e r
result
147 };
148 r e a d e r . o n e r r o r = ( ) => r e j e c t ( ” E r r o r r e a d i n g image data ” ) ;
149 r e a d e r . readAsDataURL ( encryptedImageData ) ; // Read t h e b l o b a s data URL
150 }) ;
151 }
152 }
37