-
Notifications
You must be signed in to change notification settings - Fork 0
/
Device.py
71 lines (58 loc) · 2.04 KB
/
Device.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import ECDSA as e
import datetime
import MineBlock as p
import IoTid_check as c
import location as l
import math
import random as r
import head as h
def Device():
print("Select one of the below options")
print("1.Enroll Device")
print("2.Communicate")
option=int(input())
if option==1:
ip=input()
d=l.checkLocation(ip)
if d>=0:
p.Mine()
AM=c.deviceid
with open('blockData.txt', 'w') as f:
f.write(str(AM))
print("Block Enrolled Successfully")
else:
print("Incorrect ip-address or Device Out of Range")
else:
with open('blockData.txt', 'r') as f:
for line in f:
ID=line.strip()
if c.checkId(ID):
ip=input()
d=l.checkLocation(ip)
if d>=0:
print("Authentication Successful")
n1=math.floor(r.random()*100)
Id=ID
my_bytes = ID.encode('utf-8')
my_bytearray = bytearray(my_bytes)
ID=my_bytearray
n1=n1.to_bytes(len(ID), byteorder='big')
reqId = bytes([b1 ^ b2 for b1, b2 in zip(ID, n1)])
curTime=datetime.datetime.now()
H=curTime.hour
M=curTime.minute
time=str(curTime.hour)+str(curTime.minute)
time=int(time)
time1=str(time)
time=time.to_bytes(len(reqId), byteorder='big')
reqId= bytearray(reqId)
time = bytearray(time)
# Perform bitwise OR operation on the two bytearray objects
T = bytes(reqId[i] | time[i] for i in range(len(reqId)))
pk,prk=h.Head(T,reqId,time1,Id,H,M)
e.ecdsa(pk,prk)
else:
print("Device Out Of Range")
else:
print("Deviece not Enrolled")
Device()