title: How can I input my binary string into the linear complexity test?
body: <p>I am hoping to gain help to understand how and where I would insert my own binary string that I generated in order to test it for randomness through the linear complexity test. I am very new to coding and would appreciate any help I could get. I uploaded a picture of the code I was using as I was unsuccessful in running the test.</p>
  <p>Thanks in advance!</p>
  <pre><code>from copy import copy as copy
  from numpy import dot as dot
  from numpy import histogram as histogram
  from numpy import zeros as zeros
  from scipy.special import gammainc as gammainc
  
  class ComplexityTest:
  
      @staticmethod
      def linear_complexity_test(my_binary_string:str, verbose=False, block_size=4):
          &quot;&quot;&quot;
          Note that this description is taken from the NIST documentation [1]
          [1] http://csrc.nist.gov/publications/nistpubs/800-22-rev1a/SP800-22rev1a.pdf
          The focus of this test is the length of a linear feedback shift register (LFSR). The purpose of this test is to
          determine whether or not the sequence is complex enough to be considered random. Random sequences are
          characterized by longer LFSRs. An LFSR that is too short implies non-randomness.
  
          :param      my_binary_string:    a binary string
          :param      verbose         True to display the debug messgae, False to turn off debug message
          :param      block_size:     Size of the block
          :return:    (p_value, bool) A tuple which contain the p_value and result of frequency_test(True or False)
          &quot;&quot;&quot;
      my_binary_string = '0010101100010010100010011110110101111010011111110001111001101101'
      length_of_my_binary_string  = len(my_binary_string)
  
          # The number of degrees of freedom;
          # K = 6 has been hard coded into the test.
      degree_of_freedom = 6
  
          #  π0 = 0.010417, π1 = 0.03125, π2 = 0.125, π3 = 0.5, π4 = 0.25, π5 = 0.0625, π6 = 0.020833
          #  are the probabilities computed by the equations in Section 3.10
      pi = [0.01047, 0.03125, 0.125, 0.5, 0.25, 0.0625, 0.020833]
  
      t2 = (block_size / 3.0 + 2.0 / 9) / 2 ** block_size
      mean = 0.5 * block_size + (1.0 / 36) * (9 + (-1) ** (block_size + 1)) - t2
  
      number_of_block = int(length_of_my_binary_string / block_size)
  
      if number_of_block &gt; 1:
          block_end = block_size
          block_start = 0
          blocks = []or i in range(number_of_block):
          blocks.append(binary_data[block_start:block_end])
          block_start += block_size
          block_end += block_size
  
          complexities = []
          for block in blocks:
              complexities.append(ComplexityTest.berlekamp_massey_algorithm(block))
  
              t = ([-1.0 * (((-1) ** block_size) * (chunk - mean) + 2.0 / 9) for chunk in complexities])
              vg = histogram(t, bins=[-9999999999, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 9999999999])[0][::-1]
              im = ([((vg[ii] - number_of_block * pi[ii]) ** 2) / (number_of_block * pi[ii]) for ii in range(7)])
  
              xObs = 0.0
              for i in range(len(pi)):
                  xObs += im[i]
  
              # P-Value = igamc(K/2, xObs/2)
              p_value = gammainc(degree_of_freedom / 2.0, xObs / 2.0)
  
              if verbose:
              print('Linear Complexity Test DEBUG BEGIN:')
              print(&quot;\tLength of input:\t&quot;, length_of_binary_data)
              print('\tLength in bits of a block:\t', )
              print(&quot;\tDegree of Freedom:\t\t&quot;, degree_of_freedom)
              print('\tNumber of Blocks:\t', number_of_block)
              print('\tValue of Vs:\t\t', vg)
              print('\txObs:\t\t\t\t', xObs)
              print('\tP-Value:\t\t\t', p_value)
              print('DEBUG END.')
  
  
          return (p_value, (p_value &gt;= 0.01))
      else:
          return (-1.0, False)
  </code></pre>