{'fraction_non_alphanumeric': 0.031184155077960386, 'fraction_numerical': 0.00688298918387414, 'mean_word_length': 4.788617886178862, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
An Improved Stream Cipher Algorithm Based on NFLSR

To overcome defects of traditional stream cryptographic algorithms based on XOR operation, this paper proposes a new stream cipher algorithm with higher security and suitability for encrypting short information, which is based upon traversal operation and zipper-like random dynamic hash mapping, has the same time and space complexity as the traditional one. It generates the key stream through an application of Nonlinear Feedback Shift Register (NLFSR) and Bits Scrambling.


Introduction
The current study on stream cipher mainly concentrates on key stream generator and methods of attacking the key stream. In fact, the key stream generator would form the key stream involving 0, 1 data streams through a given algorithm, which is usually based on mathematical models that can generate pseudo-random sequences, such as Linear Feedback Shift Register(LFSR) [1] [2], Clock Control Sequence [3], Chaos Theory [4] [5], etc. The sender encrypts the plaintext with the key stream to generate ciphertext and sends it to the receiver, who decrypts the ciphertext with the same key stream to regain the plaintext. After years of research, many scholars have mastered many identifying and decoding methods. For instance, Courtois and Meier [6] in 2003 applied algebraic attacks to stream cipher algorithms on the basis of LFSR, greatly impacting on traditional stream cipher systems.
In order to resist related and algebraic attacks, the stream cipher algorithm based on LFSR needs more complex feedforward function. NLFSR [7][8], as a pseudo-random sequence generator with high security, can effectively resist correlation and algebraic attacks. Since 2004, key stream generators based on NLFSR technology have started to emerge. For example, the Grain, Trivium and MICKEY algorithms finally recommended by eSTREAM Project all use NLFSR as a key stream generator.

Problems
The stream cipher is used to transform plaintext into ciphertext in binary bits according to certain rules. With common stream cipher technology, ciphertext can be obtained through XOR operation between key stream and plaintext; the plaintext can be decrypted after regaining the original binary characters by XOR operation between the key stream and the plaintext.
The key of common stream cipher technology is to generate (pseudo) random sequences as key streams through various key stream generators. Therefore, attacks on stream cipher also focus on attacks on key stream generators.
One of the defects of this approach is the single encryption and decryption process. Now there have been many attack technologies on the key stream generator in that the security of the stream cryptosystem depends entirely on the security intensity of the key stream. Another defect is that ciphertext with good randomness and code distribution uniformity cannot be obtained just by XOR operation.

Method
Similar to LFSR, NLFSR is also based on gate circuits. From the perspective of algebraic expression, XOR gate is expressed as binary addition (+), while AND gate is expressed as binary multiplication (×). The difference between NLFSR and LFSR is that the feedback logic of NLFSR is composed of XOR gate and AND gate, while that of LFSR is composed of XOR gate only, which leads to higher complexity of NLFSR, Up to now, there is no universally applicable algebraic attack method against NLFSR. The output sequence of NLFSR is periodic, for seed keys with a length of n, the longest cycle of the output sequence can reach 2 n -1. Obviously, the longer the cycle is, the better the encryption is.
We have figured out an encryption and decryption method based on zipper-like dynamic hash and NLFSR. The key stream generator is formed based on NLFSR and Boolean function with Bits Scrambling. The seed key is pre-processed by the key stream generator and then generates the output sequence as the key stream. In the process of traversing operation, the pseudo-plaintext is obtained from plaintext based on scrambling bits of key stream. At the same time, the zipper-like dynamic directly-addressing method based on key stream can be used to calculate the hash address of binary bits of pseudo-plaintext in ciphertext space, and then the pseudo-plaintext is mapped into ciphertext space to generate the final ciphertext. An illustrative diagram of a modified stream cipher system based on NFLSR is shown in Figure 1. The encryption algorithm is expressed by natural language mixed with C + + language. Its execution process is as follows: (1) Read the file of plaintext and set the seed key, establish working pointers M, K and C, allocate storage space for plaintext, key and ciphertext, wherein M is the working pointer of plaintext, K is the working pointer of key, C is the working pointer of ciphertext, and count the M bytes (byte number of plaintext M).
(2) Calculate the output sequence of seed key by nonlinear feedback function. The function void get_NLFSR_sequence (string str, int a, int b, int c, int d) calculates the first output sequence of the seed key by the nonlinear feedback function and stores it in the string -NlfsrSequence. Parameter str is the seed key, and a, b, c and d are the coefficients of the nonlinear feedback function F1 (x0, xa, xb, xc, xd) = x0 × xa × xb × xc • xd, as shown in the figure 2, where "⊕ " is "XOR" operation (i.e. Modulo 2 addition) and "•" is "AND" operation (i.e. Modulo 2 multiplication). (3) Cyclic filling of the aforementioned output sequence NlfsrSequence to the key stream space K. The function void get_key_stream (string Seq) converts the output sequence Seq by the nonlinear feedback function into a string, which is stored in the key space K by cyclic filling. The parameter Seq is the output sequence generated by the seed key by the nonlinear feedback function. The algorithm is described as follows: for  (1) void write_bit_0 (char * p_str, int n) implements the function of generating 0 towards the nth binary bit, and the parameter p_str is a pointer to a string.
(2) void write_bit_1 (char * p_str, int n) implements the function of generating 1 towards the nth binary bit, and the parameter p_str is a pointer to a string.
(3) int read_one _ bit (char * p_str, int n) implements the function of reading the nth binary bit and returning, and the parameter p_str is a pointer to a string.  Figure 3 shows the illustrative diagram of the above algorithm when the seed key is Binary {1000}2. The nonlinear feedback function is F1(x0, x1, x2, x2, x3); the plaintext is "aaaa", and finally the ciphertext C is obtained.

Conclusion
This paper presents an improved stream cipher algorithm based on NLFSR, which is consistent with the common stream cipher in time and space complexity. The important difference from the common one is that the security intensity of this algorithm does not completely depend on the key stream, and the uniformity of the key stream is not strictly required so that it has higher security. In addition, this algorithm scrambles bits of plaintext stream and key stream, so it is also applicable to short information.