### Generating the pseudo-random codes that measured the distance to the Apollo spacecraft

During the Apollo mission to the Moon, NASA needed to know the distance from Earth to the spacecraft. This was accomplished by a sending a signal from Earth to the spacecraft and receiving the response. Since the signal traveled at the speed of light, the distance could be determined from the time delay between the sent and received signals. They determined the delay by transmitting a pseudo-random bit sequence and correlating it with the returned signal. This web page demonstrates how the pseudo-random bit sequence was generated.The sequence was generated by combining four short code sequences to form a very long code. The short codes could be generated with simple circuits: shift registers and exclusive-or gates forming a linear-feedback shift register. The result was a very long code of length 5,456,682 that wouldn't repeat in the time it took the signal to get to the Moon and back.

The first sequence is the "A code", which repeats every 31 bits. The animation shows how each new bit (red) is generated by XOR of two bits in the 5-bit shift register. The new bit is then shifted into the shift register.

Next, the "B code", which repeats every 63 bits.
With a 6-bit shift register, the sequence repeats after 2^{6} bits.

The "C code" repeats every 127 bits.

The "X code" is generated by a more complex circuit to achieve the length of 11 bits. This sequence is based on a Legendre sequence to obtain the desired correlation properties.

Finally, the four sequences are combined, along with a clock, generating the pseudo-random sequence that is broadcast. By combining the sequences with a majority function instead of simply XORing them together, the resulting sequence can be correlated against the component sequences. This allows the overall phase shift of the received sequence to be measured. (The process is illustrated on this page.)

(X' · maj(A, B, C)) ⊕ clk