Bidirectional stream encryption algorithm

zhaozj2021-02-16  71

Due to the many encryption applications, the information requiring encrypted has anti-reverse analysis (for example, the crackman knows the plan of the plain text.

The ability to reverse the key and decrypt the rest of the information on this basis. This article proposes a such as-long bidirectional stream

The information encrypted by this algorithm is encrypted by this algorithm, with the data of the overall information correlation, with strong anti-reverse analysis

And the ability of differential analysis.

Algorithm thinking:

See the plus decryption object as a BYTE array a [N]. First of all, we traverse it from head to tail, and will meet the elements encountered.

The value is added to the value of the previous element and writes back to the array. That is, A [i] a [i-1] => a [i] (I am increasing from 2 to N). such

As a result, the ciphertext of the back element directly depends on the value of the previous element, and has reached the purpose of partial anti-analysis. It is not difficult to find, enter

Darkness over and over again, only allow the elements of the array to form a small element to the small element, and the ideal situation should be mixed

Dependent dependence. In order to solve this defect, we are easy to think of reverse traversal - thinking is the same as the traversal, just

The stop is reversed: a [i] a [i 1] => a [i] (i is decremented from N-1 to 1). After the opposite traversal, each of the arrays

The value of an element becomes associated with the value of all other elements - thereby, this algorithm also has an anti-reverse analysis

And the ability of differential analysis.

After solving the problem of information-dependent, we need to think about it, as an encryption algorithm, how the key is

Place the above calculation process. First, I added one in the process of being forwarded and reverse traversal.

The length of one byte is a key, so the encryption process is turned:

(A [i] a [i-1]) xor key1 => a [i] - forward traversal

(A [i] a [i 1]) xor key2 => a [i] - reverse traversal

Let us look carefully to the traversal process, it is not difficult to find that in each traversal, there is a value of the elements in the starting point without hair.

Life changes (A [1] in the traversal, A [N]) in the reverse traversal, obviously an entry point - so we are

The two ends of the array have another "implied element" (a [0], a [n 1]), which is the third after the front key1, Key2

And the fourth key (which is of course one byte), allowing them to act in traversing in traversal at the beginning of the two traversal

The start element value does not change in:

A [1] key3 => a [1] - forward traversal

A [n] key4 => a [n] - reverse traversal

Now, the complexity of the key reaches four bytes, namely 32bits, which can meet the general addendal requirements (considering this algorithm)

The encryption object is based on bytes, compared to the block plus calculation of the encrypted object with the positive length (64bit or larger) data block.

Method, the key to this algorithm is simple to understand, in order to obtain a larger key space, the user can use

Multiple encryption or multi-layer encryption methods (considering the simplicity of this algorithm, easy to implement, and execute block encryption

The algorithm is very fast, multi-layer nested encryption is a good choice). It should be pointed out that due to this algorithm each encrypted object

It is the entire plaintext, rather than a certain length block, so many key information will be even text after multiple nested encryption.

Access (unless the information amount of the key has been greater than the amount of information of the plaintext - for example: encrypts the two bytes of information with a total of 1024bit "!), Rather than mixing each other in the fixed length block (嘿, If you use DES to nested, you will send it.

Born this situation).

In the specific code below, I not only realize the above algorithm, but also multiple encrypted directly to the addendency process.

Among them.

{

Name: Two-way stream encryption algorithm

Author: creation_zy

Time: 2004-4

Remarks:

Appropriate increasing parameter Times (encryption) can greatly improve the difficulty of ciphertext, but time consuming

The proportion increases, for text within 1 kB, it is recommended to control it within 1-1024. If it is embedded

Setting up, it can be further controlled between 1-8.

}

Procedure seqenc (var str: string; key: integer; times: integer);

VAR

I, C, N: integer;

Key1, Key2, Key3, Key4: Byte;

Begin

N: = Length (STR);

IF n = 0 THEN

EXIT;

Key4: = byte (Key SHR 24);

Key3: = Byte (key shr 16);

Key2: = byte (Key Shr 8);

Key1: = byte (key);

For c: = Times-1 Downto 0 DO

Begin

STR [1]: = char (byte (str [1]) key3);

For i: = 2 to n DO

Str [I]: = char ((Byte (STR [I-1]) Byte (STR [I])) XOR Key1);

Str [n]: = char (byte (str [n]) key4);

For i: = n-1 Downto 1 do

Str [I]: = char ((Byte (STR [i 1]) Byte (STR [i])) XOR Key2);

END;

END;

Procedure seqdec (var str: string; key: integer; times: integer);

VAR

I, C, N: integer;

Key1, Key2, Key3, Key4: Byte;

Begin

N: = Length (STR);

IF n = 0 THEN

EXIT;

Key4: = byte (Key SHR 24);

Key3: = Byte (key shr 16);

Key2: = byte (Key Shr 8);

Key1: = byte (key);

For c: = Times-1 Downto 0 DO

Begin

For i: = 1 to N-1 DO

Str [I]: = char (Byte (STR [i]) XOR Key2-byte (STR [i 1]));

Str [n]: = char (byte (str [n]) - key4);

For i: = n Downto 2 do

Str [I]: = char (byte (STR [i]) xor key1-byte (STR [i-1]));

Str [1]: = char (Byte (Str [1]) - KEY3);

END;

END;

Use example:

VAR

Str: string;

Begin

Str: = 'Name: two-way flow of encryption algorithms: creation_zy';

SEQENC (STR, 6, 927506813); // Perform 6 encryption with key 927506813

// Str has been encrypted

SEQENC (STR, 2, 200498157); // Perform 2 encryption // Strs with key 200498157 has been encrypted secondary ...

SEQDEC (STR, 2, 200498157); // Perform 2 decryption with key 200498157

// Decrypt the first floor ...

SEQDEC (STR, 6, 927506813); // Perform 6 decryption with key 927506813

// Decrypt the second layer - Str has been restored

END;

Encryption Effect Example:

Str: "Varpool.SetValue ('Tablestr', STR1);"

Key: 927506813

Times: 5

Encrypted results displayed in hexadecimal:

"5FC4305B6A2ABFA0B13DD4F5253AC697092853741E12175C2886C7682EB3F41D1AF3"

The "1" in the clear text STR replaces the encryption result after "2" (displayed in hexadecimal):

"AA57C2B25A07C30EC1C955074C62A7D2CAB10709E89D2D907210FEEC2F9DB75AEDF2"

转载请注明原文地址:https://www.9cbs.com/read-16751.html

New Post(0)