Stop and go

Stop and go generator based on LFSR implemented in other posts.

It has been proposed by CG Gunther in 1987. As the Geffe algorithm, was built with three LFSR's. It is based on the timing clock. LFSR 1 is moved at each clock cycle and controls the other two registers. If the output value will be 1 to 2 of the register LFSR is advanced in the register LFSR and the three preceding bit is repeated. However, if the output of LFSR 1 is 0, the LFSR 3 is moved and the previous bit in LFSR 2 is repeated. The output bits of the LFSR registers LFSR 2 and 3 are added modulo 2 to generate another pseudo-random bit sequence. If the length of all three registers are relatively prime , and periods of LFSR generators LFSR 2 and 3 have the greatest common divisor equal to 1 , the period of the generator is equal to the product of the periods of all registers.

So here's the code :)

int stop_and_go() {
    int lf2, lf3;
    if (lfsr_1() == 1) {
        lf2 = lfsr_2();
        lf3 = reg3[0];
    }
    else {
        lf3 = lfsr_3();
        lf2 = reg2[0];
    }
    return lf2 ^ lf3;
}
Source code: https://github.com/khipis/c-unix-sandbox/blob/master/shift-registers/stopngo.c

Komentarze

Popularne posty