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 GNUradio 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 GNUradio.
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

have to be fixed beforehand and are known as the seed of the scrambler.
The multiplicative descrambler works as follows: it transforms a sequence
into the sequence
given by

are fixed beforehand (these are the seed of the descrambler). To see that this function does, in fact, revert the scrambling process, assume that the receiver starts receiving and descrambling at some point in time, so that
for
. Then we see that
for
. Thus, the descrambler recovers the stream of data (obviously shifted
units in time), except for the first
elements.
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

is defined by the recurrence
are known as the seed and are fixed beforehand.
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

for all
.
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 coefficients of
are
or
, so it is usual to encode them as the digits of a binary number. However, there are several possible ways to do so. First, there is the choice of order: whether later bits correspond to higher or lower powers of
. Then, the independent term of
is always
, so it is possible to omit this coefficient in the binary representation. Also, the leading term of
is always
, because we can assume that
is the degree of
. Then, it is possible to omit this coefficient as well.
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 GNUradio suggests that the notation used in GNUradio 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 GNUradio 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 GNUradio, 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
.