Simple Encryption
Example 4 uses this technique in a simple example. The function hideandshow(char *,char *) processes the text in one buffer into another using 8 values for the xor. I picked 8 values from the output of example 3 with 5 or more bits set. With a higher number of bits set there is a greater overall transformation. Using only 8 values though means the range of transformations is lower.As this is a light weight scheme, you should realize that it is not suitable for anything stronger than hiding text. Every developer thinks that their encryption scheme is uncrackable but that protection usually relies on hiding how the data was encrypted, this is known as "security through obscurity" and is not regarded every highly.
The strongest encryption schemes have their algorithms published and it is the strength of those algorithms that protects the data. If you write your own scheme, it is quite difficult to prevent your code being reverse engineered and if the prize is high enough, it will be.
The 8 values are indexed by the variable eindex which is repeatedly incremented but constrained within the range 0..7 by the line
eindex % = 8;This uses the built in C modulus operator. This line is the same as
if (eindex>=8)As can be seen from the output, the text displayed by the last printf is identical to the text supplied to the first call of hideandshow() in the output listing below.
eindex=0;
The hidden text isDownload Example 4.
89
1a
e3
15
c8
93
cc
d0
b3
13
eb
57
The unhidden text is Hello world.
On the next page All about Unions.

