def test(): import bin2hex # bin2hex conversions. a_key = [ "00000000000000000000000000000000", "00000000000000000000000000000000", "9F589F5CF6122C32B6BFEC2F2AE8C35A", "D491DB16E7B1C39E86CB086B789F5419", "019F9809DE1711858FAAC3A3BA20FBC3", "6363977DE839486297E661C6C9D668EB", "816D5BD0FAE35342BF2A7412C246F752" ] a_pt = [ "00000000000000000000000000000000", "9F589F5CF6122C32B6BFEC2F2AE8C35A", "D491DB16E7B1C39E86CB086B789F5419", "019F9809DE1711858FAAC3A3BA20FBC3", "6363977DE839486297E661C6C9D668EB", "816D5BD0FAE35342BF2A7412C246F752", "5449ECA008FF5921155F598AF4CED4D0" ] a_ct = [ "9F589F5CF6122C32B6BFEC2F2AE8C35A", "D491DB16E7B1C39E86CB086B789F5419", "019F9809DE1711858FAAC3A3BA20FBC3", "6363977DE839486297E661C6C9D668EB", "816D5BD0FAE35342BF2A7412C246F752", "5449ECA008FF5921155F598AF4CED4D0", "6600522E97AEB3094ED5F92AFCBCDD10" ] key = [] pt = [] ct = [] for s in a_key: # t=bin2hex.hex2bin(s) t = bin2hex.reverse(bin2hex.hex2bin(s)) key.append(t) continue for s in a_pt: t = bin2hex.hex2bin(s) # t=bin2hex.reverse(bin2hex.hex2bin(s)) pt.append(t) continue for s in a_ct: # t=bin2hex.reverse(bin2hex.hex2bin(s)) t = bin2hex.hex2bin(s) ct.append(t) continue c = twofish() # set our cipher! i = 0 for k in key: print "[%s:%s:%s]" % (i, len(k), bin2hex.bin2hex(k)), c.setkey(k) r = c.encrypt(pt[i]) if r != ct[i]: print "Vector", i, ":" print " Should be: ", a_ct[i] print " Is: ", bin2hex.bin2hex(r) pass i = i + 1 continue print "------Test Finished-----------" pass
def sim_start(simulator, wave_log, top_name, hex_name, tb_model_list, srclist, inclist): global check_list; cnt = 0; #Message message = "Check Instruction : "; for instlist in check_list: message = message + instlist + " "; print(message); #Sim Dir Make if(os.path.exists("sim") != True): subprocess.call("mkdir sim", shell=True); #Simulation Loop for line in check_list: #Start Time date = datetime.datetime.today(); print("-[" + str(cnt) + "]Start : [" + line + "] : " + date.strftime("%Y-%m-%d %H:%M:%S")); #Generate TCL gen_tcl.generate_tcl(1, simulator, str(wave_log), top_name, tb_model_list, srclist, inclist, "sim/" + line + ".result\n", "sim_run.tcl"); #Binary 2 Hex fr = open("./bin/" + line + ".bin", "rb"); read_data = fr.read(); result_hex = bin2hex.bin2hex(read_data); fw = open(hex_name, 'w'); fw.write(result_hex); fr.close(); fw.close(); #Start Sim if(simulator == "modelsim"): if(wave_log == '1'): subprocess.call('vsim -c -voptargs="+acc" ' + top_name + " -do sim_run.tcl", shell=True); else: subprocess.call('vsim -c ' + top_name + " -do sim_run.tcl", shell=True); elif(simulator == "riviera"): subprocess.call("vsimsa -do sim_run.tcl", shell=True); else: print("Simulation Error"); sys.exit(); #End Time date = datetime.datetime.today(); print("-[" + str(cnt) + "]Finish : [" + line + "] : " + date.strftime("%Y-%m-%d %H:%M:%S")); cnt = cnt + 1; #Tempfile Remove os.remove(hex_name); os.remove("sim_run.tcl");
def sim_start(wave_log, top_name, hex_name, tb_model_list, srclist, inclist): global check_list; cnt = 0; #Message message = "Check Instructions : "; for instlist in check_list: message = message + instlist + " "; print(message); #Sim Dir if(os.path.exists("sim") != True): subprocess.call("mkdir sim", shell=True); #Simulation Loop for line in check_list: #Start Time date = datetime.datetime.today(); print("-[" + str(cnt) + "]Start : [" + line + "] : " + date.strftime("%Y-%m-%d %H:%M:%S")); #Make TCL File gen_tcl.generate_tcl(True, wave_log, tb_model_list, srclist, inclist, "sim/" + line + ".result\n", "sim_run.tcl"); #Make Simulation HEX file fr = open("./bin/" + line + ".bin", "rb"); read_data = fr.read(); result_hex = bin2hex.bin2hex(read_data); fw = open(hex_name, 'w'); fw.write(result_hex); fr.close(); fw.close(); #Start Simlation if(wave_log == True): subprocess.call('vsim -c -voptargs="+acc" ' + top_name + " -do sim_run.tcl", shell=True); else: subprocess.call('vsim -c ' + top_name + " -do sim_run.tcl", shell=True); #End Time date = datetime.datetime.today(); print("-[" + str(cnt) + "]Finish : [" + line + "] : " + date.strftime("%Y-%m-%d %H:%M:%S")); cnt = cnt + 1;
def test(): import bin2hex # bin2hex conversions. a_key=[ "00000000000000000000000000000000", "00000000000000000000000000000000", "9F589F5CF6122C32B6BFEC2F2AE8C35A", "D491DB16E7B1C39E86CB086B789F5419", "019F9809DE1711858FAAC3A3BA20FBC3", "6363977DE839486297E661C6C9D668EB", "816D5BD0FAE35342BF2A7412C246F752" ] a_pt=[ "00000000000000000000000000000000", "9F589F5CF6122C32B6BFEC2F2AE8C35A", "D491DB16E7B1C39E86CB086B789F5419", "019F9809DE1711858FAAC3A3BA20FBC3", "6363977DE839486297E661C6C9D668EB", "816D5BD0FAE35342BF2A7412C246F752", "5449ECA008FF5921155F598AF4CED4D0" ] a_ct=[ "9F589F5CF6122C32B6BFEC2F2AE8C35A", "D491DB16E7B1C39E86CB086B789F5419", "019F9809DE1711858FAAC3A3BA20FBC3", "6363977DE839486297E661C6C9D668EB", "816D5BD0FAE35342BF2A7412C246F752", "5449ECA008FF5921155F598AF4CED4D0", "6600522E97AEB3094ED5F92AFCBCDD10" ] key=[] pt=[] ct=[] for s in a_key: # t=bin2hex.hex2bin(s) t=bin2hex.reverse(bin2hex.hex2bin(s)) key.append(t) continue for s in a_pt: t=bin2hex.hex2bin(s) # t=bin2hex.reverse(bin2hex.hex2bin(s)) pt.append(t) continue for s in a_ct: # t=bin2hex.reverse(bin2hex.hex2bin(s)) t=bin2hex.hex2bin(s) ct.append(t) continue c=twofish() # set our cipher! i=0 for k in key: print "[%s:%s:%s]" % (i,len(k),bin2hex.bin2hex(k)), c.setkey(k) r=c.encrypt(pt[i]) if r != ct[i]: print "Vector",i,":" print " Should be: ",a_ct[i] print " Is: ",bin2hex.bin2hex(r) pass i=i+1 continue print "------Test Finished-----------" pass