-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChecksum.py
31 lines (28 loc) · 837 Bytes
/
Checksum.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
def sender(n,datagram):
print('\n\n\n-----Sender End-----')
checksum = 0
for i in range(1,n):
checksum = checksum + datagram[i]
print('Checksum at sender End is',checksum)
return checksum
def receiver(n,datagram,check):
print('-----Receiver End-----')
for i in range(1,n):
check = check - datagram[i]
if check != 0:
print('The packet is collided')
return False
else:
print('Checksum at receiver end is',check)
return check
datagram = []
n = int(input("Enter number of packets: "))
print('Enter:')
for i in range(1,n+1):
p = int(input('Packet: '))
datagram.append(p)
check = sender(n,datagram)
print('\n\n\nPacket sending......\n\n\n')
res = receiver(n,datagram,check)
if res == 0:
print('\n\n\nCommunication is Successful!!!')