Scramblers and their implementation in GNU Radio
A scrambler is a function that is applied to a sequence of data before transmitting with the goal of making this data more “random-like”. For instance, scrambling avoids long runs of the bits 0 or 1 only, which may make the receiver loose synchronization or cause spectral concentration of the signal. The receiver applies the inverse function, which is called descrambler, to recover the original data. The documentation for the scrambler blocks in GNU Radio is not very good and one may need to take a look at the implementation of these blocks to get their parameters right. Here, I’ll try to explain a bit of the mathematics behind scramblers and the peculiarities of their implementation in GNU Radio.
There are two types of scramblers, multiplicative or self-synchronizing and additive or synchronous. Both may be explained in terms of Linear Feedback Shift Registers but I will try to do an alternative exposition without using this concept.
Let be a module over a ring . Usually, and will be in the applications (this is the ring consisting of the elements , with addition given by the XOR Boolean operation and multiplication given by the AND Boolean operation). Both types of scramblers are defined by some fixed coefficients .
The multiplicative scrambler transforms the sequence into the sequence given by the recurrence
The multiplicative descrambler works as follows: it transforms a sequence into the sequence given by
We have seen that the multiplicative descrambler can start descrambling at any time, without the need to synchronize with the stream of data. For this reason, the multiplicative scrambler/descrambler is called self-synchronizing. Another remark is that the seeds used for the scrambler and descrambler make no effect in practice and any values can be used as a seed. The descrambler “loses” the first elements of the data, but this is not a problem in applications.
The additive scrambler takes the sequence and transforms it into the sequence given by
Now we see that, in contrast to the multiplicative scrambler, there is no way to descramble this sequence in a self-synchronizing manner. In fact, the only way possible way to descramble it is that the scrambler and descrambler start at the same time (so the descrambler input is ). The descrambler generates the same sequence using the same seed, and takes the sequence into by
Therefore, the additive scrambler and descrambler must start at the same time and use the same seed. For this reason, this scrambler is called synchronous. In applications, an unscrambled synchronization word is sent before the scrambled data to signal the descrambler that it has to start working. Another remark is that when the characteristic of is 2 the additive scrambler and descrambler are the same function.
It is usual to give the coefficients as the coefficients of a polynomial
The choice of the binary representation to use is ultimately tied to the implementation of the the scrambler using a shift register, as there are several possible ways to do so. For instance, this huge list uses the notation . For instance, is is represented as 0xC.
The documentation from GNU Radio suggests that the notation used in GNU Radio is . For instance, it says that is represented as 0x19. However, a careful look at the code reveals that this is not the case. The following method next_bit_scramble() implements the multiplicative scrambler.
unsigned char next_bit_scramble(unsigned char input)
{
unsigned char output = d_shift_register & 1;
unsigned char newbit = (popCount( d_shift_register & d_mask )%2)^(input & 1);
d_shift_register = ((d_shift_register>>1) | (newbit<<d_shift_register_length));
return output;
}The function popCount() just counts the number of bits that are 1. We see that d_shift_register is used to store the bits (big-endian order). The variable d_mask stores the polynomial. Hence, we see that the representation used for is . For instance, would be represented as 0x3. The polynomial , which is used in 9k6 baud FSK AX.25, is represented as 0x21. When using this representation, one should also indicate the degree of . The way to indicate this in GNU Radio is by means of the variable d_shift_register_length. This should be set to .
A similar notation problem happens for the seed value. Although one can use any seed for the multiplicative scrambler/descrambler, it is necessary to use the correct seed for the additive scrambler. Moreover, above we have defined the seed as the values . It is also possible to use the values instead. If is invertible, then one can obtain in terms of and vice versa. Thus, the choice of using one definition of the seed or the other one depends more on how the scrambler is implemented.
In GNU Radio, the seed is defined as . The binary representation used for the seed is similar to the notation used for polynomials: it is represented as the binary number .