def process_data(data, key_len): offsets = [] # If redirecting into a file we might not want to show progress if SHOW: pb = 0 blocks = len(data) / key_len progress = progressBar(0, len(data) - key_len, 77) for e in range(len(data)): # Don't look behind if e == 0: print "\nStarting. Processing byte-by-byte of %d bytes. Please be patient." % len( data) #continue # If redirecting into a file we might not want to show progress if SHOW and (progress.amount < (len(data) - key_len)): # Use progress bar to help user pb += 1 progress(pb) # Don't go past the end #if (e + key_len + 1) >= len(data): #print "keylen",key_len," : data",len(data) if (e + key_len) > len(data): print "Done. Patience pays off. Hopefully.\n" break # Note: you must use float for this test. #if H(data[e:e+key_len]) >= key_entropy[key_len]: if H(data[e:e + (key_len - 1)]) >= key_entropy[key_len]: offsets.append(e) #print "Storing offset",offsets #else: #print "not storing" return offsets
def process_data(data,key_len): offsets = [] # If redirecting into a file we might not want to show progress if SHOW: pb = 0 blocks = len(data)/key_len progress = progressBar(0, len(data) - key_len, 77) for e in range(len(data)): # Don't look behind if e == 0: print "\nStarting. Processing byte-by-byte of %d bytes. Please be patient."%len(data) #continue # If redirecting into a file we might not want to show progress if SHOW and (progress.amount < (len(data) - key_len)): # Use progress bar to help user pb += 1 progress(pb) # Don't go past the end #if (e + key_len + 1) >= len(data): #print "keylen",key_len," : data",len(data) if (e + key_len) > len(data): print "Done. Patience pays off. Hopefully.\n" break # Note: you must use float for this test. #if H(data[e:e+key_len]) >= key_entropy[key_len]: if H(data[e:e+(key_len - 1)]) >= key_entropy[key_len]: offsets.append(e) #print "Storing offset",offsets #else: #print "not storing" return offsets
def entropy_scan(data, block_size): if SHOWPROGRESS: progress = progressBar(0, len(data) - block_size, 77) # creates blocks of block_size for all possible offsets ('x'): blocks = (data[x:block_size + x] for x in range(len(data) - block_size)) i = 0 for block in (blocks): i += 1 if SHOWPROGRESS: progress(i) yield H(block)
def entropy_scan (data, block_size) : if SHOWPROGRESS: progress = progressBar(0, len(data) - block_size, 77) # creates blocks of block_size for all possible offsets ('x'): blocks = (data[x : block_size + x] for x in range (len (data) - block_size)) i = 0 for block in (blocks) : i += 1 if SHOWPROGRESS: progress(i) yield H (block)
def getPubsPerYear(keyword, year_low, year_high): n_pubs = [] print(">> Query: " + keyword + " from " + str(year_low) + " to " + str(year_high) + "...") YEAR = range(year_low, year_high + 1, 1) pBar = progressBar(len(YEAR)) for year in YEAR: n_pubs.append(getNumberOfCitations(keyword, year)) # Delay to avoid multiple-requests detection pBar.update() time.sleep(1) if n_pubs[len(n_pubs) - 1] == -1: print( "WARNING: further requests on this IP address are blocked from the server. Please re-try in a while..." ) return return n_pubs
errf.close() else : #如果文件名字不包含全路径,则默认为当前目录 if os.sep not in ip_or_file: ip_or_file = os.getcwd()+os.sep+ip_or_file if not os.path.exists(ip_or_file): print u'您输入的文件文件名称有误' usage() sys.exit(1) try: filename = open(ip_or_file) outf = open(output_file,'a') errf = open(err_output_file,'a') file_line = open(ip_or_file).readlines() flie_line_no = file_line.__len__() prog = progressBar(0,flie_line_no,75) for i in filename.readlines(): i = i.strip() lineno += 1 try: locate_info = get_ip_locate(str(i)) output_dict[str(i)]=locate_info outf.write("%s\n"%locate_info) outf.flush() print prog(lineno), except: # errf.write("%s\n" %(str(i))) # errf.flush() pass outf.close() # errf.close()
POSITION_FORCE_array[-1].append(float(line.split()[3])) POSITION_FORCE_array[-1].append(float(line.split()[7])) POSITION_FORCE_array[-1].append(float(line.split()[8])) POSITION_FORCE_array[-1].append(float(line.split()[9])) POSITION_FORCE_array[-1].append(-10) inputFile.close() number_of_snapshots = int(len(POSITION_FORCE_array)/float(number_of_particles)) CELL_array = cell_size*numpy.ones((number_of_snapshots,3), dtype=numpy.float) print 'input read complete' sanity = (CELL_array[0][0]**2 + CELL_array[0][1]**2 + CELL_array[0][2]**2)**(1.0/2.0) progess = progressBar(0, number_of_snapshots, 77) s = 0 # counts over snapshots while s < number_of_snapshots: molecule_number = 0 p = 0 # counts over particles while p < number_of_particles: if (POSITION_FORCE_array[s*number_of_particles + p][6] == -10): o = 0 # counts over other particles