1. Introduction
Chaos theory is one of the great discoveries of the 20th century. Currently, chaos and its applications are an important aspect in many fields of science [
1]. The effect of chaos can be undesirable, such as oscillations in chemical reactors, or be used to achieve positive results. A wide group of chaos applications includes cryptography based on chaotic dynamical systems. Chaotic cryptography uses dynamic systems with very complex behavior. On the one hand, the obtained values from such systems appear to be random, while the way they are obtained is completely deterministic. For these reasons, chaotic mappings have been used in, among other areas, data encryption [
2,
3,
4].
The beginnings of cryptography based on the chaos theory date to the 1990s. It was then that the first stream ciphers were presented, which were used mainly for text encryption. One of the first publications that dealt with this subject was the publication by M.S. Baptista [
5]. In that article, an algorithm that uses the logistic map to encrypt 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 solution [
6]. However, chaotic cryptography deals not only with stream ciphers, but also asymmetric ciphers [
7] and their successors [
8], hash functions [
9,
10], S-boxes [
11,
12], pseudo-random numbers generators (PRNGs) [
13,
14] or image-encryption algorithms [
13]. Currently, the last group of mentioned algorithms is of particular interest to scientists. Chaotic image encryption is obtained using a selected chaotic dynamic system to transform the image pixels appropriately. Such algorithms are considered to be safe and applicable in practice. In the context outlined, a question can be asked: is it possible to use the developed techniques and methods of image encryption for text encryption? An affirmative answer to 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 multimedia 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 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.
Analyzing the above works, it can be seen that this field of cryptography is developing 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:
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.
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:
The text message is read into the buffer.
Text characters are converted to numbers in the range 0–65535 (UTF-8 encoding).
Each of the values
is stored in the positional system with base 256 according to the equation:
where
and
are the coefficients of
in the positional numeral system with base 256. Values
and
are stored in one-dimensional table
T.
The image size (height and width) is calculated using the formula
where
stands for the ceiling function, and
is the length of the table
T.
If
then
T is first padded with the value 3 (“End-of-Text” character) and then with random values from set
so that its length is exactly
.
T is saved as a three-dimensional array , i.e., every three consecutive elements of the array T are stored as an element of a matrix with dimensions of .
Array 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.
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.
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:
Successive image pixels are loaded in the buffer until the value of one of the components is equal to 3.
Loaded RGB pixel components values are stored in one- dimensional table T.
Every two values from
T are retrieved and marked as
and
. These values are the coefficients of the number
written in the number system with base 256, i.e.,
The 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.
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 and the value of the
p parameter. For further processing of this algorithm, the following values were established:
and
.
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
Figure 4b,
Figure 5a and
Figure 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
pixels. Test Files 2 and 3 are
and
pixels, respectively.
In turn,
Figure 4c,
Figure 5b and
Figure 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
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.
To assess whether the encryption algorithm meets specific security requirements, certain 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
Figure 7,
Figure 8 and
Figure 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 of times. Such a situation is, of course, necessary from the point of view of the security of the encrypted message.
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
where
N is the number of all possible characters in the source alphabet,
is the source character, and
is the probability of
. In the case of text in UTF-8 encoding,
N = 65,536, and in the case of an image saved in the format
png . Entropy is maximal when
. For text in UTF-8 encoding, the maximum entropy value is
, while for the image
png it is
. 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.
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,
37,
38,
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
, so
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
, 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.
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
where
x and
y are consecutive image pixels with dimension
. The correlation coefficient satisfies the
relationship, and
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 relationship 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
,
, respectively, for the test files. In turn, for the encrypted image it is about
,
and
, 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.
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 and are needed. Those cipher-images are created from encryption for two plaintexts and , which differ by one random pixel value using the same keys.
The
value is calculated from the formula:
where
stands for image dimension and
stands for pixel in
coordinates of image
. The ideal value for
is 100%.
The
value is calculated from the formula:
where
stands for image dimension and
stands for pixel in
coordinates of image
. The ideal value for
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.
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
where
stands for image dimension and
stands for pixel in
coordinates of image
. The
MSE value should be high for any robust encryption algorithms. In the case of the analyzed case,
means the cipher-image, while
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.
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].