import getopt
import sys
import uuid
import hashlib
import csv
def getIds(totals,encrypt):
seed=set()
for i in range(totals):
uid=uuid.uuid1()
if encrypt:
encrypt_id=hashlib.sha256((str(uid)+"saltValue").encode("utf-8")).hexdigest()
seed.add(encrypt_id)
else:
seed.add(str(uid).replace('-',''))
return seed
def gen_Datasets():
guest,host,intersect,encrypt_mode=getDataNum()
ids=list(getIds(intersect+host+guest,encrypt=encrypt_mode))
dataset_intersect=ids[:intersect]
dataset_host=ids[intersect:host]
dataset_host.extend(dataset_intersect)
dataset_guest=ids[intersect:guest]
dataset_guest.extend(dataset_intersect)
print(len(dataset_intersect),len(dataset_host),len(dataset_guest))
write_csvtb("./intersect.csv",dataset_intersect)
write_csvtb("./host_a.csv", dataset_intersect)
write_csvtb("./guest_b.csv", dataset_intersect)
print("finish all write ")
# with open("./intersect.txt","w")as i:
# for line in dataset_intersect:
# print(line)
# i.writelines(line)
# print("finish intersect========")
# with open("./host_a.txt","w") as h:
# for line in dataset_host:
# print(line)
# h.write(line)
# print("finsh host===============")
# with open("./guest_b.txt","w") as g:
# for line in dataset_guest:
# # print(line)
# g.write(line)
# print("finish guest=======")
def getDataNum():
def usage():
print("examples:-m: --help -e or --encrypt=: sha256 -i or --intersect=: intersect datasets number -g or --guest : guest number -h or --host : host dataset number ")
opts, args = getopt.getopt(sys.argv[1:], '-m-i:g:h:e:', ['help', 'host=', 'guest=','intersect=','encrypt='])
guest,host,intersect=None,None,None
encrypt = False
for opt_name, opt_value in opts:
if opt_name in ('-m', '--help'):
usage()
sys.exit()
if opt_name in ('-g', '--guest'):
guest = int(opt_value)
if opt_name in ('-h', '--host'):
host = int(opt_value)
if opt_name in ('-i','--intersect'):
intersect=int(opt_value)
if opt_name in('-e','--encrypt'):
if int(opt_value)==1:
encrypt=True
elif int(opt_value)==0:
encrypt=False
else:
raise ValueError("encrypt must between 0 and 1")
return guest,host,intersect,encrypt
def write_csvtb(path,dt):
with open(path,"w",newline='')as f:
writer=csv.writer(f)
for i in dt:
writer.writerow([i])
if __name__ == '__main__':
gen_Datasets()