NTRU_IoT/infidel-code/py_wrappers/blast_rciot.py

56 lines
1.3 KiB
Python
Raw Normal View History

2022-02-01 11:45:47 -05:00
#!/bin/env python3
import paho.mqtt.client as paho
import csv
import pandas as pd
# from Publish_rciot_NTRU import main as sec_pub
## from SABER_KEM.test.so_handler import main as sec_pub
import time
broker = "192.168.1.17"
client = paho.Client()
port = 1883
with open('data/rciot_data.csv') as f: # 1 Fasa
# with open('./file.csv') as f: # 3 Fasa
data=[tuple(line) for line in csv.reader(f)]
# data = pd.DataFrame()
print(data[0])
header = ["Message Length", "Encryption Time"]
with open("data/saber_enc_time.csv", "w") as f:
writer = csv.writer(f)
writer.writerow(header)
def publish_enc():
x = 0
for i in data[10:500]:
print("===> : "+str(x))
dec_time = sec_pub(str(i))
with open("data/saber_enc_time.csv", "a+") as f:
writer = csv.writer(f)
writer.writerow([len(str(i)), dec_time])
x = x+1
time.sleep(0.5)
def publish_nonenc():
x = 0
for i in data[10:500]:
print("===> : "+str(x))
status = client.connect(broker,port)
client.loop_start()
client.publish("device01/msg", str(i))
# with open("saber_enc_time.csv", "a+") as f:
# writer = csv.writer(f)
# writer.writerow([len(str(i)), dec_time])
x = x+1
time.sleep(0.5)
# publish_enc()
for i in data[1:5]:
print(str(i))