Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6865985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:07:26+00:00 2026-05-27T03:07:26+00:00

Fibonacci LFSR is described on wiki, it’s pretty simple. I’d like to calucate the

  • 0

Fibonacci LFSR is described on wiki, it’s pretty simple.

I’d like to calucate the period of some Fibonacci’s LFSR and use generated sequence for ciphering later.

Let’s take and example from wiki:

x16 + x14 + x13 + x11 + 1;

//code from wiki:
include <stdint.h>
uint16_t lfsr = 0xACE1u;
unsigned bit;
unsigned period = 0;
do {
  /* taps: 16 14 13 11; characteristic polynomial: x^16 + x^14 + x^13 + x^11 + 1 */
  bit  = ((lfsr >> 0) ^ (lfsr >> 2) ^ (lfsr >> 3) ^ (lfsr >> 5) ) & 1;
  lfsr =  (lfsr >> 1) | (bit << 15);
  ++period;
} while(lfsr != 0xACE1u);

My weakly try so far in php:

function getPeriod(){
    $polynoms = array(16, 14, 13, 11);
    $input = $polynoms[0] - 1;
    $n = sizeof($polynoms);
    for ($i = 1; $i < $n; $i++)
        $polynoms[$i] = $polynoms[0] - $polynoms[$i];
    $polynoms[0] = 0;
    //reversed polynoms == array(0, 2, 3, 5);
    $lfsr = 0x1; //begining state       
    $period = 0;
    //gmp -- php library for long numbers;
    $lfsr = gmp_init($lfsr, 16);
    do {            
        $bit = $lfsr; //bit = x^16 >> 0;

        for($i = 1; $i < $n; $i++) {
            //bit ^= lfsr >> 2 ^ lfst >> 3 ^ lfst >> 5;
            $bit = gmp_xor($bit, ( gmp_div_q($lfsr, gmp_pow(2, $polynoms[$i])) ));                  
        }
        //bit &= 1;
        $bit = gmp_and($bit, 1);            
        //lfsr = $lfsr >> 1 | $lsfr << (16 - 1);
        $lfsr = gmp_or( (gmp_div_q($lfsr, 2)), (gmp_mul($bit, gmp_pow(2, $input))) );

        $period++;
    } while (gmp_cmp($lfsr, 0x1) != 0);
    echo '<br />period = '.$period;
    //period == 65535 == 2^16 - 1; -- and that's correct;
            //                        I hope, at least;
    return $period;
}

Problem:

If i try to modulate work of i.e.

x321 + x14 + x13 + x11 + 1;

i got an error:”Fatal error: Maximum execution time of 30 seconds exceeded in /var/www/Dx02/test.php“;

Can i somehow optimize (accelerate 🙂 ) the calculation?

Any help is appreciated. Thank you and excuse me for my English.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:07:27+00:00Added an answer on May 27, 2026 at 3:07 am

    You simply can’t do it this way with a polynomial like x^321 + …;

    If the polynomial is chosen well, you get a period length of 2^231 -1,
    and this is approximately 4.27 *10^96. If I’m not mistaken, this number is
    believed to exceed the number of atoms in the universe…
    (Strictly speaking, I’m referring to the posted C-code since I do not know php, but that certainly makes no difference.)

    However, there is a mathematical method to calculate the length of the period without doing a brute-force attack. Unfortunately, this can’t be explained in a few lines. If you have a solid background in math (especially calculations in finite fields), I’ll be glad to look for a helpful reference for you.

    EDIT:
    The first step in calculating the period of the LFSR obtained by using a polynomial p(x) is to obtain a factorization of p(x) mod 2, i.e. in GF(2). To do this, I recommend using software like Mathematica or Maple if available. You could also try the freely available Sage, see e.g. http://www.sagemath.org/doc/constructions/polynomials.html for usage details.

    The period of p(x) is given by its order e, that means the smallest number such that p(x) divedes x^e+1. Unfortunately, I can’t provide more information at the moment, it will take me several days to look for the lecture notes of a course I took several years ago…

    A small example: p(x) = (x^5+x^4+1) = (x^3+x+1)*(x^2+x+1), the individual periods are 2^3-1=7 and 2^2-1=3, and since all polynomial factors are different, the period of p(x) is 3*7=21, which I also verified in C++.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking through some example Fibonacci sequence clojure code: (def fibs (lazy-cat [1
Each new term in the Fibonacci sequence is generated by adding the previous two
I'm trying to expand a simple fibonacci function, and I need to use the
Here's a simple function to compute Fibonacci numbers: fib :: [Int] fib = 1
I was calculating the Fibonacci sequence, and stumbled across this code, which I saw
Generate the Fibonacci sequence in the fewest amount of characters possible. Any language is
Please explain this simple code: public int fibonacci(int n) { if(n == 0) return
I'm writing a code to output fibonacci series in C++, which is simple enough,
I have this function (produces the fibonacci sequence): unfoldr (\(p1, p2) -> Just (p1+p2,
I have to program a little program that show a Fibonacci sequence from 1

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.