title: CRC CCITT (0xFFFF) Implementation in Python
body: <p>I need to implement calculation of crc from string of zeroes and one-s like 10000000 etc</p>
  
  <p>I have found this code but its for CRC CCITT(XModem)
      POLYNOMIAL = 0x1021
      PRESET = 0</p>
  
  <pre><code>    def _initial(c):
          crc = 0
          c = c &lt;&lt; 8
          for j in range(8):
              if (crc ^ c) &amp; 0x8000:
                  crc = (crc &lt;&lt; 1) ^ POLYNOMIAL
              else:
                  crc = crc &lt;&lt; 1
              c = c &lt;&lt; 1
          return crc
  
      _tab = [ _initial(i) for i in range(256) ]
  
      def _update_crc(crc, c):
          cc = 0xff &amp; c
  
          tmp = (crc &gt;&gt; 8) ^ cc
          crc = (crc &lt;&lt; 8) ^ _tab[tmp &amp; 0xff]
          crc = crc &amp; 0xffff
  
          return crc
  
      def crc(str):
          crc = PRESET
          for c in str:
              crc = _update_crc(crc, ord(c))
          return crc
  
      def crcb(*i):
          crc = PRESET
          for c in i:
              crc = _update_crc(crc, c)
          print crc
          return crc
  </code></pre>
  
  <p>Changing PRESET to 0xFFFF as it is initial value for CRC CCITT (0xFFFF) doesnt help.</p>
  
  <p>Does anyone can help to rewrite or adapt this code? For reaching a result? For checking uses <a href="https://www.lammertbies.nl/comm/info/crc-calculation.html" rel="nofollow noreferrer">https://www.lammertbies.nl/comm/info/crc-calculation.html</a></p>
  
  <p>Downloading and installation crc16 library not allowed due security reasons</p>
  
  <p>Python2.7</p>