def update_password(pw_old, pw_new, smartcard_file): if not is_logged_in(): return 1 (auth_params, tp, ltk, kh, f) = util.load(smartcard_file) pwd_old = compute_one_way_hash(str(urs.uid) + urs.k + pw_old) fx = compute_one_way_hash(str(urs.uid) + str(pwd_old) + str(urs.ct)) if fx != f: print("Incorrect password") urs.reset() return 1 pwd_new = compute_one_way_hash(str(urs.uid) + urs.k + pw_new) auth_params_new = [] for sid, a, p in auth_params: a_new = a ^ pwd_old ^ pwd_new p_new = p ^ pwd_old ^ pwd_new auth_params_new.append((sid, a_new, p_new)) f_new = compute_one_way_hash(str(urs.uid) + str(pwd_new) + str(urs.ct)) util.store((auth_params_new, tp, ltk, kh, f_new), smartcard_file) print("Password updated successfully") return 0
def main(): # print('hi') try: os.mkdir("./evens") except: pass evens = set([(1,)]) evens = util.load(f"./evens/evens.dat") startSigma = util.startSigma() # startSigma = 2 for s in range(startSigma+1, MAX_SIGMA + 1): t1 = time.time() pHandler = ProccesHandler(evens, PROCESSES) for b in util.sigmaBatches(s, BATCH_SIZE): pHandler.run(b) newEvens = pHandler.getEvens() evens.update(newEvens) print(f"sigma: {s} \tevens: {len(evens)}\tnewEvens: {len(newEvens)} \tin {time.time() - t1}s" ) util.store(evens, f"./evens/evens.dat") util.store(newEvens, f"./evens/evens_{s}.dat") # print(f"newEvens: {newEvens}") pHandler.terminate()
def store_user_data(biom_file, smart_card, uid): dir_path = os.path.join(config.USER_DATA_PATH, str(uid) + "_" + str(int(time.time()))) os.mkdir(dir_path) shutil.copy(biom_file, dir_path) file_name = str(uuid.uuid1()) + ".smartcard" file_path = os.path.join(dir_path, file_name) util.store(smart_card, file_path) print("Smartcard created: ", file_name)
def register_user(uid, pwd): auth_params = [] for (sid, x) in servers: a = compute_one_way_hash(str(uid) + str(x)) ^ pwd p = compute_one_way_hash(str(sid) + str(x)) ^ pwd auth_params.append((sid, a, p)) users.append((uid, compute_one_way_hash(str(pwd) + str(x)))) util.store(users, config.MSRC_USER_FILE_PATH) return auth_params
def main(): #previous mxn completed m, n = util.load(settings.DATA_FOLDER / "mXn.dat") settings.prefixes = util.load(settings.DATA_FOLDER / "prefixes.dat") startM = m startN = n firstST = time.time() #m and n are prev m and n expanded to while m < settings.MAX_M or n < settings.MAX_N: #dM and dN are how much to expand m and n by respectively dM = min(settings.DELTA_M, settings.MAX_M - m) dN = min(settings.DELTA_N, settings.MAX_N - n) print(f"\nExpanding from {m}X{n} to {m+dM}X{n+dN}") sT = time.time() #expand sideways by dM expand.expandSide(m, n, dM, dN) sideTime = time.time() print(f"Side time: {sideTime - sT}s") util.emptyDir(settings.DATA_FOLDER / "parents") util.emptyDir(settings.DATA_FOLDER / "oldRoots") #expand down by dN expand.expandDown(m, n, dM, dN) print(f"Down time: {time.time() - sideTime}s") endT = time.time() m += dM n += dN #load all evens just for us to check if it's working properly # print("genning all evens") allEvens = set() for x in range(1, n + 1): eX = util.load(settings.EVENS_FOLDER / f"evens{x}.dat") allEvens.update(eX) print(f"{m}X{n} total evens: {len(allEvens)}\t in {str(endT-sT)}s") if settings.printEvens: print(str(m) + "X" + str(n) + " evens: " + str(allEvens)) # print(f"size of all evens: {sys.getsizeof(allEvens)}") # print(f"Deep allEvens objSize: {get_deep_size(allEvens)}") # print() #store the m and n completed, evens are stored in side and down expand util.store((m, n), settings.DATA_FOLDER / "mXn.dat") util.store(settings.prefixes, settings.DATA_FOLDER / "prefixes.dat") print( f"\n\nTotal run time for {startM}X{startN} to {m}X{n}: {time.time() - firstST}s " )
def update_biometric(pw, biom_file, smartcard_file): if not is_logged_in(): return 1 biom = util.load_biometric(biom_file) (auth_params, tp, ltk, kh, f) = util.load(smartcard_file) pwd = compute_one_way_hash(str(urs.uid) + urs.k + pw) fx = compute_one_way_hash(str(urs.uid) + str(pwd) + str(urs.ct)) if fx != f: print("Incorrect password") urs.reset() return 1 tp_new = numpy.random.rand(4) ct_new = compute_cancellable_template(biom, tp_new) ltk_new = ltk ^ urs.ct ^ ct_new f_new = compute_one_way_hash(str(urs.uid) + str(pwd) + str(ct_new)) util.store((auth_params, tp_new, ltk_new, kh, f_new), smartcard_file) print("Fingerprint updated successfully") return 0
def expandSide(m, n, dM, dN): # print("\nExpanding Side") #? settings.staticPrefixes = settings.prefixes.copy() settings.currRootsDir = settings.DATA_FOLDER / "sideRoots" settings.currOldRootsDir = settings.DATA_FOLDER / "sideOldRoots" #initialize the root roots with path len 1 util.emptyDir(settings.DATA_FOLDER / "sideRoots") for x in range(m + 1, m + dM + 1): util.store(set([(x, )]), settings.DATA_FOLDER / f"sideRoots/{(x,)}.dat") settings.prefixes.add((x, )) util.store(settings.prefixes, settings.DATA_FOLDER / "prefixes.dat") for d in range(2, n + dN): expandSideLayer(d, m, dM) #take resulting side roots and add them to main roots files = os.listdir(settings.DATA_FOLDER / "sideRoots") for f in files: try: oldRoots = util.load(settings.DATA_FOLDER / f"roots/{f}") newRoots = util.load(settings.DATA_FOLDER / f"sideRoots/{f}") oldRoots.update(newRoots) combRoots = oldRoots util.store(combRoots, settings.DATA_FOLDER / f"roots/{f}") except OSError: os.rename(settings.DATA_FOLDER / f"sideRoots/{f}", settings.DATA_FOLDER / f"roots/{f}")
def do_it(self, ev): login = self.login_edit.get() password = self.password_edit.get() diary_id = self.diary_id_edit.get() filename = self.filename_edit.get() split_type = self.split_type.get() if not login: messagebox.showinfo("Error", "Логин не задан") return if not diary_id: messagebox.showinfo("Error", "Адрес сообщества не задан") return if not filename: messagebox.showinfo("Error", "Путь к файлу не задан") return api = Diary() try: api.login(login, password) text_with_header = util.load(filename) prefix = os.path.splitext(filename)[0] text_with_header = util.fix_characters(text_with_header) header, text = find_header(text_with_header) if split_type == 1: post, comments = split_text_with_comments(header, text) util.store(prefix + "_post.txt", post) for i, comment in enumerate(comments): util.store(prefix + "_comment_%d.txt" % (i+1), comment) # Send to diary post_id = api.new_post(post, diary_id) for comment in comments: api.add_comment(post_id, comment) if len(comments) > 0: messagebox.showinfo("Info", "Пост успешно опубликован, тексты комментариев ищите в файлах *comment_N.txt") else: messagebox.showinfo("Info", "Пост успешно опубликован") else: posts = split_text_with_posts(header, text) for i, post in enumerate(posts): util.store(prefix + "_post_%d.txt" % (i + 1), post) # Send to diary for post in posts: api.new_post(post, diary_id) messagebox.showinfo("Info", "Посты успешно опубликованы. Тексты продублированы в файлы *post_N.txt") except Exception as e: messagebox.showinfo("Error", str(e)) return
def seed(): #make sure all folders exist try: util.emptyDir(settings.DATA_FOLDER) except: pass try: os.mkdir(Path(settings.THIS_FOLDER, "./data")) except: pass try: os.mkdir(settings.DATA_FOLDER) except: pass try: os.mkdir(settings.EVENS_FOLDER) except: pass try: os.mkdir(settings.DATA_FOLDER / "roots") except: pass try: os.mkdir(settings.DATA_FOLDER / "oldRoots") except: pass try: os.mkdir(settings.DATA_FOLDER / "parents") except: pass try: os.mkdir(settings.DATA_FOLDER / "sideOldRoots") except: pass try: os.mkdir(settings.DATA_FOLDER / "sideRoots") except: pass util.store((1, 1), settings.DATA_FOLDER / "mXn.dat") # util.store(set(), DATA_FOLDER / "roots/rootsBatch0.dat") util.store(set([(1, )]), settings.EVENS_FOLDER / "evens1.dat") prefixes = set() util.store(prefixes, settings.DATA_FOLDER / "prefixes.dat")
def main(MAX_N, DELTA_N): #seed here for testing tree = chompTree.Tree(1) util.fillTree([tree.getNode((1,))], tree, 1) tree.getNode((1,)).setEven() n_evens = (1,set([tree.getNode((1,))])) nevens = n_evens # nevens = util.load(DATA_FOLDER / "n&evens.dat") # tree = util.load(DATA_FOLDER / "tree.dat") n = nevens[0] evens = nevens[1] firstStartT = time.time() while n+DELTA_N <= MAX_N: sT = time.time() evens, tree = expand(evens, tree, n, DELTA_N) n += DELTA_N util.store((n, evens), DATA_FOLDER / "n&evens.dat") endT = time.time() print(str(n)+"X"+str(n)+" #evens: " + str(len(evens)) + "\t in " + str(endT-sT)+"s") print(str(n)+"X"+str(n)+" evens: " + str(evens)) #if the difference between starting n and MAX_N is not a multiple of DELTA_N, we have to do this: if n != MAX_N: sT = time.time() evens, tree = expand(evens, tree, n, MAX_N-n) n = MAX_N util.store((n, evens), DATA_FOLDER / "n&evens.dat") endT = time.time() print(str(n)+"X"+str(n)+" #evens: " + str(len(evens)) + "\t in " + str(endT-sT)+"s") print(str(n)+"X"+str(n)+" evens: " + str(evens)) # print(len(evens)) # print("4, 1, 1, 1: " + str(tree.pathNodes)) util.store((n, evens), DATA_FOLDER / "n&evens.dat")
def expandMain(depth, m, dM, isSide, evens=set()): # print("expanding main") #static settings.staticPrefixes = settings.prefixes.copy() ps = list(settings.staticPrefixes) ps.sort() for f in ps: # print(f"file: {f}") newRoots = {} workingParents = set() settings.currParentsNum = 0 util.combineDir(settings.currRootsDir, str(f), True) # util.combineDir(settings.PARENTS_FOLDER, str(f), True) try: roots = util.load(f"{settings.currOldRootsDir}/{f}.dat") except Exception as e: # print(f"error: {e}") continue # print(f"roots: {roots}") if len(roots) == 0: continue #RBS is the roots of the new nodes indexed by the sigma of the node #Note a root = node[:-1] (I love how this looks like a face btw) rootsBySigma = util.genRBS(roots) # print(f"RBS: {rootsBySigma}") # n1 = list(roots)[0] # prefix = util.getPrefix(n1, oldPrefixes) # print(os.listdir(settings.PARENTS_FOLDER)) util.combineDir(settings.PARENTS_FOLDER, str(f)) # if f == (6, 4): # print("NUM FILES: "+str(len(os.listdir(DATA_FOLDER / f"parents/{f}" )))) #try loading previosu parents and try: prevParents = util.load(settings.PARENTS_FOLDER / f"{f}.dat") # print(f"prevParents: {prevParents}") for parent in prevParents: pRoot = parent[:-1] try: # print("trying") rootsBySigma[sum(parent)].remove(pRoot) # print("2") util.addToSet(parent, newRoots, root=True) except Exception as e: # print # print(f"error rbs: {e}") pass except OSError as e: # print(f"OSerror: {e}") pass # print(f"error: {e}") # keys = rootsBySigma.keys() # # #get min and max sigma # minSigma = min(keys) # maxSigma = max(keys) #go through each sigma starting from smallest for sigma in range(min(rootsBySigma.keys()), max(rootsBySigma.keys()) + 1): #if this sigma is empty why bother # print(f"sigma: {sigma}") if sigma not in rootsBySigma.keys(): continue # print(f"Sigma: {sigma}") # newParents = {} # allParents = set() #each node here will be even for root in rootsBySigma[sigma]: #create the node, add it to evens # print("starting") node = tuple(list(root) + [sigma - sum(root)]) evens.add(node) # print(f"node: {node}") #get the parents of node # parents = util.getParents(2, pM + dM-2, node) start = node[0] - 1 delta = m + dM - (node[0] - 1) # parentD = m+dM if (isSide): start = m delta = dM # parentD = m+dM-node[-1] # print(f"pre parents {rootsBySigma}") util.getParents(start, delta, node, workingParents, rootsBySigma, newRoots) # util.getParents(parentS, m+dM, node, workingParents, rootsBySigma, newRoots) # print(f"post Parents {rootsBySigma}") # if newRoots != {}: # print(f"newRoots: {newRoots}") # print("past roots") for p in newRoots.keys(): util.dirStore(newRoots[p], settings.currRootsDir, str(p)) newRoots.clear() # del newParents del rootsBySigma[sigma] del rootsBySigma # print(f"workingParents: {workingParents}") util.storeParents(workingParents) # for pfix in workingParents.keys(): # try: # util.dirStore(workingParents[pfix], settings.PARENTS_FOLDER, str(pfix)) # except Exception as e: # # print(f"error: {e}") # pass for p in settings.prefixes: util.combineDir(settings.currRootsDir, str(p), True) util.store(evens, settings.DATA_FOLDER / f"evens/evens{depth}.dat") util.store(settings.prefixes, settings.DATA_FOLDER / "prefixes.dat") del evens
def register(sid): x1 = register_server(sid) servers.append((sid, x1)) util.store(servers, config.SERVER_FILE_PATH)
except: continue # 合理性判断 if new_data['mix_fly_ash_dosage']==0 and new_data["fly_sample_category"]!='' and new_data["fly_breed_grade"]!='': continue if new_data["mix_slag_powder_consumption"]==0 and new_data["slag_breed_grade"]!='': continue if new_data["mix_limestone_powder_consumption"]==0 and new_data["limestone_fineness"]!=-1: continue new_datali.append(new_data) return new_datali def print_data(datali): for line in datali: print(line) if __name__ == '__main__': start_day = date(2019, 1, 1) end_day = date(2019, 1, 31) while start_day <= end_day: start_time = start_day.strftime('%Y-%m-%d') datadi = get_data_web(start_time, start_time) datali = clean_data(datadi) # 清洗 store(datali) # print_data(datali) print(start_time + ": " + str(len(datali))) start_day = start_day + timedelta(days=1) print("存储完成!")
new_row += ['', -1, ''] shihuishihao = row[26] signal = 1 for row1 in shihuishi: if shihuishihao == regex3.findall(row1[0])[0]: signal = 0 new_row += row1[1:] break if signal == 1: new_row += [-1, -1, -1] pengzhangjihao = row[30] signal = 1 for row1 in pengzhangji: if pengzhangjihao == regex3.findall(row1[0])[0]: signal = 0 new_row += row1[1:] break if signal == 1: new_row += ['', -1, -1] all_data.append(new_row) return all_data if __name__ == '__main__': data = read_data() store(data)
def register_server(sid): x = compute_one_way_hash(str(sid) + krc) servers.append((sid, x)) util.store(servers, config.MSRC_SERVER_FILE_PATH) return x