Пример #1
1
def all():
    print ""
    try:
        hash = raw_input(q)
    except:
        all()
    clear()
    m4 = hashlib.new("md4")
    m4.update(hash)
    md4 = m4.hexdigest()
    md5 = hashlib.md5(hash.encode()).hexdigest()
    sha1 = hashlib.sha1(hash.encode()).hexdigest()
    sha224 = hashlib.sha224(hash.encode()).hexdigest()
    sha384 = hashlib.sha384(hash.encode()).hexdigest()
    sha512 = hashlib.sha512(hash.encode()).hexdigest()
    sha256 = hashlib.sha256(hash.encode()).hexdigest()
    m = hashlib.new("ripemd160")
    m.update(hash)
    ripemd160 = m.hexdigest()
    h = zlib.adler32(hash)
    adler32 = '%08X' % (h & 0xffffffff, )
    ss = zlib.crc32(hash)
    crc32 = '%08X' % (ss & 0xffffffff, )
    l = hashlib.new("whirlpool")
    l.update(hash)
    whirlpool = l.hexdigest()
    print "%s[%s*%s] %sMD4                %s: %s%s" % (R, Y, R, W, R, W, md4)
    print "%s[%s*%s] %sMD5                %s: %s%s" % (R, Y, R, W, R, W, md5)
    print "%s[%s*%s] %sSHA1               %s: %s%s" % (R, Y, R, W, R, W, sha1)
    print "%s[%s*%s] %sSHA224             %s: %s%s" % (R, Y, R, W, R, W,
                                                       sha224)
    print "%s[%s*%s] %sSHA256             %s: %s%s" % (R, Y, R, W, R, W,
                                                       sha256)
    print "%s[%s*%s] %sSHA384             %s: %s%s" % (R, Y, R, W, R, W,
                                                       sha384)
    print "%s[%s*%s] %sSHA512             %s: %s%s" % (R, Y, R, W, R, W,
                                                       sha512)
    print "%s[%s*%s] %sADLER32            %s: %s%s" % (R, y, R, w, R, w,
                                                       adler32.lower())
    print "%s[%s*%s] %sCRC32              %s: %s%s" % (R, y, R, w, R, w,
                                                       crc32.lower())
    print "%s[%s*%s] %sRipemd160          %s: %s%s" % (R, Y, R, W, R, W,
                                                       ripemd160)
    print "%s[%s*%s] %sWHIRLPOOL          %s: %s%s" % (R, Y, R, W, R, W,
                                                       whirlpool)
    from plib.hash import mysql323
    mysql1323 = mysql323.encrypt(hash)
    print "%s[%s*%s] %sMYSQL323           %s: %s%s" % (R, Y, R, W, R, W,
                                                       mysql1323)
    from plib.hash import mysql41
    mysql141 = mysql41.encrypt(hash)
    print "%s[%s*%s] %sMYSQL41            %s: %s%s" % (R, Y, R, W, R, W,
                                                       mysql141)
    from plib.hash import mssql2000 as m20
    mssql2000 = m20.encrypt(hash)
    print "%s[%s*%s] %sMSSQL 2000         %s: %s%s" % (R, Y, R, W, R, W,
                                                       mssql2000)
    from plib.hash import mssql2005 as m25
    mssql2005 = m25.encrypt(hash)
    print "%s[%s*%s] %sMSSQL 2005         %s: %s%s" % (R, Y, R, W, R, W,
                                                       mssql2005)
    from plib.hash import des_crypt
    des = des_crypt.encrypt(hash)
    print "%s[%s*%s] %sDES                %s: %s%s" % (R, Y, R, W, R, W, des)
    from plib.hash import bsdi_crypt
    bsdi = bsdi_crypt.encrypt(hash)
    print "%s[%s*%s] %sBSDI Crypt         %s: %s%s" % (R, Y, R, W, R, W, bsdi)
    from plib.hash import bigcrypt
    big = bigcrypt.encrypt(hash)
    print "%s[%s*%s] %sBig Crypt          %s: %s%s" % (R, Y, R, W, R, W, big)
    from plib.hash import crypt16
    crypt16 = crypt16.encrypt(hash)
    print "%s[%s*%s] %sCrypt 16           %s: %s%s" % (R, Y, R, W, R, W,
                                                       crypt16)
    from plib.hash import md5_crypt as mc
    md5_crypt = mc.encrypt(hash)
    print "%s[%s*%s] %sMD5 Crypt          %s: %s%s" % (R, Y, R, W, R, W,
                                                       md5_crypt)
    from plib.hash import sha1_crypt as mc
    sha1_crypt = mc.encrypt(hash)
    print "%s[%s*%s] %sSHA1 Crypt         %s: %s%s" % (R, Y, R, W, R, W,
                                                       sha1_crypt)
    from plib.hash import sha256_crypt as mc
    sha256_crypt = mc.encrypt(hash)
    print "%s[%s*%s] %sSHA256 Crypt       %s: %s%s" % (R, Y, R, W, R, W,
                                                       sha256_crypt)
    from plib.hash import sha512_crypt as mc
    sha512_crypt = mc.encrypt(hash)
    print "%s[%s*%s] %sSHA512 Crypt       %s: %s%s" % (R, Y, R, W, R, W,
                                                       sha512_crypt)
    from plib.hash import sun_md5_crypt as mc
    sun_md5_crypt = mc.encrypt(hash)
    print "%s[%s*%s] %sSun MD5 Crypt      %s: %s%s" % (R, Y, R, W, R, W,
                                                       sun_md5_crypt)
    from plib.hash import apr_md5_crypt as mc
    apr_md5_crypt = mc.encrypt(hash)
    print "%s[%s*%s] %sApr MD5 Crypt      %s: %s%s" % (R, Y, R, W, R, W,
                                                       apr_md5_crypt)
    from plib.hash import phpass as mc
    phpass = mc.encrypt(hash)
    print "%s[%s*%s] %sPHPASS             %s: %s%s" % (R, Y, R, W, R, W,
                                                       phpass)
    from plib.hash import cta_pbkdf2_sha1 as mc
    cta_pbkdf2_sha1 = mc.encrypt(hash)
    print "%s[%s*%s] %sCTA PBKDF2 SHA1    %s: %s%s" % (R, Y, R, W, R, W,
                                                       cta_pbkdf2_sha1)
    from plib.hash import dlitz_pbkdf2_sha1 as mc
    dlitz_pbkdf2_sha1 = mc.encrypt(hash)
    print "%s[%s*%s] %sDLITZ PBKDF2 SHA1  %s: %s%s" % (R, Y, R, W, R, W,
                                                       dlitz_pbkdf2_sha1)
    from plib.hash import django_pbkdf2_sha1 as m25
    django_sha1 = m25.encrypt(hash)
    print "%s[%s*%s] %sDjango SHA1        %s: %s%s" % (R, Y, R, W, R, W,
                                                       django_sha1)
    from plib.hash import django_pbkdf2_sha256 as m25
    django_sha256 = m25.encrypt(hash)
    print "%s[%s*%s] %sDjango SHA256      %s: %s%s" % (R, Y, R, W, R, W,
                                                       django_sha256)
    from plib.hash import grub_pbkdf2_sha512 as m25
    grup_pbkdf2_sha512 = m25.encrypt(hash)
    print "%s[%s*%s] %sGrup PBKDF2 SHA512 %s: %s%s" % (R, Y, R, W, R, W,
                                                       grup_pbkdf2_sha512)
    s()
    os.system(
        'echo "" | busybox timeout -t 3 termux-clipboard-set 2>/dev/null && busybox timeout -t 5 termux-toast "ADM-ngentot | KONTOL-MEMEK | DICK" 2>/dev/null'
    )
    sys.exit()
Пример #2
0
    def get_ea(self, url):
        """ Download exit nodes, check if there are changes """

        print "Pulling current TOR exit nodes..."

        try:
            response = urllib2.urlopen(url)
        except urllib2.HTTPError:
            print "TORcheck unavailable"
            exit(1)
        except Exception as e:
            print "Exception: %s" % e
            exit(1)

        self.ea_list = response.read()
        response.close()

        ea_file_adler32 = 0
        if os.path.exists(self.conf["ea_file"]):
            try:
                with open(self.conf["ea_file"], "r") as f:
                    ea_file_adler32 = adler32(f.read())
            except Exception as e:
                print "Exception: %s" % e
                exit(1)

        if ea_file_adler32 == adler32(self.ea_list):
            print "Exit address list not changed, exiting"
            exit(0)

        print "TOR exit node list downloaded"
Пример #3
0
	def __init__(self,x,y,terrain,ptype,feature,owner,area,visible,values,hints,scale):
		Plot.__init__(self,x,y,visible,terrain,owner);

		self.ptype = ptype
		self.feature = feature
		self.area = area
		self.values = values
		self.hints = hints

		if (self.owner!=-1):
			color_owner = pg.Color("#FF00FF")
			color_owner.hsva = ( zlib.adler32("%08d"%self.owner) % 360, 100, 100, 100 )
		else:
			color_owner = None

		color_area = pg.Color("#FF00FF")
		color_area.hsva = ( zlib.adler32("%08d"%self.area) % 360, 100, 100, 100 )

		self.color_values = [color_owner,color_area]

		assert( len(self.values)==len(scale) )
		gray = [int(255.*v/s) for v,s in zip(self.values,scale)]
		for g in gray:
			if g<0:
				if self.values[0]<0:
					self.color_values.append( pg.Color(128,0,128) ) #blocked
				else:
					self.color_values.append( pg.Color(-g,0,0) )
			else:
				self.color_values.append( pg.Color(0,+g,0) )
Пример #4
0
def sync_status(req):
    if not req.user:
        return HttpResponse(status=403)

    stats = db.stats.find_one()
    syncHash = 1  # Just used to refresh the dashboard page, until I get on the Angular bandwagon.
    conns = User.GetConnectionRecordsByUser(req.user)
    errorCodes = []
    for conn in conns:
        syncHash = zlib.adler32(bytes(conn.HasExtendedAuthorizationDetails()), syncHash)
        if not hasattr(conn, "SyncErrors"):
            continue
        for err in conn.SyncErrors:
            syncHash = zlib.adler32(bytes(str(err), "UTF-8"), syncHash)
            if "Code" in err and err["Code"] is not None and len(err["Code"]) > 0:
                errorCodes.append(err["Code"])
            else:
                errorCodes.append("SYS-" + err["Step"])

    sync_status_dict = {"NextSync": (req.user["NextSynchronization"].ctime() + " UTC") if "NextSynchronization" in req.user and req.user["NextSynchronization"] is not None else None,
                        "LastSync": (req.user["LastSynchronization"].ctime() + " UTC") if "LastSynchronization" in req.user and req.user["LastSynchronization"] is not None else None,
                        "Synchronizing": "SynchronizationWorker" in req.user,
                        "SynchronizationProgress": req.user["SynchronizationProgress"] if "SynchronizationProgress" in req.user else None,
                        "SynchronizationStep": req.user["SynchronizationStep"] if "SynchronizationStep" in req.user else None,
                        "SynchronizationWaitTime": None, # I wish.
                        "Errors": errorCodes,
                        "Hash": syncHash}

    if stats and "QueueHeadTime" in stats:
        sync_status_dict["SynchronizationWaitTime"] = (stats["QueueHeadTime"] - (datetime.utcnow() - req.user["NextSynchronization"]).total_seconds()) if "NextSynchronization" in req.user and req.user["NextSynchronization"] is not None else None

    return HttpResponse(json.dumps(sync_status_dict), mimetype="application/json")
Пример #5
0
 def __serialize_errors(self, resp):
     """reformat the error structure and add the error codes"""
     if not resp.get('errors'):
         return resp
     elif resp['errors'].get('global_error'):
         ge_message = resp['errors'].pop('global_error')
         resp['errors']['global_error'] = {
             'code': adler32(ge_message.encode('UTF-16')),
             'message': ge_message
         }
         return resp
     else:
         # compose field errors
         field_errors = {}
         for field in resp['errors']:
             field_errors[field] = {
                 'code': adler32(resp['errors'][field].encode('UTF-16')),
                 'message': resp['errors'][field]
             }
         resp['errors'] = {
             'fields': field_errors
         }
         # compose global_error
         if resp['errors'].get('global_error'):
             ge_message = resp['errors']['global_error']
             resp['errors']['global_error'] = {
                 'code': adler32(ge_message.encode('UTF-16')),
                 'message': ge_message
             }
         else:
             resp['errors']['global_error'] = {
                 'code': adler32(VALIDATION_ERROR_MESSAGE.encode('UTF-16')),
                 'message': VALIDATION_ERROR_MESSAGE
             }
         return resp
Пример #6
0
def UnpackState(packed_state):
  """Convert a packed State binary string into a StateStruct object. If the
  input doesn't have the STATE_MARK_ZIP prefix, it is assumed to be an old-style
  compressed state object, and is directly decompressed.

  Args:
    packed_state - Binary string of the type produces by PackState.

  Returns:
    Populated StateStruct object.
  """
  if not packed_state:
    return None

  if ord(packed_state[0]) == STATE_MARK_ZIP:
    # Extract the meta-data Struct from the packed data.
    meta = StateMeta()
    meta.Deserialize(packed_state)

    # Extract the compressed State from the packed data.
    compressed_state = packed_state[meta.Size():]

    # Compute the checksum and make sure it matches the metadata.
    cksum = zlib.adler32(compressed_state)
    if cksum != meta.checksum:
      raise ValueError('Compressed State Checksum Error')

    # Return the decompressed State.
    return pickle.loads(zlib.decompress(compressed_state))

  elif ord(packed_state[0]) == STATE_MARK_SNAPPY:
    # Extract the meta-data Struct from the packed data.
    meta = StateMeta()
    meta.Deserialize(packed_state)

    # Extract the compressed State from the packed data.
    compressed_state = packed_state[meta.Size():]

    # Compute the checksum and make sure it matches the metadata.
    cksum = zlib.adler32(compressed_state)
    if cksum != meta.checksum:
      raise ValueError('Compressed State Checksum Error')

    # Return the decompressed State.
    return pickle.loads(snappy.decompress(compressed_state))

  elif ord(packed_state[0]) == STATE_MARK_LIGHT:
    # Extract the meta-data Struct from the packed data.
    meta = StateMeta()
    meta.Deserialize(packed_state)

    # Extract the State buffer from the packed data.
    state_buffer = packed_state[meta.Size():]

    # Return the decompressed State.
    return pickle.load(state_buffer)

  else:
    # Unsupported format.
    raise ValueError('Unrecognized State serialization format')
Пример #7
0
 def test_crc32_adler32_unsigned(self):
     foo = 'abcdefghijklmnop'
     # explicitly test signed behavior
     self.assertEqual(zlib.crc32(foo), 2486878355)
     self.assertEqual(zlib.crc32('spam'), 1138425661)
     self.assertEqual(zlib.adler32(foo+foo), 3573550353)
     self.assertEqual(zlib.adler32('spam'), 72286642)
Пример #8
0
 def get_in_rcaches(self, s1, s2):
     try:
         return self.__rcaches[ self.ctype ][ zlib.adler32( s1 + s2 ) ]
     except KeyError:
         try:
             return self.__rcaches[ self.ctype ][ zlib.adler32( s2 + s1 ) ]
         except KeyError:
             return -1, -1
Пример #9
0
    def test_penguins(self):
        ##self.assertEqual32(zlib.crc32("penguin", 0), 0x0e5c1a120L)
        self.assertEqual32(zlib.crc32("penguin", 1), 0x43b6aa94)
        ##self.assertEqual32(zlib.adler32("penguin", 0), 0x0bcf02f6)
        self.assertEqual32(zlib.adler32("penguin", 1), 0x0bd602f7)

        ##self.assertEqual(zlib.crc32("penguin"), zlib.crc32("penguin", 0))
        self.assertEqual(zlib.adler32("penguin"),zlib.adler32("penguin",1))
Пример #10
0
 def test_abcdefghijklmnop(self):
     """test issue1202 compliance: signed crc32, adler32 in 2.x"""
     foo = 'abcdefghijklmnop'
     # explicitly test signed behavior
     self.assertEqual(zlib.crc32(foo), -1808088941)
     self.assertEqual(zlib.crc32('spam'), 1138425661)
     self.assertEqual(zlib.adler32(foo+foo), -721416943)
     self.assertEqual(zlib.adler32('spam'), 72286642)
Пример #11
0
def copy(original, destination, purge=settings.PURGE_OLD_FILES, replace_files=True):
    """
    Do the file copying with all the appropriate error checking. Don't replace 
    an existing file if ``replace_files`` is ``False``
    
    :param original:
        The path to the original file/directory
    :type original: 
        ``string``
    :param destination: 
        The path to the destination file/directory
    :type destination: 
        ``string``
    :param purge:
        Should directories be emptied before copying. **Default:** ``settings.PURGE_OLD_FILES``
    :type purge:
        ``bool``
    :param replace_files:
        Should existing files be over-written (``True``) or kept (``False``). 
        Whole directories will *not* be over-written. Each file within a directory
        will be evaluated. **Default:** ``True``
    :type replace_files:
        ``bool``
    """
    if not os.path.exists(original):
        print "Can't access %s or it doesn't exist." % original
        return
    
    if os.path.basename(original) and os.path.basename(original)[0] == '.':
        print "Skipping the hidden item " % original
        return
    
    # If original is a file, copy it over
    if os.path.isfile(original):
        if os.path.isdir(destination):
            dst_file = os.path.join(destination, os.path.basename(original))
        else:
            dst_file = destination
        if os.path.exists(dst_file) and replace_files:
            src_chksum = zlib.adler32(open(original, 'rb').read())
            dst_chksum = zlib.adler32(open(dst_file, 'rb').read())
            if src_chksum != dst_chksum:
                print "Replacing %s" % dst_file
                shutil.copy2(original, dst_file)
    
    # if original is a directory, check for an existing directory
    # Empty it out if configured
    if os.path.isdir(original):
        if os.path.exists(destination) and purge:
            print "Purging %s" % destination
            shutil.rmtree(destination)
            os.makedirs(destination)
        elif os.path.exists(destination) and not os.path.isdir(destination):
            print "The destination (%s) for directory %s is a file instead of a directory." % (destination, original)
            return
        elif not os.path.exists(destination):
            os.makedirs(destination)
        copydir(original, destination, replace_files)
Пример #12
0
def checksumfile(fs, path):
    """Compute adler32 checksum of file."""
    value = zlib.adler32("")

    with fs.open(path, "rb") as f:
        for data in f:
            value = zlib.adler32(data, value)

    return value
Пример #13
0
    def test_penguins(self):
        self.assertEqual32(zlib.crc32("penguin", 0), 0x0e5c1a120L)
        self.assertEqual32(zlib.crc32("penguin", 1), 0x43b6aa94)
        if not test_support.is_jython:
            self.assertEqual32(zlib.adler32("penguin", 0), 0x0bcf02f6)
        self.assertEqual32(zlib.adler32("penguin", 1), 0x0bd602f7)

        self.assertEqual(zlib.crc32("penguin"), zlib.crc32("penguin", 0))
        self.assertEqual(zlib.adler32("penguin"),zlib.adler32("penguin",1))
Пример #14
0
 def checksum(self, include_metas=True):
     # TODO: zlib.adler32 does not work for numpy arrays with dtype object
     # (after pickling and unpickling such arrays, checksum changes)
     # Why, and should we fix it or remove it?
     """Return a checksum over X, Y, metas and W."""
     cs = zlib.adler32(self.X)
     cs = zlib.adler32(self.Y, cs)
     if include_metas:
         cs = zlib.adler32(self.metas, cs)
     cs = zlib.adler32(self.W, cs)
     return cs
Пример #15
0
def hashkey_fast(obj, salt=0):
    """Optimized version of :py:func:`~.hashkey`"""
    if obj.__class__ in hashkey_fast.types:
        if obj.__class__ is str:
            return zlib.adler32(obj.encode(), salt) & 0xffffffff
        elif obj.__class__ is bytes:
            return zlib.adler32(obj, salt) & 0xffffffff
        # must be datetime_type
        else:
            return zlib.adler32(str(obj).encode(), salt) & 0xffffffff
    return hash(obj) & 0xffffffff
Пример #16
0
	def read(self):
		self._ini.read(config_file)

		if self.conn_mode == Config.CONN_MODE_LOGIN:
			ah = '%08X' % (zlib.adler32((((((((((('')))))))))).encode()) & 0xFFFFFFFF)
		else:
			ah = '%08X' % (zlib.adler32(self.cert_file_content.encode()) & 0xFFFFFFFF)

		if self.get('AMI', 'hash') != ah:

			self.set('AMI', 'jsid', '')
			self.set('AMI', 'hash', ah)
Пример #17
0
    def add_module(self, ref, text, format=None,
                   expect_modulename=None, expect_revision=None,
                   expect_failure_error=True):
        """Parse a module text and add the module data to the context

        `ref` is a string which is used to identify the source of
              the text for the user.  used in error messages
        `text` is the raw text data
        `format` is one of 'yang' or 'yin'.

        Returns the parsed and validated module on success, and None on error.
        """
        if format == None:
            format = util.guess_format(text)

        if format == 'yin':
            p = yin_parser.YinParser()
        else:
            p = yang_parser.YangParser()

        module = p.parse(self, ref, text)
        if module is None:
            return None

        if expect_modulename is not None and expect_modulename != module.arg:
            if expect_failure_error:
                error.err_add(self.errors, module.pos, 'BAD_MODULE_NAME',
                              (module.arg, ref, expect_modulename))
                return None
            else:
                error.err_add(self.errors, module.pos, 'WBAD_MODULE_NAME',
                              (module.arg, ref, expect_modulename))
        latest_rev = util.get_latest_revision(module)
        if expect_revision is not None:
            if expect_revision != latest_rev:
                if expect_failure_error:
                    error.err_add(self.errors, module.pos, 'BAD_REVISION',
                                  (latest_rev, ref, expect_revision))
                    return None
                else:
                    error.err_add(self.errors, module.pos, 'WBAD_REVISION',
                                  (latest_rev, ref, expect_revision))

        if module.arg not in self.revs:
            self.revs[module.arg] = []
            revs = self.revs[module.arg]
            revs.append((latest_rev, None))

        if sys.version < '3':
            module.i_adler32 = zlib.adler32(text)
        else:
            module.i_adler32 = zlib.adler32(text.encode('UTF-8'))
        return self.add_parsed_module(module)
Пример #18
0
    def calc_hash(self):

        if self.list_choice == "File":
            if os.path.isfile(self.filename):
                # read() from file as bytes
                txt = open(self.filename, 'rb').read()
            else:
                # No such file, warning
                self.filename = ''
                messagebox.showinfo('Error', 'File not found !\n' + self.entry.get())
                return
        elif self.list_choice == "Text":
            txt = self.entry.get().encode()

        self.enable_entry()
        self.clear_fields()
        print(self.list_choice)
        # algorithms_guaranteed
        self.entryMd5.insert(0, hlb.md5(txt).hexdigest())
        self.entrySha1.insert(0, hlb.sha1(txt).hexdigest())
        self.entrySha224.insert(0, hlb.sha224(txt).hexdigest())
        self.entrySha256.insert(0, hlb.sha256(txt).hexdigest())
        self.entrySha384.insert(0, hlb.sha384(txt).hexdigest())
        self.entrySha512.insert(0, hlb.sha512(txt).hexdigest())

        # algorithms_not_guaranteed
        # Collisions might occur

        # Using the same object initialized in __init__ method results in unsecured hashes.
        # So initialize objects each time
        self.init_insecure_hashes()

        # ripemd160
        self.ripe.update(txt)
        self.entryRipeMd.insert(0, self.ripe.hexdigest())
        # md4
        self.md4.update(txt)
        self.entryMd4.insert(0, self.md4.hexdigest())
        # whirlpool
        self.whirl.update(txt)
        self.entryWhirl.insert(0, self.whirl.hexdigest())
        # dsa
        self.dsa.update(txt)
        self.entryDsa.insert(0, self.dsa.hexdigest())

        # Starting from index 2 to get rid of the '0x'
        # crc32
        self.entryCrc.insert(0, (8 - len(hex(crc32(txt))[2:])) * '0' + hex(crc32(txt))[2:])
        # adler32
        self.entryAdler.insert(0, (8 - len(hex(adler32(txt))[2:])) * '0' + hex(adler32(txt))[2:])

        self.disable_entry()
Пример #19
0
def format_article(art, **response_args):
    art["X-FromName"], art["X-FromEmail"] = parseaddr(art["From"] if "From" in art else "")
    if art["X-FromName"] == '': art["X-FromName"] = art["X-FromEmail"]

    date = mktime_tz(parsedate_tz(art["Date"]))
    if date < time.time() - 120:
        title = "\x0314In \x0F\x03{0:02d}{Newsgroups}\x0F\x0314: on \x0F{Date}\x0314 by \x0F\x03{0:02d}{X-FromName}\x0F \x02{Subject}\x0F"
    else:
        title = "\x0314In \x0F\x03{0:02d}{Newsgroups}\x0F\x0314: by \x0F\x03{0:02d}{X-FromName}\x0F \x02{Subject}\x0F"

    return Response(art.get_payload().replace('\n', ' '),
                    title=title.format(adler32(art["Newsgroups"].encode()) & 0xf, adler32(art["X-FromEmail"].encode()) & 0xf, **{h: decode_header(i) for h,i in art.items()}),
                    **response_args)
	def _execute_cb(self, goal):
		rospy.loginfo('Received a new request to start behavior: %s' % goal.behavior_name)
		try:
			be_id, behavior = next((id, be) for (id, be) in self._behavior_lib.items() if be["name"] == goal.behavior_name)
		except Exception as e:
			rospy.logwarn("Did not find behavior with requested name: %s" % goal.behavior_name)
			self._as.set_preempted()
			return

		be_selection = BehaviorSelection()
		be_selection.behavior_id = be_id
		be_selection.autonomy_level = 255
		be_selection.arg_keys = goal.arg_keys
		be_selection.arg_values = goal.arg_values

		be_structure = ContainerStructure()
		be_structure.containers = self._create_behavior_structure(goal.behavior_name)

		be_filepath_new = os.path.join(self._rp.get_path(behavior["package"]), 'src/' + behavior["package"] + '/' + behavior["file"] + '.py')
		with open(be_filepath_new, "r") as f:
			be_content_new = f.read()

		be_filepath_old = os.path.join(self._rp.get_path(behavior["package"]), 'src/' + behavior["package"] + '/' + behavior["file"] + '_tmp.py')
		if not os.path.isfile(be_filepath_old):
			be_selection.behavior_checksum = zlib.adler32(be_content_new)
		else:
			with open(be_filepath_old, "r") as f:
				be_content_old = f.read()

			sqm = difflib.SequenceMatcher(a=be_content_old, b=be_content_new)
			diffs = [x[1] for x in sqm.get_grouped_opcodes(0)]
			for opcode, a0, a1, b0, b1 in diffs:
				content = be_content_new[b0:b1]
				be_selection.modifications.append(BehaviorModification(a0, a1, content))

			be_selection.behavior_checksum = zlib.adler32(be_content_new)

		self._pub.publish(be_selection)
		self._behavior_running = True

		rate = rospy.Rate(10)
		while self._behavior_running and not rospy.is_shutdown():
			if self._current_state is not None:
				self._as.publish_feedback(BehaviorExecutionFeedback(self._current_state))
				self._current_state = None

			rate.sleep()

		rospy.loginfo('Finished behavior execution!')
		self._as.set_succeeded('')
Пример #21
0
	def create_company_office(self,cursor):
		"""docstring for create_company_office"""
		print "Company office attribute creation"
		query = "SELECT company_id, country_code FROM company_office"
		cursor.execute(query)
		
		for row in cursor.fetchall():
			try:
				self.data[row[0] - 1,6] = zlib.adler32(str(row[1]))
			except IndexError:
				self.data = np.concatenate( (self.data, np.zeros( (self.num_company, 1) ) ) ,1 )
				self.data[row[0] - 1,6] = zlib.adler32(str(row[1]))
		
		print "\t...Done"
Пример #22
0
	def parse_raw(cls, data):
		# bail early if there is not enough data
		if len(data) < cls.header_size:
			raise ACPMessageError("need to pass at least {0} bytes".format(cls.header_size))
		header_data = data[:cls.header_size]
		# make sure there's data beyond the header before we try to access it
		body_data = data[cls.header_size:] if len(data) > cls.header_size else None
		
		(magic, version, header_checksum, body_checksum, body_size, flags, unused, command, error_code, key) = cls._header_format.unpack(header_data)
		logging.debug("ACP message header fields, parsed not validated")
		logging.debug("magic           {0!r}".format(magic))
		logging.debug("header_checksum {0:#x}".format(header_checksum))
		logging.debug("body_checksum   {0:#x}".format(body_checksum))
		logging.debug("body_size       {0:#x}".format(body_size))
		logging.debug("flags           {0:#x}".format(flags))
		logging.debug("unused          {0:#x}".format(unused))
		logging.debug("command         {0:#x}".format(command))
		logging.debug("error_code      {0:#x}".format(error_code))
		logging.debug("key             {0!r}".format(key))
		
		if magic != cls._header_magic:
			raise ACPMessageError("bad header magic")
		
		if version not in [0x00000001, 0x00030001]:
			raise ACPMessageError("invalid version")
		
		#TODO: can we zero the header_checksum field without recreating the struct (how?)
		tmphdr = cls._header_format.pack(magic, version, 0, body_checksum, body_size, flags, unused, command, error_code, key)
		if header_checksum != zlib.adler32(tmphdr):
			raise ACPMessageError("header checksum does not match")
		
		if body_data and body_size == -1:
			raise ACPMessageError("cannot handle stream header with data attached")
		
		if body_data and body_size != len(body_data):
			raise ACPMessageError("message body size does not match available data")
		
		if body_data and body_checksum != zlib.adler32(body_data):
			raise ACPMessageError("body checksum does not match")
		
		#TODO: check flags
		
		#TODO: check status
		
		if command not in [1, 3, 4, 5, 6, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b]:
			raise ACPMessageError("unknown command")
		
		#TODO: check error code
		
		return cls(version, flags, unused, command, error_code, key, body_data, body_size)
Пример #23
0
def setup_training_environment(args, ttns, training_stats):
    train_stack_param_names = [
        str(e) for e in ttns.train_stack_config.updatable_parameters()]

    test_stack_param_names = [
        str(e) for e in ttns.test_stack_config.updatable_parameters()]

    # Assert that train_stack and test_stack are perfectly aligned so
    # that zipping them would do the right thing.
    for trv, tev in map(lambda x, y: (x, y), train_stack_param_names, test_stack_param_names):
        assert tev.startswith(re.match(r'^(.*_)\d+$', trv).group(1))

    # Populate two maps.
    train_test_map = dict(zip(train_stack_param_names, test_stack_param_names))
    train_hash_map = dict((e, zlib.adler32(ttns.train_stack_config[e].get_value()))
                          for e in train_stack_param_names)
    print 'Epoch:', training_stats['epoch_id'], \
        'Learning Rate', training_stats['clr']
    #---#
    yield
    #---#
    if args.verbose >= 2:
        param_copy_str = ', '.join('%s -> %s'%(str(trv), str(tev))
                                   for trv, tev
                                   in train_test_map.items())
        print 'Copying parameters', param_copy_str
    # Based on the trained parameters. Update the parameters of the
    # testing model.
    for trv, tev in train_test_map.items():
        # Assert that trained parameters actually changed.
        trv_new_hash = zlib.adler32(ttns.train_stack_config[trv].get_value())
        assert trv_new_hash != train_hash_map[trv], (
            'This assertion checks that during each training epoch, the neural '
            'network parameters actually change. If the neural net parameters '
            'do not change in one epoch, then we raise as assertion error '
            'to stop the training loop.')
        
        if hasattr(ttns.train_stack_config[trv], 'dropout_retention_freq'):
            retention_freq = ttns.train_stack_config[trv].dropout_retention_freq
            ttns.test_stack_config[tev].set_value(
                ttns.train_stack_config[trv].get_value()
                * retention_freq)
        else:
            ttns.test_stack_config[tev].set_value(
                ttns.train_stack_config[trv].get_value())
            assert (zlib.adler32(ttns.test_stack_config[tev].get_value())
                    == trv_new_hash)
    pass
Пример #24
0
    def UpdateChecksum(self):
        """Recalculate the checksum field."""
        self.size = self.next.v() - self.obj_offset
        data = self.obj_vm.read(
            self.obj_offset, self.checksum.obj_offset - self.obj_offset)

        self.checksum = zlib.adler32(data)
Пример #25
0
 def __send(self, fx, lang, fn, data):
     """
     Private method to send a job request to one of the clients.
     
     @param fx remote function name to execute (str)
     @param lang language to connect to (str)
     @param fn filename for identification (str)
     @param data function argument(s) (any basic datatype)
     """
     connection = self.connections.get(lang)
     if connection is None:
         if fx != 'INIT':
             # Avoid growing recursion deep which could itself result in an
             # exception
             QTimer.singleShot(
                 0,
                 lambda: self.serviceNotAvailable.emit(
                     fx, lang, fn, self.tr(
                         '{0} not configured.').format(lang)))
         # Reset flag and continue processing queue
         self.isWorking = None
         self.__processQueue()
     else:
         packedData = json.dumps([fx, fn, data])
         if sys.version_info[0] == 3:
             packedData = bytes(packedData, 'utf-8')
         header = struct.pack(
             b'!II', len(packedData), adler32(packedData) & 0xffffffff)
         connection.write(header)
         connection.write(packedData)
Пример #26
0
def normalize_fasta(fastaFile, refFile, outFile):
    f = FastaReader(fastaFile)
    recs = []
    with open(outFile, "w") as of:
        for r in f:
            r_id = "%s" %  hex(zlib.adler32(r.name + r.sequence) & 0xffffffff)
            print >>of, ">"+r_id
            seq = r.sequence.upper()
            print >>of, seq 


    output = subprocess.check_output("blasr -bestn 1 -m 1 %s %s" % ( outFile, refFile ), shell=True)
    direction = {}
    output = output.strip().split("\n")
    for l in output:
        l = l.strip().split()
        rId = l[0].split("/")[0]
        if l[2] != l[3]:
            direction[rId] = "-"
        else:
            direction[rId] = "+"

    f = FastaReader(outFile)
    outData = []
    for r in f:
        r_id = "%s" % r.name
        outData.append(">"+r_id)
        seq = r.sequence.upper()
        if direction != None:
            if direction.get(r_id, "+") != "+":
                seq = "".join([rmap[c] for c in seq[::-1]])
        outData.append(seq)
    with open(outFile,"w") as of:
        print >>of, "\n".join(outData)
Пример #27
0
    def generate_uml_image(self, abs_target_dir, plantuml_code):
        print "Generating image"
        
        plantuml_code = plantuml_code.encode('utf8')
        tf = tempfile.NamedTemporaryFile(delete=False)
        tf.write('@startuml\n'.encode('utf8'))
        tf.write(plantuml_code)
        tf.write('\n@enduml'.encode('utf8'))
        tf.flush()
        #print "uml_code" + plantuml_code
        #print "tfname " + tf.name
        imgext = '.png'

        pl = plantuml.PlantUML()

        newname = os.path.join(abs_target_dir, "%08x" % (adler32(plantuml_code) & 0xffffffff))+imgext

        if os.path.exists(newname):
            os.remove(newname)

        if pl.processes_file(tf.name, newname):
            os.remove(tf.name)
            return os.path.basename(newname)
        else:
            # the temporary file is still available as aid understanding errors
            raise RuntimeError('Error in "uml" directive')
Пример #28
0
	def _write_key_sect(self, outfile):
		# Writes the key section header, key block index, and all the key blocks to
		# outfile.
		
		# outfile: a file-like object, opened in binary mode.
		
		keyblocks_total_size = sum(len(b.get_block()) for b in self._key_blocks)
		if self._version == "2.0":
			preamble = struct.pack(b">QQQQQ",
			    len(self._key_blocks),
			    self._num_entries,
			    self._keyb_index_decomp_size,
			    self._keyb_index_comp_size,
			    keyblocks_total_size)
			preamble_checksum = struct.pack(b">L", zlib.adler32(preamble))
			if(self._encrypt):
				preamble = _salsa_encrypt(preamble, self._encrypt_key)
			outfile.write(preamble)
			outfile.write(preamble_checksum)
		else:
			preamble = struct.pack(b">LLLL",
			    len(self._key_blocks),
			    self._num_entries,
			    self._keyb_index_decomp_size,
			    keyblocks_total_size)
			if(self._encrypt):
				preamble = _salsa_encrypt(preamble, self._encrypt_key)
			outfile.write(preamble)
		
		outfile.write(self._keyb_index)
		for b in self._key_blocks:
			outfile.write(b.get_block())
Пример #29
0
	def _compose_header(self):
		"""Compose the message header
		
		Returns:
			String containing header data
		
		"""
		tmphdr = self._header_format.pack(self._header_magic,
		                                  self.version,
		                                  0,
		                                  self.body_checksum,
		                                  self.body_size,
		                                  self.flags,
		                                  self.unused,
		                                  self.command,
		                                  self.error_code,
		                                  self.key)
		
		header = self._header_format.pack(self._header_magic,
		                                  self.version,
		                                  zlib.adler32(tmphdr),
		                                  self.body_checksum,
		                                  self.body_size,
		                                  self.flags,
		                                  self.unused,
		                                  self.command,
		                                  self.error_code,
		                                  self.key)
		
		return header
Пример #30
0
def display(sphinx_id):

    db = oursql.connect(user='******', passwd='codesearch',
                        db='codesearch')

    cursor = db.cursor(oursql.DictCursor)
    query = 'SELECT project, path, text FROM documents WHERE id = ?'
    cursor.execute(query, (sphinx_id,))
    sourcecode = cursor.fetchone()
    if sourcecode is None:
        flask.abort(404)

    title = posixpath.join(sourcecode['project'], sourcecode['path'])

    try:
        lexer = get_lexer_for_filename(sourcecode['path'])
    except ClassNotFound:
        # Syntax highlighting not supported.'
        code = u'<pre>{}</pre>'.format(sourcecode['text'])
        return flask.render_template('display.html', title=title, code=code)

    formatter = HtmlFormatter()

    # Highlighting large files can be a slow operation. This is a candidate
    # for caching.
    checksum = zlib.adler32(sourcecode['text'])
    key = json.dumps(['HIGHLIGHT', checksum])
    code = cache.get(key)
    if code is None:
        code = highlight(sourcecode['text'], lexer, formatter)
        cache.set(key, code)

    return flask.render_template('display.html', title=title,
                                 code=code)
Пример #31
0
    def _decode_key_block(self, key_block_compressed, key_block_info_list):
        key_list = []
        i = 0
        for compressed_size, decompressed_size in key_block_info_list:
            start = i
            end = i + compressed_size
            # 4 bytes : compression type
            key_block_type = key_block_compressed[start:start+4]
            # 4 bytes : adler checksum of decompressed key block
            adler32 = unpack('>I', key_block_compressed[start+4:start+8])[0]
            if key_block_type == b'\x00\x00\x00\x00':
                key_block = key_block_compressed[start+8:end]
            elif key_block_type == b'\x01\x00\x00\x00':
                if lzo is None:
                    print("LZO compression is not supported")
                    break
                # decompress key block
                header = b'\xf0' + pack('>I', decompressed_size)
                key_block = lzo.decompress(header + key_block_compressed[start+8:end])
            elif key_block_type == b'\x02\x00\x00\x00':
                # decompress key block
                key_block = zlib.decompress(key_block_compressed[start+8:end])
            # extract one single key block into a key list
            key_list += self._split_key_block(key_block)
            # notice that adler32 returns signed value
            assert(adler32 == zlib.adler32(key_block) & 0xffffffff)

            i += compressed_size
        return key_list
Пример #32
0
 def generate_etag(self, mtime, file_size, real_filename):
     if not isinstance(real_filename, bytes):
         real_filename = real_filename.encode(sys.getfilesystemencoding())
     return 'wzsdm-%d-%s-%s' % (mktime(
         mtime.timetuple()), file_size, adler32(real_filename) & 0xffffffff)
Пример #33
0
 def __hash__(self):
     return adler32(str(self._board_state).encode('utf-8'))
Пример #34
0
 def setUp(self):
   self.rng = np.random.default_rng(zlib.adler32(self.__class__.__name__.encode()))
Пример #35
0
 def update(self, data):
     if self.accumulated == b'':
         self.accumulated = zlib.adler32(data)
     else:
         self.accumulated = zlib.adler32(data, self.accumulated)
Пример #36
0
 def calculateChecksum(self):
     oldChecksum = self.Checksum
     self.Checksum = 0
     bytes = self.__serialize__()
     self.Checksum = oldChecksum
     return zlib.adler32(bytes) & 0xffff
Пример #37
0
def generate_aid(entity_id):
    """Generate accessory aid with zlib adler32."""
    aid = adler32(entity_id.encode('utf-8'))
    if aid == 0 or aid == 1:
        return None
    return aid
Пример #38
0
                'filename': filename,
                'tags': list(tags),
                'modified': arrow.now().isoformat(),
                'title': title,
                'serial': serial,
            }
            # TODO: this is probably useless, candidate for removal
            for tag in tags:
                try:
                    db.db['tags'][tag].append(filename)
                except KeyError:
                    db.db['tags'][tag] = [filename]

    if edit:
        # get checksum of filename to compare after edition and check if there was a change
        crc = zlib.adler32(open(filename, 'br').read())
        subprocess.run([editor_binary, filename])
        if crc == zlib.adler32(open(filename, 'br').read()):
            log.info(f"no changes in {filename}")
        else:
            update_db(filename, title)
    else:
        # we did nto want to edit the file, just update the metadata in the database
        update_db(filename, title)


def ask_for_note() -> (str, str):
    """
    Ask the user for the note thay want to manage (edit, delete, ...)
    :return: a tuple (filename, title)
    """
Пример #39
0
def generate_id_from_name_and_version(name, version):
    return ctypes.c_long((adler32(name) << 32) | version).value
Пример #40
0
def computeChecksums(datum):
    return adler32(datum.encode("utf8")) & 0xFFFFFFFF
Пример #41
0
def calc_checksum(*args):
    '''
    Calculates the check sum of the given args
    '''
    checksum_string = "|".join(map(str,args))
    return adler32(checksum_string, 1) & 0xffffffff
Пример #42
0
def send_file(filename_or_fp, mimetype=None, as_attachment=False,
              attachment_filename=None, add_etags=True,
              cache_timeout=60 * 60 * 12, conditional=False):
    """Sends the contents of a file to the client.  This will use the
    most efficient method available and configured.  By default it will
    try to use the WSGI server's file_wrapper support.  Alternatively
    you can set the application's :attr:`~Flask.use_x_sendfile` attribute
    to ``True`` to directly emit an `X-Sendfile` header.  This however
    requires support of the underlying webserver for `X-Sendfile`.

    By default it will try to guess the mimetype for you, but you can
    also explicitly provide one.  For extra security you probably want
    to send certain files as attachment (HTML for instance).  The mimetype
    guessing requires a `filename` or an `attachment_filename` to be
    provided.

    Please never pass filenames to this function from user sources without
    checking them first.  Something like this is usually sufficient to
    avoid security problems::

        if '..' in filename or filename.startswith('/'):
            abort(404)

    .. versionadded:: 0.2

    .. versionadded:: 0.5
       The `add_etags`, `cache_timeout` and `conditional` parameters were
       added.  The default behaviour is now to attach etags.

    .. versionchanged:: 0.7
       mimetype guessing and etag support for file objects was
       deprecated because it was unreliable.  Pass a filename if you are
       able to, otherwise attach an etag yourself.  This functionality
       will be removed in Flask 1.0

    :param filename_or_fp: the filename of the file to send.  This is
                           relative to the :attr:`~Flask.root_path` if a
                           relative path is specified.
                           Alternatively a file object might be provided
                           in which case `X-Sendfile` might not work and
                           fall back to the traditional method.  Make sure
                           that the file pointer is positioned at the start
                           of data to send before calling :func:`send_file`.
    :param mimetype: the mimetype of the file if provided, otherwise
                     auto detection happens.
    :param as_attachment: set to `True` if you want to send this file with
                          a ``Content-Disposition: attachment`` header.
    :param attachment_filename: the filename for the attachment if it
                                differs from the file's filename.
    :param add_etags: set to `False` to disable attaching of etags.
    :param conditional: set to `True` to enable conditional responses.
    :param cache_timeout: the timeout in seconds for the headers.
    """
    mtime = None
    if isinstance(filename_or_fp, basestring):
        filename = filename_or_fp
        file = None
    else:
        from warnings import warn
        file = filename_or_fp
        filename = getattr(file, 'name', None)

        # XXX: this behaviour is now deprecated because it was unreliable.
        # removed in Flask 1.0
        if not attachment_filename and not mimetype \
           and isinstance(filename, basestring):
            warn(DeprecationWarning('The filename support for file objects '
                'passed to send_file is now deprecated.  Pass an '
                'attach_filename if you want mimetypes to be guessed.'),
                stacklevel=2)
        if add_etags:
            warn(DeprecationWarning('In future flask releases etags will no '
                'longer be generated for file objects passed to the send_file '
                'function because this behaviour was unreliable.  Pass '
                'filenames instead if possible, otherwise attach an etag '
                'yourself based on another value'), stacklevel=2)

    if filename is not None:
        if not os.path.isabs(filename):
            filename = os.path.join(current_app.root_path, filename)
    if mimetype is None and (filename or attachment_filename):
        mimetype = mimetypes.guess_type(filename or attachment_filename)[0]
    if mimetype is None:
        mimetype = 'application/octet-stream'

    headers = Headers()
    if as_attachment:
        if attachment_filename is None:
            if filename is None:
                raise TypeError('filename unavailable, required for '
                                'sending as attachment')
            attachment_filename = os.path.basename(filename)
        headers.add('Content-Disposition', 'attachment',
                    filename=attachment_filename)

    if current_app.use_x_sendfile and filename:
        if file is not None:
            file.close()
        headers['X-Sendfile'] = filename
        data = None
    else:
        if file is None:
            file = open(filename, 'rb')
            mtime = os.path.getmtime(filename)
        data = wrap_file(request.environ, file)

    rv = current_app.response_class(data, mimetype=mimetype, headers=headers,
                                    direct_passthrough=True)

    # if we know the file modification date, we can store it as the
    # the time of the last modification.
    if mtime is not None:
        rv.last_modified = int(mtime)

    rv.cache_control.public = True
    if cache_timeout:
        rv.cache_control.max_age = cache_timeout
        rv.expires = int(time() + cache_timeout)

    if add_etags and filename is not None:
        rv.set_etag('flask-%s-%s-%s' % (
            os.path.getmtime(filename),
            os.path.getsize(filename),
            adler32(filename) & 0xffffffff
        ))
        if conditional:
            rv = rv.make_conditional(request)
            # make sure we don't send x-sendfile for servers that
            # ignore the 304 status code for x-sendfile.
            if rv.status_code == 304:
                rv.headers.pop('x-sendfile', None)
    return rv
Пример #43
0
        if read_int(cd_start) != 0x02014b50:
            break
        file_name_length = read_short(cd_start + 28)
        extra_field_length = read_short(cd_start + 30)
        comment_length = read_short(cd_start + 32)
        adjust_offset(cd_start + 42)
        cd_start += 46 + file_name_length + extra_field_length + comment_length
        cd_count_actual += 1

    if cd_count_actual != cd_count_expected:
        print('[!] Only adjusted {} records but expected {}!'.format(
            cd_count_actual, cd_count_expected))
        exit(1)

    print('[+] Adjusted {} central directory records.'.format(cd_count_actual))

    print('[+] Fixing up combined data.')

    data = dex_data + data

    adler_start = 8
    sha1_start = 8 + 4
    file_length_start = sha1_start + 20
    write_int(file_length_start, len(data))
    write_bytes(sha1_start, sha1(data[file_length_start:]))
    write_int(adler_start, zlib.adler32(data[sha1_start:]))

    with open(out_apk_path, 'wb') as out_apk_file:
        out_apk_file.write(data)
    print('[+] Adjusted APK written to {}.'.format(out_apk_path))
Пример #44
0
 def __hash__(self):
     return zlib.adler32(self) ^ hash(self.unknowns)
Пример #45
0
def hash_buffer(view):
    '''Deterministic hash of the text in the buffer underlying a view'''
    whole_buffer_region = sublime.Region(0, view.size())
    text = view.substr(whole_buffer_region)
    text_bytes = bytes(text, 'UTF-8')
    return str(adler32(text_bytes) & 0xffffffff)
 def test_adler32start(self):
     self.assertEqual(zlib.adler32(""), zlib.adler32("", 1))
     self.assert_(zlib.adler32("abc", 0xffffffff))
 def test_adler32empty(self):
     self.assertEqual(zlib.adler32("", 0), 0)
     self.assertEqual(zlib.adler32("", 1), 1)
     self.assertEqual(zlib.adler32("", 432), 432)
Пример #48
0
def _checksum_Adler32(data, crc_init=-1, crc_poly=-1):
    return zlib.adler32(data)
Пример #49
0
 def checksum(self,seq_num_bin_str,data_bin):
     filled_data = string.join([string.zfill(n, 8) for n in map(lambda s: s[2:], map(bin, data_bin))], '')
     checksum = zlib.adler32(seq_num_bin_str + filled_data) & 0xffffffff
     return checksum
Пример #50
0
def myhash(x):
    return zlib.adler32(str(x).encode('utf-8'))
Пример #51
0
sentence = parse_file(file)
word_set = set()
nlp = spacy.load('en_core_web_sm', disable=['parser', 'ner'])
doc = nlp(sentence)
stop_list = ['.', ',', '\n']
for word in doc:
    if stop_list.__contains__(str(word)) is not True:
        word_set.add(str(word))
m = len(word_set)
n = math.ceil(7 * m / math.log(2))
k = math.floor(n/m * math.log(2))
bloom_filter = [0] * n
for doc_w in doc:
    word = str(doc_w)
    crc = zlib.crc32(bytes(word.encode())) % n
    adl = zlib.adler32(bytes(word.encode())) % n
    md5 = int(hashlib.md5(bytes(word.encode())).hexdigest(), 16) % (10 ** 8) % n
    sha = int(hashlib.sha1(bytes(word.encode())).hexdigest(), 16) % (10 ** 8) % n
    sha2 = int(hashlib.sha224(bytes(word.encode())).hexdigest(), 16) % (10 ** 8) % n
    sha3 = int(hashlib.sha384(bytes(word.encode())).hexdigest(), 16) % (10 ** 8) % n
    sha4 = int(hashlib.sha512(bytes(word.encode())).hexdigest(), 16) % (10 ** 8) % n
    bloom_filter[crc] = 1
    bloom_filter[adl] = 1
    bloom_filter[md5] = 1
    bloom_filter[sha] = 1
    bloom_filter[sha2] = 1
    bloom_filter[sha3] = 1
    bloom_filter[sha4] = 1


print(bloom_filter)
Пример #52
0
    def _checksum(self, data, ipv4_src, ipv4_dst):
        """
        Calculate and return the checksum (in raw bytes) of data.

        :param data Data on which to calculate checksum.
        :type data bytes

        :rtype:  bytes
        :return: Checksum.
        """
        if isinstance(self._algorithm, six.string_types):
            if self._algorithm == "crc32":
                check = struct.pack(self._endian + "L",
                                    (zlib.crc32(data) & 0xFFFFFFFF))

            elif self._algorithm == "crc32c":
                try:
                    import crc32c  # pytype: disable=import-error
                except ImportError:
                    warnings.warn(
                        "Importing crc32c package failed. Please install it using pip.",
                        UserWarning,
                        stacklevel=2)
                    raise
                check = struct.pack(self._endian + "L", crc32c.crc32(data))

            elif self._algorithm == "adler32":
                check = struct.pack(self._endian + "L",
                                    (zlib.adler32(data) & 0xFFFFFFFF))

            elif self._algorithm == "ipv4":
                check = struct.pack(self._endian + "H",
                                    helpers.ipv4_checksum(data))

            elif self._algorithm == "udp":
                return struct.pack(
                    self._endian + "H",
                    helpers.udp_checksum(msg=data,
                                         src_addr=ipv4_src,
                                         dst_addr=ipv4_dst))

            elif self._algorithm == "md5":
                digest = hashlib.md5(data).digest()

                # TODO: is this right?
                if self._endian == ">":
                    (a, b, c, d) = struct.unpack("<LLLL", digest)
                    digest = struct.pack(">LLLL", a, b, c, d)

                check = digest

            elif self._algorithm == "sha1":
                digest = hashlib.sha1(data).digest()

                # TODO: is this right?
                if self._endian == ">":
                    (a, b, c, d, e) = struct.unpack("<LLLLL", digest)
                    digest = struct.pack(">LLLLL", a, b, c, d, e)

                check = digest

            else:
                raise exception.SullyRuntimeError(
                    "INVALID CHECKSUM ALGORITHM SPECIFIED: %s" %
                    self._algorithm)
        else:
            check = self._algorithm(data)

        if self._length:
            return check[:self._length]
        else:
            return check
Пример #53
0
 def test_adler32start(self):
     self.assertEqual(zlib.adler32(""), zlib.adler32("", 1))
Пример #54
0
def dhash(*data):
    'Generates a random-looking deterministic hash'
    return abs(zlib.adler32(bytes(str(data),'UTF-8'))*111) * SEED % 0xffffffff
Пример #55
0
dtable = readtable.read(args.dtable[0])
level = args.level if args.level else -1

header, sections, dsCount = fparser.parse(source)

dest.write(xmap)
dest.write(version)
writeInt(dest, header['WorldID'][0][0], 2)
writeInt(dest, header['AreaID'][0][0], 2)
writeInt(dest, dsCount, 4)

for name, seclist in sections.items():
    for sec in seclist:
        bname = name.encode()
        if len(bname) != 4:
            fparser.error("Section names must be 4 bytes long. You put" + name)
        dest.write(bname)
        buf = maprules.handlers[name](sec, table=table, dtable=dtable)
        usize = len(buf)
        cbuf = zlib.compress(buf, level)
        csize = len(cbuf)
        if csize + 4 < usize:
            writeInt(dest, csize | 0x80000000, 4)
            writeInt(dest, usize, 4)
            writeInt(dest, zlib.adler32(cbuf), 4)
            dest.write(cbuf)
        else:
            writeInt(dest, usize, 4)
            writeInt(dest, zlib.adler32(buf), 4)
            dest.write(buf)
Пример #56
0
def send_file(filename_or_fp, mimetype=None, as_attachment=False,
              attachment_filename=None, add_etags=True,
              cache_timeout=None, conditional=False, last_modified=None):
    """Sends the contents of a file to the client.  This will use the
    most efficient method available and configured.  By default it will
    try to use the WSGI server's file_wrapper support.  Alternatively
    you can set the application's :attr:`~Flask.use_x_sendfile` attribute
    to ``True`` to directly emit an ``X-Sendfile`` header.  This however
    requires support of the underlying webserver for ``X-Sendfile``.

    By default it will try to guess the mimetype for you, but you can
    also explicitly provide one.  For extra security you probably want
    to send certain files as attachment (HTML for instance).  The mimetype
    guessing requires a `filename` or an `attachment_filename` to be
    provided.

    ETags will also be attached automatically if a `filename` is provided. You
    can turn this off by setting `add_etags=False`.

    If `conditional=True` and `filename` is provided, this method will try to
    upgrade the response stream to support range requests.  This will allow
    the request to be answered with partial content response.

    Please never pass filenames to this function from user sources;
    you should use :func:`send_from_directory` instead.

    .. versionadded:: 0.2

    .. versionadded:: 0.5
       The `add_etags`, `cache_timeout` and `conditional` parameters were
       added.  The default behavior is now to attach etags.

    .. versionchanged:: 0.7
       mimetype guessing and etag support for file objects was
       deprecated because it was unreliable.  Pass a filename if you are
       able to, otherwise attach an etag yourself.  This functionality
       will be removed in Flask 1.0

    .. versionchanged:: 0.9
       cache_timeout pulls its default from application config, when None.

    .. versionchanged:: 0.12
       The filename is no longer automatically inferred from file objects. If
       you want to use automatic mimetype and etag support, pass a filepath via
       `filename_or_fp` or `attachment_filename`.

    .. versionchanged:: 0.12
       The `attachment_filename` is preferred over `filename` for MIME-type
       detection.

    :param filename_or_fp: the filename of the file to send in `latin-1`.
                           This is relative to the :attr:`~Flask.root_path`
                           if a relative path is specified.
                           Alternatively a file object might be provided in
                           which case ``X-Sendfile`` might not work and fall
                           back to the traditional method.  Make sure that the
                           file pointer is positioned at the start of data to
                           send before calling :func:`send_file`.
    :param mimetype: the mimetype of the file if provided. If a file path is
                     given, auto detection happens as fallback, otherwise an
                     error will be raised.
    :param as_attachment: set to ``True`` if you want to send this file with
                          a ``Content-Disposition: attachment`` header.
    :param attachment_filename: the filename for the attachment if it
                                differs from the file's filename.
    :param add_etags: set to ``False`` to disable attaching of etags.
    :param conditional: set to ``True`` to enable conditional responses.

    :param cache_timeout: the timeout in seconds for the headers. When ``None``
                          (default), this value is set by
                          :meth:`~Flask.get_send_file_max_age` of
                          :data:`~flask.current_app`.
    :param last_modified: set the ``Last-Modified`` header to this value,
        a :class:`~datetime.datetime` or timestamp.
        If a file was passed, this overrides its mtime.
    """
    mtime = None
    fsize = None
    if isinstance(filename_or_fp, string_types):
        filename = filename_or_fp
        if not os.path.isabs(filename):
            filename = os.path.join(current_app.root_path, filename)
        file = None
        if attachment_filename is None:
            attachment_filename = os.path.basename(filename)
    else:
        file = filename_or_fp
        filename = None

    if mimetype is None:
        if attachment_filename is not None:
            mimetype = mimetypes.guess_type(attachment_filename)[0] \
                or 'application/octet-stream'

        if mimetype is None:
            raise ValueError(
                'Unable to infer MIME-type because no filename is available. '
                'Please set either `attachment_filename`, pass a filepath to '
                '`filename_or_fp` or set your own MIME-type via `mimetype`.'
            )

    headers = Headers()
    if as_attachment:
        if attachment_filename is None:
            raise TypeError('filename unavailable, required for '
                            'sending as attachment')
        headers.add('Content-Disposition', 'attachment',
                    filename=attachment_filename)

    if current_app.use_x_sendfile and filename:
        if file is not None:
            file.close()
        headers['X-Sendfile'] = filename
        fsize = os.path.getsize(filename)
        headers['Content-Length'] = fsize
        data = None
    else:
        if file is None:
            file = open(filename, 'rb')
            mtime = os.path.getmtime(filename)
            fsize = os.path.getsize(filename)
            headers['Content-Length'] = fsize
        data = wrap_file(request.environ, file)

    rv = current_app.response_class(data, mimetype=mimetype, headers=headers,
                                    direct_passthrough=True)

    if last_modified is not None:
        rv.last_modified = last_modified
    elif mtime is not None:
        rv.last_modified = mtime

    rv.cache_control.public = True
    if cache_timeout is None:
        cache_timeout = current_app.get_send_file_max_age(filename)
    if cache_timeout is not None:
        rv.cache_control.max_age = cache_timeout
        rv.expires = int(time() + cache_timeout)

    if add_etags and filename is not None:
        from warnings import warn

        try:
            rv.set_etag('%s-%s-%s' % (
                os.path.getmtime(filename),
                os.path.getsize(filename),
                adler32(
                    filename.encode('utf-8') if isinstance(filename, text_type)
                    else filename
                ) & 0xffffffff
            ))
        except OSError:
            warn('Access %s failed, maybe it does not exist, so ignore etags in '
                 'headers' % filename, stacklevel=2)

    if conditional:
        if callable(getattr(Range, 'to_content_range_header', None)):
            # Werkzeug supports Range Requests
            # Remove this test when support for Werkzeug <0.12 is dropped
            try:
                rv = rv.make_conditional(request, accept_ranges=True,
                                         complete_length=fsize)
            except RequestedRangeNotSatisfiable:
                file.close()
                raise
        else:
            rv = rv.make_conditional(request)
        # make sure we don't send x-sendfile for servers that
        # ignore the 304 status code for x-sendfile.
        if rv.status_code == 304:
            rv.headers.pop('x-sendfile', None)
    return rv
Пример #57
0
	def _callback(self, msg):
		try:
			be_id, behavior = next((id, be) for (id, be) in self._behavior_lib.items() if be["name"] == msg.behavior_name)
		except Exception as e:
			rospy.logwarn("Did not find behavior with requested name: %s" % msg.behavior_name)
			return

		rospy.loginfo("Request for behavior " + behavior["name"])

		be_selection = BehaviorSelection()
		be_selection.behavior_id = be_id
		be_selection.autonomy_level = msg.autonomy_level
		try:
			for k, v in zip(msg.arg_keys, msg.arg_values):
				if k.split('/')[-1].startswith('YAML:'):
					key = '/'.join(k.split('/')[0:-1]) + '/' + k.split('/')[-1].split(':')[1]
					path = v.split(':')[0]
					ns = v.split(':')[1]
					if path.startswith('~') or path.startswith('/'):
						yamlpath = os.path.expanduser(path)
					else:
						yamlpath = os.path.join(self._rp.get_path(path.split('/')[0]), '/'.join(path.split('/')[1:]))
					with open(yamlpath, 'r') as f:
						content = yaml.load(f)
					if ns != '' and ns in content:
						content = content[ns]
					be_selection.arg_keys.append(key)
					be_selection.arg_values.append(yaml.dump(content))
				else:
					be_selection.arg_keys.append(k)
					be_selection.arg_values.append(v)
		except Exception as e:
			rospy.logwarn('Failed to parse and substitute behavior arguments, will use direct input.\n%s' % str(e))
			be_selection.arg_keys = msg.arg_keys
			be_selection.arg_values = msg.arg_values

		be_structure = ContainerStructure()
		be_structure.containers = msg.structure

		be_filepath_new = os.path.join(self._rp.get_path(behavior["package"]), 'src/' + behavior["package"] + '/' + behavior["file"] + '.py')
		with open(be_filepath_new, "r") as f:
			be_content_new = f.read()

		be_filepath_old = os.path.join(self._rp.get_path(behavior["package"]), 'src/' + behavior["package"] + '/' + behavior["file"] + '_tmp.py')
		if not os.path.isfile(be_filepath_old):
			be_selection.behavior_checksum = zlib.adler32(be_content_new)
			if msg.autonomy_level != 255:
				be_structure.behavior_id = be_selection.behavior_checksum
				self._mirror_pub.publish(be_structure)
			self._pub.publish(be_selection)
			rospy.loginfo("No changes to behavior version.")
			return

		with open(be_filepath_old, "r") as f:
			be_content_old = f.read()

		sqm = difflib.SequenceMatcher(a=be_content_old, b=be_content_new)
		diffs = [x[1] for x in sqm.get_grouped_opcodes(0)]
		for opcode, a0, a1, b0, b1 in diffs:
			content = be_content_new[b0:b1]
			be_selection.modifications.append(BehaviorModification(a0, a1, content))

		be_selection.behavior_checksum = zlib.adler32(be_content_new)
		if msg.autonomy_level != 255:
			be_structure.behavior_id = be_selection.behavior_checksum
			self._mirror_pub.publish(be_structure)

		self._pub.publish(be_selection)
Пример #58
0
def discover(timeout=None,
             local_ip_address=None,
             discover_ip_address='255.255.255.255'):
    if local_ip_address is None:
        local_ip_address = socket.gethostbyname(socket.gethostname())
    if local_ip_address.startswith('127.'):
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        s.connect(('8.8.8.8',
                   53))  # connecting to a UDP address doesn't send packets
        local_ip_address = s.getsockname()[0]
    address = local_ip_address.split('.')
    cs = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    cs.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    cs.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
    cs.bind((local_ip_address, 0))
    port = cs.getsockname()[1]
    starttime = time.time()

    devices = []

    timezone = int(time.timezone / -3600)
    packet = bytearray(0x30)

    year = datetime.now().year

    if timezone < 0:
        packet[0x08] = 0xff + timezone - 1
        packet[0x09] = 0xff
        packet[0x0a] = 0xff
        packet[0x0b] = 0xff
    else:
        packet[0x08] = timezone
        packet[0x09] = 0
        packet[0x0a] = 0
        packet[0x0b] = 0
    packet[0x0c] = year & 0xff
    packet[0x0d] = year >> 8
    packet[0x0e] = datetime.now().minute
    packet[0x0f] = datetime.now().hour
    subyear = str(year)[2:]
    packet[0x10] = int(subyear)
    packet[0x11] = datetime.now().isoweekday()
    packet[0x12] = datetime.now().day
    packet[0x13] = datetime.now().month
    packet[0x18] = int(address[0])
    packet[0x19] = int(address[1])
    packet[0x1a] = int(address[2])
    packet[0x1b] = int(address[3])
    packet[0x1c] = port & 0xff
    packet[0x1d] = port >> 8
    packet[0x26] = 6

    checksum = adler32(packet, 0xbeaf) & 0xffff
    packet[0x20] = checksum & 0xff
    packet[0x21] = checksum >> 8

    cs.sendto(packet, (discover_ip_address, 80))
    if timeout is None:
        response = cs.recvfrom(1024)
        responsepacket = bytearray(response[0])
        host = response[1]
        devtype = responsepacket[0x34] | responsepacket[0x35] << 8
        mac = responsepacket[0x3a:0x40]
        name = responsepacket[0x40:].split(b'\x00')[0].decode('utf-8')
        cloud = bool(responsepacket[-1])
        device = gendevice(devtype, host, mac, name=name, cloud=cloud)
        return device

    while (time.time() - starttime) < timeout:
        cs.settimeout(timeout - (time.time() - starttime))
        try:
            response = cs.recvfrom(1024)
        except socket.timeout:
            return devices
        responsepacket = bytearray(response[0])
        host = response[1]
        devtype = responsepacket[0x34] | responsepacket[0x35] << 8
        mac = responsepacket[0x3a:0x40]
        name = responsepacket[0x40:].split(b'\x00')[0].decode('utf-8')
        cloud = bool(responsepacket[-1])
        device = gendevice(devtype, host, mac, name=name, cloud=cloud)
        devices.append(device)
    return devices
Пример #59
0
def send_file(
    filename_or_fp,
    mimetype=None,
    as_attachment=False,
    attachment_filename=None,
    add_etags=True,
    cache_timeout=None,
    conditional=False,
    last_modified=None,
):
    """Sends the contents of a file to the client.  This will use the
    most efficient method available and configured.  By default it will
    try to use the WSGI server's file_wrapper support.  Alternatively
    you can set the application's :attr:`~Flask.use_x_sendfile` attribute
    to ``True`` to directly emit an ``X-Sendfile`` header.  This however
    requires support of the underlying webserver for ``X-Sendfile``.

    By default it will try to guess the mimetype for you, but you can
    also explicitly provide one.  For extra security you probably want
    to send certain files as attachment (HTML for instance).  The mimetype
    guessing requires a `filename` or an `attachment_filename` to be
    provided.

    ETags will also be attached automatically if a `filename` is provided. You
    can turn this off by setting `add_etags=False`.

    If `conditional=True` and `filename` is provided, this method will try to
    upgrade the response stream to support range requests.  This will allow
    the request to be answered with partial content response.

    Please never pass filenames to this function from user sources;
    you should use :func:`send_from_directory` instead.

    .. versionadded:: 0.2

    .. versionadded:: 0.5
       The `add_etags`, `cache_timeout` and `conditional` parameters were
       added.  The default behavior is now to attach etags.

    .. versionchanged:: 0.7
       mimetype guessing and etag support for file objects was
       deprecated because it was unreliable.  Pass a filename if you are
       able to, otherwise attach an etag yourself.  This functionality
       will be removed in Flask 1.0

    .. versionchanged:: 0.9
       cache_timeout pulls its default from application config, when None.

    .. versionchanged:: 0.12
       The filename is no longer automatically inferred from file objects. If
       you want to use automatic mimetype and etag support, pass a filepath via
       `filename_or_fp` or `attachment_filename`.

    .. versionchanged:: 0.12
       The `attachment_filename` is preferred over `filename` for MIME-type
       detection.

    .. versionchanged:: 1.0
        UTF-8 filenames, as specified in `RFC 2231`_, are supported.

    .. _RFC 2231: https://tools.ietf.org/html/rfc2231#section-4

    .. versionchanged:: 1.0.3
        Filenames are encoded with ASCII instead of Latin-1 for broader
        compatibility with WSGI servers.

    .. versionchanged:: 1.1
        Filename may be a :class:`~os.PathLike` object.

    .. versionadded:: 1.1
        Partial content supports :class:`~io.BytesIO`.

    :param filename_or_fp: the filename of the file to send.
                           This is relative to the :attr:`~Flask.root_path`
                           if a relative path is specified.
                           Alternatively a file object might be provided in
                           which case ``X-Sendfile`` might not work and fall
                           back to the traditional method.  Make sure that the
                           file pointer is positioned at the start of data to
                           send before calling :func:`send_file`.
    :param mimetype: the mimetype of the file if provided. If a file path is
                     given, auto detection happens as fallback, otherwise an
                     error will be raised.
    :param as_attachment: set to ``True`` if you want to send this file with
                          a ``Content-Disposition: attachment`` header.
    :param attachment_filename: the filename for the attachment if it
                                differs from the file's filename.
    :param add_etags: set to ``False`` to disable attaching of etags.
    :param conditional: set to ``True`` to enable conditional responses.

    :param cache_timeout: the timeout in seconds for the headers. When ``None``
                          (default), this value is set by
                          :meth:`~Flask.get_send_file_max_age` of
                          :data:`~flask.current_app`.
    :param last_modified: set the ``Last-Modified`` header to this value,
        a :class:`~datetime.datetime` or timestamp.
        If a file was passed, this overrides its mtime.
    """
    mtime = None
    fsize = None

    if hasattr(filename_or_fp, "__fspath__"):
        filename_or_fp = fspath(filename_or_fp)

    if isinstance(filename_or_fp, string_types):
        filename = filename_or_fp
        if not os.path.isabs(filename):
            filename = os.path.join(current_app.root_path, filename)
        file = None
        if attachment_filename is None:
            attachment_filename = os.path.basename(filename)
    else:
        file = filename_or_fp
        filename = None

    if mimetype is None:
        if attachment_filename is not None:
            mimetype = (mimetypes.guess_type(attachment_filename)[0]
                        or "application/octet-stream")

        if mimetype is None:
            raise ValueError(
                "Unable to infer MIME-type because no filename is available. "
                "Please set either `attachment_filename`, pass a filepath to "
                "`filename_or_fp` or set your own MIME-type via `mimetype`.")

    headers = Headers()
    if as_attachment:
        if attachment_filename is None:
            raise TypeError(
                "filename unavailable, required for sending as attachment")

        if not isinstance(attachment_filename, text_type):
            attachment_filename = attachment_filename.decode("utf-8")

        try:
            attachment_filename = attachment_filename.encode("ascii")
        except UnicodeEncodeError:
            filenames = {
                "filename":
                unicodedata.normalize("NFKD", attachment_filename).encode(
                    "ascii", "ignore"),
                "filename*":
                "UTF-8''%s" % url_quote(attachment_filename, safe=b""),
            }
        else:
            filenames = {"filename": attachment_filename}

        headers.add("Content-Disposition", "attachment", **filenames)

    if current_app.use_x_sendfile and filename:
        if file is not None:
            file.close()
        headers["X-Sendfile"] = filename
        fsize = os.path.getsize(filename)
        headers["Content-Length"] = fsize
        data = None
    else:
        if file is None:
            file = open(filename, "rb")
            mtime = os.path.getmtime(filename)
            fsize = os.path.getsize(filename)
            headers["Content-Length"] = fsize
        elif isinstance(file, io.BytesIO):
            try:
                fsize = file.getbuffer().nbytes
            except AttributeError:
                # Python 2 doesn't have getbuffer
                fsize = len(file.getvalue())
            headers["Content-Length"] = fsize
        data = wrap_file(request.environ, file)

    rv = current_app.response_class(data,
                                    mimetype=mimetype,
                                    headers=headers,
                                    direct_passthrough=True)

    if last_modified is not None:
        rv.last_modified = last_modified
    elif mtime is not None:
        rv.last_modified = mtime

    rv.cache_control.public = True
    if cache_timeout is None:
        cache_timeout = current_app.get_send_file_max_age(filename)
    if cache_timeout is not None:
        rv.cache_control.max_age = cache_timeout
        rv.expires = int(time() + cache_timeout)

    if add_etags and filename is not None:
        from warnings import warn

        try:
            rv.set_etag("%s-%s-%s" % (
                os.path.getmtime(filename),
                os.path.getsize(filename),
                adler32(
                    filename.encode("utf-8") if isinstance(
                        filename, text_type) else filename)
                & 0xFFFFFFFF,
            ))
        except OSError:
            warn(
                "Access %s failed, maybe it does not exist, so ignore etags in "
                "headers" % filename,
                stacklevel=2,
            )

    if conditional:
        try:
            rv = rv.make_conditional(request,
                                     accept_ranges=True,
                                     complete_length=fsize)
        except RequestedRangeNotSatisfiable:
            if file is not None:
                file.close()
            raise
        # make sure we don't send x-sendfile for servers that
        # ignore the 304 status code for x-sendfile.
        if rv.status_code == 304:
            rv.headers.pop("x-sendfile", None)
    return rv
Пример #60
0
  print "Exec Unpacked Size: %s" %unpackedsize
  print "Exec Adler32: %x" %adler32

  # Load the key
  keyf = open(sys.argv[2])
  key = bytearray(keyf.read())
  keyf.close()

  print "Doing Key Mess"
  for i in range(512):
    key[i] = (key[i] - 1) & 0xFF

  print "Decrypting Phase 0"
  exe = decryptPhase0(exe, key, packedsize)

  decadler = zlib.adler32(str(exe[:packedsize])) & 0xFFFFFFFF

  if decadler == adler32:
    print "Checksum OK"
    print "Decrypting Phase 1"
    exe = decryptPhase1(exe, packedsize)

    print "Decrypting Phase 2"
    exe = decryptPhase2(exe)

    print "Decompressing Phase 3"
    exe = decompressPhase(exe, unpackedsize)

    #print "Uncorrupting Phase 4"
    #exe = uncorruptPhase3(exe)