├── Makefile ├── README.md ├── find_scramblers.c └── scramble.c /Makefile: -------------------------------------------------------------------------------- 1 | all : scramble find_scramblers 2 | 3 | find_scramblers : find_scramblers.c 4 | gcc -o find_scramblers find_scramblers.c -Wall -pedantic -O4 5 | 6 | scramble : scramble.c 7 | gcc -o scramble scramble.c -Wall -pedantic -O4 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # lfsr_scramblers 2 | Experiments with self-synchronizing LFSR scramblers. 3 | 4 | Scramblers are useful to convert a a somewhat predictable sequence 5 | of bits into what look like random bits, with approximately even 6 | numbers of '1's and '0's (so minimal DC bias). 7 | 8 | This allows them to be easily transmitted and recoverd (e.g. over radio or optics) 9 | 10 | The structure of the LFSR scrambler is such that it self-synchronizes between 11 | encoder and decoder, and that RX errors will quickly clear from the receiver. 12 | 13 | ## The two programs 14 | 15 | find_scramblers.c : Search for 1-tap maximal LFSRs (repeat period is 2^n-1) 16 | 17 | scramble.c : Show a scrambler in action or can be used to gnerate test vectors 18 | -------------------------------------------------------------------------------- /find_scramblers.c: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * find_scramblers.c : Find maximal LFSR shift registers with 1 tap 3 | * 4 | * (c) 2020 Mike Field 5 | * 6 | *******************************************************************/ 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | uint32_t state = 1; 14 | uint8_t seen[64*1024*1024]; 15 | 16 | uint8_t doit(int len, int tap1) { 17 | uint8_t out = ((state>>(len-1)) ^ (state>>(len-tap1))) & 1; 18 | state = (state <<1) | out; 19 | state &= (1< 5 | * 6 | *******************************************************************/ 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | uint32_t state_s = 0xAAAAAAAA; 13 | uint32_t state_u = 0xFFFFFFF1; 14 | 15 | 16 | static uint8_t scramble(int len, int tap, uint8_t d) { 17 | uint8_t out = ((state_s>>(len-1)) ^ (state_s>>(len-tap))) & 1; 18 | out ^= d; 19 | state_s = (state_s <<1) | out; 20 | state_s &= (1<>(len-1)) ^ (state_u>>(len-tap))) & 1; 26 | uint8_t out; 27 | out = q ^ d; 28 | state_u = (state_u <<1) | d; 29 | state_u &= (1<>1) | (data<<63); 49 | 50 | d_str[w] = d ? '1' : '0'; 51 | s_str[w] = s ? '1' : '0'; 52 | u_str[w] = u ? '1' : '0'; 53 | w++; 54 | if(w == 70) { 55 | d_str[w] = 0; 56 | s_str[w] = 0; 57 | u_str[w] = 0; 58 | printf("Data : %s\n",d_str); 59 | printf("Scrambled : %s\n",s_str); 60 | printf("Unscrambled : %s\n",u_str); 61 | printf("\n"); 62 | w = 0; 63 | } 64 | } 65 | if(w != 0) { 66 | d_str[w] = 0; 67 | s_str[w] = 0; 68 | u_str[w] = 0; 69 | printf("Data : %s\n",d_str); 70 | printf("Scrambled : %s\n",s_str); 71 | printf("Unscrambled : %s\n",u_str); 72 | printf("\n"); 73 | w = 0; 74 | } 75 | } 76 | --------------------------------------------------------------------------------