You are on page 1of 13

electronics

Article
Chaos-Based Cryptography: Text Encryption Using
Image Algorithms
Marcin Lawnik 1, * , Lazaros Moysis 2,3 and Christos Volos 2

1 Department of Mathematics Applications and Methods for Artificial Intelligence, Faculty of Applied
Mathematics, Silesian University of Technology, Kaszubska 23, 44-100 Gliwice, Poland
2 Laboratory of Nonlinear Systems—Circuits & Complexity, Physics Department, Aristotle University of
Thessaloniki, 54124 Thessaloniki, Greece
3 Department of Mechanical Engineering, University of Western Macedonia, 50150 Kozani, Greece
* Correspondence: marcin.lawnik@polsl.pl

Abstract: Currently, chaotic cryptography is mainly concentrated on image encryption. Once-


popular stream-encryption algorithms, e.g., textual data, are now rarely considered. This article
studies how chaotic image-encryption algorithms can be used to encrypt text. The proposed approach
to this problem consists of two stages: in the first stage, the text message is intended for encryption
into an image; in the second step, the selected image-encryption algorithm is used. An example
illustrates the efficiency of this method. In addition, the article presents measures used in image-
encryption analysis that confirm the security of the obtained cipher-image, such as entropy (value
close to 8), correlation of adjacent pixels (values close to 0), or measures related to differential
cryptanalysis. The proposed method offers a new look at text encryption using chaos, by applying
image-encryption algorithms already known from the literature.

Keywords: chaos; cryptography; image encryption; text encryption; compression




Citation: Lawnik, M.; Moysis, L.;
Volos, C. Chaos-Based Cryptography: 1. Introduction
Text Encryption Using Image
Chaos theory is one of the great discoveries of the 20th century. Currently, chaos and its
Algorithms. Electronics 2022, 11, 3156.
applications are an important aspect in many fields of science [1]. The effect of chaos can be
https://doi.org/10.3390/
undesirable, such as oscillations in chemical reactors, or be used to achieve positive results.
electronics11193156
A wide group of chaos applications includes cryptography based on chaotic dynamical
Academic Editor: Flavio Canavero systems. Chaotic cryptography uses dynamic systems with very complex behavior. On the
Received: 1 September 2022
one hand, the obtained values from such systems appear to be random, while the way they
Accepted: 27 September 2022
are obtained is completely deterministic. For these reasons, chaotic mappings have been
Published: 1 October 2022
used in, among other areas, data encryption [2–4].
The beginnings of cryptography based on the chaos theory date to the 1990s. It
Publisher’s Note: MDPI stays neutral
was then that the first stream ciphers were presented, which were used mainly for text
with regard to jurisdictional claims in
encryption. One of the first publications that dealt with this subject was the publication
published maps and institutional affil-
by M.S. Baptista [5]. In that article, an algorithm that uses the logistic map to encrypt
iations.
text messages was presented. From then on, further publications dealing with this subject
appeared in the literature. Many of the proposed ciphers were quickly broken, thus
showing that, from a practical point of view, using chaos to encrypt text is not an effective
Copyright: © 2022 by the authors.
solution [6]. However, chaotic cryptography deals not only with stream ciphers, but also
Licensee MDPI, Basel, Switzerland. asymmetric ciphers [7] and their successors [8], hash functions [9,10], S-boxes [11,12],
This article is an open access article pseudo-random numbers generators (PRNGs) [13,14] or image-encryption algorithms [13].
distributed under the terms and Currently, the last group of mentioned algorithms is of particular interest to scientists.
conditions of the Creative Commons Chaotic image encryption is obtained using a selected chaotic dynamic system to transform
Attribution (CC BY) license (https:// the image pixels appropriately. Such algorithms are considered to be safe and applicable in
creativecommons.org/licenses/by/ practice. In the context outlined, a question can be asked: is it possible to use the developed
4.0/). techniques and methods of image encryption for text encryption? An affirmative answer to

Electronics 2022, 11, 3156. https://doi.org/10.3390/electronics11193156 https://www.mdpi.com/journal/electronics


Electronics 2022, 11, 3156 2 of 13

this question would open up a whole new perspective on the use of chaotic mappings in
cryptography. This article will answer that question and discuss how it will be possible to
use image-encryption algorithms to encrypt text.
The main contribution of this article is showing the method of text encryption based
on existing image-encryption algorithms. For this purpose, the method of converting text
into an image is shown. Then, one of the known image-encryption algorithms is applied.
To the best of the authors’ knowledge, such a method of text encryption has not been
considered in the professional literature so far. As a result, this article will not propose a
new cipher, as is the case with most chaos-based encryption works. This article aims to
illustrate how the image-encryption algorithms known from the literature can be used to
encrypt text. In addition, the presented method of text encryption sheds new light on the
subject of image encryption using chaos theory, which is very popular among researchers.
This article is divided into several parts. In the first of them—the Introduction—the
article’s topic is outlined. The next part discusses text-encryption algorithms and image-
encryption algorithms. In the third part, the text-to-image transformation method and the
use of chaotic encryption algorithms are presented. The next part presents an example of
the proposed encryption technique and the analysis of the obtained cipher-image. The last
part is the conclusions.

2. Related Work
The review of similar solutions will be divided into two parts. The first part presents
algorithms that use chaos to encrypt text. The second group consists of image-encryption
algorithms using chaotic mappings.

2.1. Chaotic Text Encryption


The early works on chaotic cryptography concerned the encryption of various multi-
media files, including text, e.g., [5]. Over the years, more articles that used chaotic mappings
to encrypt textual data appeared, e.g., [15,16]. However, for some time now, algorithms for
encrypting text using chaotic mappings have ceased to be of interest to scientists.
For this reason, there are currently few articles in this field. However, this does not
mean that such works are not published at all. One such work is [17], where the authors
present an encryption framework for various types of multimedia media, including text.
Text encryption also applies in the publication [18,19], where the ciphertext is obtained by
appropriate permutation and substitution. A similar encryption process was used in [20,21]
where a new encryption algorithm was presented based on a chaotic dynamic system, a
pseudo-random number generator, and an XOR operation. The XOR operation was also
used in [22] to encrypt text with some pseudo-random string. In [23], the authors presented
a text-encryption algorithm that, in addition to a chaotic arrangement, also used DNA
sequences to encrypt text messages. In turn, ref. [24] uses matrix calculus and chaotic
mapping to encrypt text. In [25], the authors used a fractional chaotic system to encrypt
various types of multimedia, including text. In turn, ref. [26] shows a text-encryption
algorithm using Bi-Arnold cat map and modulus operation.
Summarizing the conducted review of the literature on text encryption through chaotic
mappings, one must point out the disadvantages of this approach. First, some of the above
works turned out to be unsafe, as demonstrated by the cryptanalysis techniques appearing
in the literature [6]. On the other hand, some of the work on encrypting text using chaos
has a fairly simple structure (e.g., XOR substitution, e.g., [22]), which may also lead to
breaking such ciphers in the future. These and other reasons have drawn the attention of
researchers to the use of chaos to encrypt images.

2.2. Chaotic Image Encryption


Contrary to text encryption, the interest among researchers in this way of encrypting
images still is very high. To confirm this thesis, we can cite, for example, the number of
articles from the Scopus database which refer to the keywords “chaos image encryption”—it
Electronics 2022, 11, 3156 3 of 13

is above 2500. In this part of the article, only selected recent works on image encryption
will be described.
Chaotic image-encryption methods use chaotic mappings to transform image pixels
properly. Roughly speaking, these algorithms usually rely on permuting and adding
pseudo-random values to a pixel through, for example, an XOR function. Of course, these
operations differ from one work to another. The general scheme of image encryption and
decryption is shown in Figure 1. In [27] a new dynamic system—M-map—was presented,
and a new encryption algorithm that uses, among others, an S-box for substitution. In [28],
based on the combination of tent and logistic maps, an image-encryption algorithm was
presented also using a generated S-box and XOR operation. In turn, ref. [29] proposes
an image-encryption algorithm using logistic mapping and Arnold’s cat map. In this
algorithm, a new method of pixel permutation and an XOR operation with a sequence of
pseudo-random values is shown. In [30], a new image-encryption algorithm was developed
using discrete fractional wavelet transform (DFRWT) and quantum logistic mapping. It is
also based on the operation of permuting pixels and adding pseudo-random values through
the XOR operation. In [31], the authors present an image-encryption algorithm using a
Rubik’s cube and the prime factorization process. In turn, [32] presents an asymmetric
image-encryption algorithm based on the improved Lorentz system. Yet another approach
to image encryption is presented in [33], where hyperchaotic maps and DNA sequences
were used to obtain a cipher-image in the form of a 3D cube image. On the other hand,
ref. [34] shows an image-encryption algorithm that, apart from the chaotic system, also
uses elliptic curves.

(a) (b)

Figure 1. Encryption and decryption process of an image. (a) Image-encryption scheme. (b) Image
decryption scheme.

Analyzing the above works, it can be seen that this field of cryptography is develop-
ing very dynamically. Therefore, it makes sense to try to use these different encryption
techniques not only for images but also for other types of data, such as text.

3. The Method
Using image-encryption algorithms to encrypt textual data is conceptually quite
simple. The steps of this procedure are as follows:
1. Convert a text message into an image
2. Apply the selected image-encryption algorithm to the received image
The first step above is to convert text into an image. This allows text to be input into
the encryption algorithm. In the second step, the received image is encrypted according to
the selected image-encryption algorithm.
The following subsections describe the above steps in detail.
Electronics 2022, 11, 3156 4 of 13

3.1. Text-to-Image Conversion


The authors in [35] present a simple algorithm for changing the message format from
text to image. This procedure was not related to one of the encryption steps. It was mainly
intended to save disk space occupied by data files. So using it in the context of encryption
is a new idea. This algorithm requires that the text message must be encoded with UTF-8.
A simplified version of this algorithm is presented below to better illustrate the procedure:
1. The text message is read into the buffer.
2. Text characters ti are converted to numbers in the range 0–65535 (UTF-8 encoding).
3. Each of the values ti is stored in the positional system with base 256 according to
the equation:
ti = ai · 256 + bi , (1)
where ai and bi are the coefficients of ti in the positional numeral system with base
256. Values ai and bi are stored in one-dimensional table T.
4. The image size (height and width) is calculated using the formula
&r '
length T
size = , (2)
3

where d·e stands for the ceiling function, and length T is the length of the table T.
5. If
length T < 3 · size2 , (3)
then T is first padded with the value 3 (“End-of-Text” character) and then with random
values from set {0, 1, · · · , 255} so that its length is exactly 3 · size2 .
6. T is saved as a three-dimensional array TPsize×size×3 , i.e., every three consecutive
elements of the array T are stored as an element of a matrix with dimensions of
size × size.
7. Array TPsize×size×3 is treated as an array of pixels and saved as a png file.
Figure 2 shows a general scheme of the proposed procedure for converting text into
an image.

Figure 2. Text to image conversion scheme.

Any text message in UTF-8 format can be converted with this procedure. This is
because Formula (1) reduces the characters from this encoding to the pixel value range,
i.e., the range 0–255. For the next step, which is image encryption, the proposed png image
file extension is the best choice. This is due to the fact that this graphic file format has an
RGB structure, which allows the use of a very wide range of encryption algorithms known
from the literature. Moreover, thanks to the compression algorithms built into this format,
simply storing the text in the form of a png file usually saves disk space. However, when
choosing a format other than png, graphic formats with built-in lossy compression (such
as jpg) must be avoided. In this case, it will be impossible to recover the plaintext, as the
compression algorithm will modify its content.
The above algorithm allows the conversion of a text message into exactly one image.
There may be times when the resulting image is too large in dimensions. In this case, the
text can be divided into several parts, and the image conversion algorithm can be applied
to each of them separately.
Electronics 2022, 11, 3156 5 of 13

The proposed procedure of text-to-image conversion is fully reversible. In addition,


the added random values in step 5 of the text-to-image algorithm are ignored in the
image-to-text conversion. They only play the role of padding to achieve the fixed file size.
To receive a text message from a png file, follow these steps:
1. Successive image pixels are loaded in the buffer until the value of one of the compo-
nents is equal to 3.
2. Loaded RGB pixel components values are stored in one- dimensional table T.
3. Every two values from T are retrieved and marked as ai and bi . These values are the
coefficients of the number ti written in the number system with base 256, i.e.,

ti = ai · 256 + bi . (4)

4. The ti values are stored as consecutive characters in UTF-8 encoding in the text
message.
Figure 3 shows a general scheme of the proposed procedure for converting images
into text.

Figure 3. Image to text conversion scheme.

The above method of decoding an image into text is correct and allows the conversion
of any RGB image to text in UTF-8 encoding. This is because the pixel range, i.e., 0–255, is
extended to the UTF-8 encoding range, i.e., the value 0–65,535, by the Formula (4).

3.2. Image-Encryption Algorithm


This step requires selecting an image-encryption algorithm known from the literature.
It is not important which algorithm is chosen because the text is in the form of an image and
can be encrypted with any algorithm. However, it should be noted that the algorithm has
no image size limitations. If they are, the text should be divided into enough parts so that
the size of each of the obtained images does not exceed the assumed sizes in the algorithm.

4. Examples
To show how the whole procedure works, selecting the appropriate text message and
a specific image-encryption algorithm is necessary. Obviously, the converted text message
will not resemble any commonly used test images such as Lena, Baboon, or Pepper. If so,
it will be impossible to compare the obtained results with other works related to image
encryption. It is also evident that changing the algorithm to another one will change
the obtained results. However, if the algorithm is safe, obtained results will be close to
optimal values. Thus, the analysis of a specific example may seem redundant. However,
it is worth showing that the obtained values of the analysis measures are close to the
optimal one. Therefore, the whole procedure makes sense for the selected text message and
image-encryption algorithm.
It is also worth mentioning that the structure of the text is different from the structure
of the image. In an image, neighboring pixels are usually correlated with each other.
However, in the case of text, such a correlation should be smaller.
To present the operation of the procedure in use, the algorithm from [27] has been
selected. Roughly, its operation uses the substitution with the generated S-box, as well
as the permutation of pixels by saving them in the appropriate place in the cipher-image.
Its advantage is the fact that it does not have any imposed maximum image sizes and is
dedicated to images in the png format. It uses two keys: the value of the initial condition x
Electronics 2022, 11, 3156 6 of 13

and the value of the p parameter. For further processing of this algorithm, the following
values were established: x = 0.123 and p = 0.352.
Three different text files with the following content were selected as the message to
be encrypted:

Test File 1: Lorem Ipsum text 200 words long (ASCII encoding);
Test File 2: Hamlet by Shakespeare in English (ASCII encoding);
Test File 3: Hamlet by Shakespeare in Polish (UTF-8 encoding).

The first two files are ASCII encoded (characters of which are included in UTF-8 encoding),
while the third file is UTF-8 encoding.
Figure 4a shows the generated 200-word Lorem Ipsum text. The test files converted
into an image are shown in Figures 4b, 5a and 6a. It is worth noting that the size of the text
message in the form of the text file and the image file differ in size. For example, the image
of Test File 3 takes about 20% less disk space than the text file. Detailed data of this issue
are presented in Table 1. This observation is described in more detail in [35].
Table 1 also provides information on the dimensions of the resulting image files. In
the case of Test File 1, it is only 31 × 31 pixels. Test Files 2 and 3 are 361 × 361 and 387 × 387
pixels, respectively.

Table 1. Disk space comparison of the original text file with its image version and the encrypted
image.

Text File Size Image File Size Image File Encrypted File
[in B] [in B] Dimensions Size [in B]
Test File 1 1433 1224 31 × 31 2982
Test File 2 200,203 147,196 361 × 361 391,831
Test File 3 252,640 196,408 387 × 387 450,132

In turn, Figures 4c, 5b and 6b represent the encrypted images. It is worth emphasizing
that the size of the encrypted file is significantly larger than the text file and the image file.
This is due to the fact that the pixel distribution in the encrypted image is uniform, and
thus the compression algorithms used in the png format will not be as efficient as in the
case of a non-flat distributed graphic file. This is due to the fact that the image cipher has a
random form with no pixel dependencies.

(a) (b) (c)


Figure 4. Test File 1 text message, transformed message into a png image and its cipher-image.
(a) Lorem Ipsum text. (b) Text message in image form. (c) Encrypted image.
Electronics 2022, 11, 3156 7 of 13

(a) (b)
Figure 5. Test File 2 text message as image png and its cipher-image. (a) Text message in image form.
(b) Encrypted image.

(a) (b)
Figure 6. Test File 3 text message as image png and its cipher-image. (a) Text message in image form.
(b) Encrypted image.

To assess whether the encryption algorithm meets specific security requirements, cer-
tain numerical values of encrypted messages are shown, which illustrate how the algorithm
copes with various cryptoanalysis techniques. For the proposed approach, measures related
to image cryptoanalysis should be used. Such measures include, among others, entropy,
correlation of adjacent pixels, differential attack analysis or pixel inconsistency analysis. In
the following subsections, these measures are presented together with their discussion for
the analyzed example.

4.1. Histograms
A simple criterion for assessing the security of an encrypted image is the assessment
of histograms for RGB components. Such histograms should be uniform, which means that
each of the possible pixel values has appeared almost the same number of times. In the
case of the analyzed test files, the histograms of both the text converted into an image and
its encrypted form are presented in Figures 7–9. The top row of these Figures clearly shows
that there are both dominant values in the RGB components of pixels and those that are
not present in the image at all. However, in the case of the encrypted image, the obtained
histogram is flat, i.e., each possible pixel value appeared almost exactly the same number
Electronics 2022, 11, 3156 8 of 13

of times. Such a situation is, of course, necessary from the point of view of the security of
the encrypted message.

Figure 7. Histogram of the R, G, and B components of the pixels of the image version of Test File 1
(top row) and its cipher-image (bottom row).

Figure 8. Histogram of the R, G, and B components of the pixels of the image version of Test File 2
(top row) and its cipher-image (bottom row).

Figure 9. Histogram of the R, G, and B components of the pixels of the image version of Test File 3
(top row) and its cipher-image (bottom row).

4.2. Entropy
Entropy is a measure of information in the source. It can be viewed as a measure of
randomness. Its value can be calculated from the formula
Electronics 2022, 11, 3156 9 of 13

N −1
H (m) = − ∑ p(mi ) log2 p(mi ), (5)
i =0

where N is the number of all possible characters in the source alphabet, mi is the source char-
acter, and p(mi ) is the probability of mi . In the case of text in UTF-8 encoding, N = 65,536,
and in the case of an image saved in the format png N = 256. Entropy is maximal when
p(mi ) = N1 . For text in UTF-8 encoding, the maximum entropy value is Hmax = 16, while
for the image png it is Hmax = 8. In cryptography, it is required that the entropy of the
latent (encrypted) source be as close as possible to the maximum entropy.
In the case of the analyzed test files, the entropy values are presented in Table 2. The
entropy of the test files is, respectively, equal to 4.2068, 4.4600 and 5.0650 (with 16 as the
maximum value), an average value of 3.09, 3.23 and 3.72 for the image png version of the
test files and finally an average value of 7.80, 7.99 and 7.99 for the encrypted image (with
8 as the maximum value in both cases) for the test files. These values confirm that the
proposed text-encryption procedure meets the requirements for this type of algorithm.

Table 2. Entropy comparison of the original text file with its image version and the encrypted image.

Text File Image File Encrypted File


Red Green Blue Red Green Blue
Test File 1 4.2068 3.0823 3.0984 3.0998 7.8131 7.7826 7.7949
Test File 2 4.4600 3.2316 3.2382 3.2276 7.9985 7.9984 7.9985
Test File 3 5.0650 3.7215 3.7209 3.7205 7.9986 7.9988 7.9987

4.3. Local Entropy


As a measure, entropy is computed over the complete information signal. This can
be complemented by a secondary measure, that of local entropy [36–39]. Local entropy is
computed as the average entropy of a collection of random, non-overlapping sub-blocks of
an image. This measure can be more representative, as it measures the local distribution of
information along the source signal.
Here, a set of 30 randomly chosen non-overlapping blocks is considered. Each block
has size of 44 × 44, so 442 = 1936 pixels. The results are displayed in Table 3, for all three
channels of the English (Test File 2) and Polish (Test File 3) source text images. The “Lorem
Ipsum” text (Test File 1) is not considered here, due to its short length. In both cases, the
encrypted images showcase a high value of local entropy, at around 7.9, which is close to
the optimal value, similar to the entropy measure. On the other hand, the plaintext images
have low values of local entropy, indicating that the sub-blocks of the transformed image
still “carry” information about the plaintext source.

Table 3. Local entropy for plaintext and encrypted image versions of the text source.

Image File Encrypted File


Red Green Blue Red Green Blue
Test File 2 3.2003 3.2072 3.1948 7.9045 7.9036 7.9040
Test File 3 3.6858 3.6808 3.6858 7.9045 7.9049 7.9033

4.4. Correlations of Adjacent Pixels


The linear correlation shows whether there is a relationship between successive pixels
in the vertical, horizontal, and diagonal arrangement. Its value can be calculated from
Pearson’s linear correlation coefficient, which is given by the formula

Cov( x, y)
r= , (6)
σx · σy
Electronics 2022, 11, 3156 10 of 13

where
v
u1 N
q u
σx = Var( x ) = t ∑( xi − E( x ))2 , (7)
N i =i
v
u1 N
q u
σy = Var(y) = t ∑(yi − E(y))2 , (8)
N i =i
N
1
Cov( x, y) =
N ∑(xi − E(x))(yi − E(y)), (9)
i =i
N N
1 1
E( x ) =
N ∑ xi and E(y) = N ∑ yi . (10)
i =1 i =1

x and y are consecutive image pixels with dimension W × H. The correlation coefficient
satisfies the r ∈ [−1, 1] relationship, and |r | values close to 1 mean that the neighboring
pixels are correlated with each other, while the r value close to 0 means that such a relation-
ship between adjacent pixels does not exist. From the point of view of cryptography, the
second case is the desired variant.
In the case of the analyzed test files, the correlation values are presented in Table 4. For
the test files in the image form, the correlation value in each channel is about |0.84|, |0.72|,
respectively, for the test files. In turn, for the encrypted image it is about |0.02|, |0.002| and
|0.002|, respectively, for the test files. These values show that the text saved as an image is
quite strongly correlated, while its encrypted version has a completely blurred relationship
between adjacent pixels.

Table 4. Correlations of adjacent pixels of the image version of the text and the encrypted image.

Image File Encrypted File


Red Green Blue Red Green Blue
Vertical −0.8225 −0.8601 −0.8586 −0.0111 0.0068 −0.0370
Test file 1 Horizontal −0.8249 −0.8559 −0.8547 −0.0212 −0.0209 0.0400
Diagonal 0.8127 0.8511 0.8599 −0.0075 −0.0073 0.0004
Vertical −0.7275 −0.7299 −0.7268 0.0017 −0.0006 0.0030
Test file 2 Horizontal −0.7275 −0.7299 −0.7268 0.0042 0.0014 0.0011
Diagonal 0.7305 0.7305 0.7274 −0.0018 0.0005 0.0050
Vertical −0.7229 −0.7235 −0.7214 −0.0029 −0.0014 −0.0027
Test file 3 Horizontal −0.7274 −0.7277 −0.7256 −0.0009 0.0023 0.0049
Diagonal 0.7227 0.7239 0.7205 −0.0005 −0.0021 0.0007

4.5. Differential Attack Analysis


Differential cryptoanalysis is one of the basic techniques for assessing the security of
a given encryption algorithm. It involves examining the differences between ciphertexts
that are obtained for plaintext that differ in some specific way (usually a randomly selected
value) using the same keys. In the context of the proposed method, it will allow the checking
of whether the text message treated as an image can be securely encrypted with the selected
algorithm. Typically, differential cryptanalysis is based on two measures—NPCR (Number
of Pixel of Change Rate) and UACI (Unified Average Changing Intensity). To receive them,
two cipher-images E1 and E2 are needed. Those cipher-images are created from encryption
for two plaintexts P1 and P2 , which differ by one random pixel value using the same keys.
The NPCR value is calculated from the formula:
1
NPCR =
W×H ∑ D(i, j) × 100%, (11)
i,j
Electronics 2022, 11, 3156 11 of 13

where (
0 if E1(i,j) = E2(i,j)
D (i, j) = , (12)
1 if E1(i,j) 6= E2(i,j)

W × H stands for image dimension and E∗(i,j) stands for pixel in (i, j) coordinates of image
E∗ . The ideal value for NPCR is 100%.
The U ACI value is calculated from the formula:
" #
1 | E1(i,j) − E2(i,j) |
W×H ∑
U ACI = × 100%, (13)
i,j
255

where W × H stands for image dimension and E∗(i,j) stands for pixel in (i, j) coordinates of
image E∗ . The ideal value for U ACI is 33%.
In the case of the analyzed test files, the values for NPCR and UACI measures are
presented in Table 5. The obtained NPCR values are average equal to 99.40%, 99.21% and
99.20%, respectively, for test files. In turn, the UACI values are average equal to 33.37%,
36.38% and 33.41%, respectively, for the test files. This means that in the context of the
analyzed algorithm, the obtained cipher-image does not allow for the effective use of
differential cryptoanalysis methods.

Table 5. NPCR and UACI values of the encrypted image.

Encrypted File
Red Green Blue
NPCR 99.47% 99.47% 99.37%
Test File 1
UACI 33.68% 32.90% 33.55%
NPCR 99.22% 99.22% 99.18%
Test File 2
UACI 36.38% 36.46% 36.30%
NPCR 99.19% 99.21% 99.19%
Test File 3
UACI 33.43% 33.38% 33.42%

4.6. Pixel Inconsistency Analysis


Another important feature of secure encryption is the occurrence of the avalanche
effect, i.e., the occurrence of a significant change in the encrypted image when the input
image or key has been slightly changed. In practice, MSE (Mean Square Error) can be used
to investigate this phenomenon, which is expressed by the formula

1  2
MSE =
W×H ∑ E1(i,j) − E2(i,j) , (14)
i,j

where W × H stands for image dimension and E∗(i,j) stands for pixel in (i, j) coordinates of
image E∗ . The MSE value should be high for any robust encryption algorithms. In the case
of the analyzed case, E1 means the cipher-image, while E2 is the cipher-image obtained for
an image that differs by one random pixel value.
In the case of the analyzed test files, the value for MSE measure is presented in Table 6.
The values of this measure are average equal to 3673, 4062 and 3629, respectively, for the
test files. This means that the compared images differ significantly.

Table 6. MSE values of the image version of the text and the encrypted image.

Encrypted File
Vertical Horizontal Diagonal
Test File 1 3761.7852 3577.8803 3683.9597
Test File 2 4057.6780 4081.2078 4050.6819
Test File 3 3630.0174 3627.9807 3630.2282
Electronics 2022, 11, 3156 12 of 13

5. Conclusions
The article presents how to use image-encryption algorithms known from professional
literature to encrypt text. The idea behind this is in two steps. In the first one, the text is
converted into an RGB image; in the second step, the selected image-encryption algorithm
is used. The proposed procedure is presented on an example that confirms that such a
text-encryption method is correct and allows for the safe hiding of a text message. This is
confirmed by the calculated measures of entropy, correlation of adjacent pixels, NPCR, and
UACI, which are related to differential cryptoanalysis, and MSE, which is related to pixel
inconsistency analysis. The proposed approach opens up a completely new field related to
chaotic cryptography, which currently focuses mainly on image encryption.
Moreover, the conversion of a text message into an image can be used directly as a step
to develop new text-encryption algorithms with an intermediate image-encryption step.
Future work on this subject may concern topics related to, e.g., visual cryptography [40,41].

Author Contributions: Conceptualization, M.L.; methodology, M.L. and L.M.; formal analysis, M.L.
and L.M.; writing—original draft preparation, M.L. and L.M.; writing—review and editing, M.L. and
L.M.; supervision, C.V.; All authors have read and agreed to the published version of the manuscript.
Funding: This research received no external funding.
Acknowledgments: The authors are thankful to the anonymous reviewers for their insightful remarks.
Conflicts of Interest: The authors declare no conflict of interest.

References
1. Strogatz, S. Nonlinear Dynamics and Chaos: With Applications to Physics, Biology, Chemistry, and Engineering; Westview Press: Boulder,
CO, USA, 2015.
2. Kocarev, L.; Lian, S. (Eds.) Chaos-Based Cryptography—Theory, Algorithms and Applications. In Studies in Computational
Intelligence; Springer: Berlin/Heidelberg, Germany, 2011; Volume 354. [CrossRef]
3. Grassi, G. Chaos in the Real World: Recent Applications to Communications, Computing, Distributed Sensing, Robotic Motion,
Bio-Impedance Modelling and Encryption Systems. Symmetry 2021, 13, 2151. [CrossRef]
4. Moysis, L.; Butusov, D.N.; Tutueva, A.; Ostrovskii, V.; Kafetzis, I.; Volos, C. Introducing Chaos and Chaos Based Encryption
Applications to University Students-Case Report of a Seminar. In Proceedings of the 2022 11th International Conference on
Modern Circuits and Systems Technologies (MOCAST), Bremen, Germany, 8–10 June 2022; pp. 1–6.
5. Baptista, M. Cryptography with Chaos. Phys. Lett. A 1998, 240, 50–54. [CrossRef]
6. Li, S.; Chen, G.; Wong, K.W.; Mou, X.; Cai, Y. Baptista-type chaotic cryptosystems: Problems and countermeasures. Phys. Lett. A
2004, 332, 368–375. [CrossRef]
7. Kocarev, L.; Tasev, Z. Public-key encryption based on Chebyshev maps. In Proceedings of the 2003 International Symposium on
Circuits and Systems ( ISCAS’03), Bangkok, Thailand, 25–28 May 2003; Volume 3, p. III. [CrossRef]
8. Lawnik, M.; Kapczyński, A. The application of modified Chebyshev polynomials in asymmetric cryptography. Comput. Sci. 2019,
20, 289–303. [CrossRef]
9. Li, Y.; Li, X. Chaotic hash function based on circular shifts with variable parameters. Chaos Solitons Fractals 2016, 91, 639–648.
[CrossRef]
10. Abdelfatah, R.I.; Baka, E.A.; Nasr, M.E. Keyed Parallel Hash Algorithm Based on Multiple Chaotic Maps (KPHA-MCM). IEEE
Access 2021, 9, 130399–130409. [CrossRef]
11. Khan, M.A.; Ali, A.; Jeoti, V.; Manzoor, S. A Chaos-Based Substitution Box (S-Box) Design with Improved Differential Approxi-
mation Probability (DP). Iran. J. Sci. Technol. Trans. Electr. Eng. 2018, 42, 219–238. [CrossRef]
12. Dimitrov, M.M. On the Design of Chaos-Based S-Boxes. IEEE Access 2020, 8, 117173–117181. [CrossRef]
13. Zia, U.; McCartney, M.; Scotney, B.; Martinez, J.; Sajjad, A. A novel pseudo-random number generator for IoT based on a coupled
map lattice system using the generalised symmetric map. SN Appl. Sci. 2022, 4, 48. [CrossRef]
14. Haliuk, S.; Krulikovskyi, O.; Vovchuk, D.; Corinto, F. Memristive Structure-Based Chaotic System for PRNG. Symmetry 2022,
14, 68. [CrossRef]
15. Yang, D.; Liao, X.; Wang, Y.; Yang, H.; Wei, P. A novel chaotic block cryptosystem based on iterating map with output-feedback.
Chaos Solitons Fractals 2009, 41, 505–510. [CrossRef]
16. Wang, X.Y.; Yu, Q. A block encryption algorithm based on dynamic sequences of multiple chaotic systems. Commun. Nonlinear
Sci. Numer. Simul. 2009, 14, 574–581. [CrossRef]
17. Yasser, I.; Mohamed, M.A.; Samra, A.S.; Khalifa, F. A Chaotic-Based Encryption/Decryption Framework for Secure Multimedia
Communications. Entropy 2020, 22, 1253. [CrossRef] [PubMed]
Electronics 2022, 11, 3156 13 of 13

18. Sheela, S.J.; Suresh, K.V.; Tandur, D. Secured text communication using chaotic maps. In Proceedings of the 2017 International
Conference on Algorithms, Methodology, Models and Applications in Emerging Technologies (ICAMMAET), Chennai, India,
16–18 February 2017; pp. 1–6. [CrossRef]
19. Menon, U.; Menon, A.R.; Hudlikar, A. A Novel Chaotic System for Text Encryption Optimized with Genetic Algorithm. Int. J.
Adv. Comput. Sci. Appl. 2020, 11, 34–40. [CrossRef]
20. Irsan, M.Y.T.; Antoro, S.C. Text Encryption Algorithm based on Chaotic Map. J. Phys. Conf. Ser. 2019, 1341, 062023. [CrossRef]
21. Charalampidis, N.; Volos, C.; Moysis, L.; Tutueva, A.V.; Butusov, D.; Stouboulos, I. Text Encryption Based on a Novel One Dimensional
Piecewise Chaotic Map. In Proceedings of the 2022 Conference of Russian Young Researchers in Electrical and Electronic Engineering
(ElConRus), St. Petersburg, Russia, 25–28 January 2022; pp. 263–268. [CrossRef]
22. Qasim, H.A. Text Encryption Method Using multi Hyper-chaotic systems. Al-Qadisiyah J. Pure Sci. 2021, 23, 1–8.
23. OleiwiTuama, S.; Kadum, S.A.; Hussein, Z. Text Encryption Approach Using DNA Computation and Hyperchaotic System. In
Proceedings of the 2021 2nd Information Technology To Enhance e-learning and Other Application (IT-ELA), Baghdad, Iraq,
28–29 December 2021; pp. 100–105. [CrossRef]
24. Arifin, S.; Muktyas, I.B.; Prasetyo, P.W.; Abdillah, A.A. Unimodular matrix and bernoulli map on text encryption algorithm using
python. Al-Jabar: J. Pendidik. Mat. 2021, 12, 447–455. [CrossRef]
25. Ataş, M.T.; Güler, H. Real-Time Encryption/Decryption Algorithm with A Fractional Chaotic System of Various Data: Image,
Speech, and Text. Int. J. Appl. Comput. Math. 2022, 8, 161. [CrossRef]
26. Ignatius Moses Setiadi, D.R.; Rachmawanto, E.H.; Zulfiningrum, R.; Sarker, M.K. Text Encryption using Bi-Amold Cat Map
and Modulus Operation. In Proceedings of the 2021 International Seminar on Application for Technology of Information and
Communication (iSemantic), Semarangin, Indonesia, 18–19 September 2021; pp. 102–106. [CrossRef]
27. Lawnik, M.; Berezowski, M. New Chaotic System: M-Map and Its Application in Chaos-Based Cryptography. Symmetry 2022,
14, 895. [CrossRef]
28. Ali, T.S.; Ali, R. A novel color image encryption scheme based on a new dynamic compound chaotic map and S-box. Multimed.
Tools Appl. 2022, 81, 20585–20609. [CrossRef]
29. Kumar, K.; Roy, S.; Rawat, U.; Malhotra, S. IEHC: An efficient image encryption technique using hybrid chaotic map. Chaos
Solitons Fractals 2022, 158, 111994. [CrossRef]
30. Li, C.; Yang, X. An image encryption algorithm based on discrete fractional wavelet transform and quantum chaos. Optik 2022,
260, 169042. [CrossRef]
31. Vidhya, R.; Brindha, M. A chaos based image encryption algorithm using Rubik’s cube and prime factorization process (CIERPF).
J. King Saud Univ. Comput. Inf. Sci. 2022, 34, 2000–2016. [CrossRef]
32. Ye, G.; Wu, H.; Liu, M.; Shi, Y. Image encryption scheme based on blind signature and an improved Lorenz system. Expert Syst.
Appl. 2022, 205, 117709. [CrossRef]
33. Gao, X.; Mou, J.; Banerjee, S.; Cao, Y.; Xiong, L.; Chen, X. An effective multiple-image encryption algorithm based on 3D cube and
hyperchaotic map. J. King Saud Univ. Comput. Inf. Sci. 2022, 34, 1535–1551. [CrossRef]
34. Banik, A.; Laiphrakpam, D.S.; Agrawal, A.; Patgiri, R. Secret image encryption based on chaotic system and elliptic curve
cryptography. Digit. Signal Process. 2022, 129, 103639. [CrossRef]
35. Lawnik, M.; Pełka, A.; Kapczyński, A. A New Way to Store Simple Text Files. Algorithms 2020, 13, 101. [CrossRef]
36. El-Latif, A.A.A.; Abd-El-Atty, B.; Belazi, A.; Iliyasu, A.M. Efficient Chaos-Based Substitution-Box and Its Application to Image
Encryption. Electronics 2021, 10, 1392. [CrossRef]
37. Wu, Y.; Zhou, Y.; Saveriades, G.; Agaian, S.; Noonan, J.P.; Natarajan, P. Local Shannon entropy measure with statistical tests for
image randomness. Inf. Sci. 2013, 222, 323–342. [CrossRef]
38. Chen, J.X.; Zhu, Z.l.; Fu, C.; Zhang, L.b.; Zhang, Y. An efficient image encryption scheme using lookup table-based confusion and
diffusion. Nonlinear Dyn. 2015, 81, 1151–1166. [CrossRef]
39. Tsafack, N.; Sankar, S.; Abd-El-Atty, B.; Kengne, J.; Jithin, K.; Belazi, A.; Mehmood, I.; Bashir, A.K.; Song, O.Y.; Abd El-Latif,
A.A. A new chaotic map with dynamic analysis and encryption application in internet of health things. IEEE Access 2020,
8, 137731–137744. [CrossRef]
40. Jiao, S.; Feng, J.; Gao, Y.; Lei, T.; Yuan, X. Visual cryptography in single-pixel imaging. Opt. Express 2020, 28, 7301–7313. [CrossRef]
41. Cheremkhin, P.A.; Krasnov, V.V.; Rodin, V.G.; Starikov, R.S. QR code optical encryption using spatially incoherent illumination.
Laser Phys. Lett. 2017, 14, 026202. [CrossRef]

You might also like