def crc32(seq) : """Returns the crc32 checksum for a sequence (string or Seq object)""" try : #Assume its a Seq object return _crc32(seq.tostring()) except AttributeError : #Assume its a string return _crc32(seq)
def crc32(seq): """Returns the crc32 checksum for a sequence (string or Seq object).""" try: #Assume its a Seq object return _crc32(seq.tostring()) except AttributeError: #Assume its a string return _crc32(seq)
def crc32(seq): """Returns the crc32 checksum for a sequence (string or Seq object).""" # NOTE - On Python 2 returns a signed int, on Python 3 it is unsigned # Docs suggest should use crc32(x) & 0xffffffff for consistency. # TODO - Should we return crc32(x) & 0xffffffff here? try: # Assume its a Seq object return _crc32(_as_bytes(str(seq))) except AttributeError: # Assume its a string/unicode return _crc32(_as_bytes(seq))
def crc32(seq): """Returns the crc32 checksum for a sequence (string or Seq object).""" #NOTE - On Python 2 returns a signed int, on Python 3 it is unsigned #Docs suggest should use crc32(x) & 0xffffffff for consistency. #TODO - Should we return crc32(x) & 0xffffffff here? try: #Assume its a Seq object return _crc32(_as_bytes(seq.tostring())) except AttributeError: #Assume its a string/unicode return _crc32(_as_bytes(seq))
def crc32(seq): """Return the crc32 checksum for a sequence (string or Seq object). Note that the case is important: >>> crc32("ACGTACGTACGT") 20049947 >>> crc32("acgtACGTacgt") 1688586483 """ try: # Assume it's a Seq object return _crc32(str(seq).encode()) except AttributeError: # Assume it's a string return _crc32(seq.encode())
def mn_checksum(wlist): '''Given a mnemonic seed word list, return a string of the seed checksum.''' if len(wlist) > 13: wlist = wlist[:24] else: wlist = wlist[:12] wstr = "".join(word[:3] for word in wlist) z = ((_crc32(wstr.encode()) & 0xffffffff) ^ 0xffffffff) >> 0 z2 = ((z ^ 0xffffffff) >> 0) % len(wlist) return wlist[z2]
def crc32(seq): """Returns the crc32 checksum for a sequence (string or Seq object). Note that the case is important: >>> crc32("ACGTACGTACGT") 20049947 >>> crc32("acgtACGTacgt") 1688586483 """ # NOTE - On Python 2 returns a signed int, on Python 3 it is unsigned # Docs suggest should use crc32(x) & 0xffffffff for consistency. # TODO - Should we return crc32(x) & 0xffffffff here? try: # Assume its a Seq object return _crc32(_as_bytes(str(seq))) except AttributeError: # Assume its a string/unicode return _crc32(_as_bytes(seq))
def crc32(seq): """Return the crc32 checksum for a sequence (string or Seq object). Note that the case is important: >>> crc32("ACGTACGTACGT") 20049947 >>> crc32("acgtACGTacgt") 1688586483 """ # NOTE - On Python 2 returns a signed int, on Python 3 it is unsigned # Docs suggest should use crc32(x) & 0xffffffff for consistency. # TODO - Should we return crc32(x) & 0xffffffff here? try: # Assume its a Seq object return _crc32(str(seq).encode()) except AttributeError: # Assume its a string/unicode return _crc32(seq.encode())
def crc32(*args): rt = _crc32(*args) return rt - ((rt & 0x80000000) << 1)
def crc32(raw, start=0): return 0xFFFFFFFF & _crc32(raw, start)
def modexp ( g, u, p ): """computes s = (g ^ u) mod p args are base, exponent, modulus (see Bruce Schneier's book, _Applied Cryptography_ p. 244)""" s = 1 while u != 0: if u & 1: s = (s * g)%p u >>= 1 g = (g * g)%p; return s # ------------------------ GENERAL PURPOSE UTILITIES ------------------------ # crc32 = lambda x: _crc32(str.encode(x)) & 0xffffffff def md5(text): m = _md5() m.update(str.encode(text)) return m.hexdigest() # ------------------------ JAM SPECIFIC FUNCTIONS --------------------------- # def read_file(fname): """Read input file format.""" with open(fname,"r") as f: lines = f.read().strip().split("\n")[1:] i = 0 res = [] while i < len(lines):