From b5dab2420696e2edb7402d3e836a5bade4ab04c9 Mon Sep 17 00:00:00 2001 From: Om Rawal <51584907+omrawal@users.noreply.github.com> Date: Mon, 28 Sep 2020 23:02:15 +0530 Subject: [PATCH 1/2] Add files via upload --- python/checksum.py | 85 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 python/checksum.py diff --git a/python/checksum.py b/python/checksum.py new file mode 100644 index 0000000..dd72320 --- /dev/null +++ b/python/checksum.py @@ -0,0 +1,85 @@ +# checksum +# author : Om Rawal +# 15/09/2020 19:31 + + +def BinaryToDecimal(binary): + + binary1 = binary + decimal, i, n = 0, 0, 0 + while(binary != 0): + dec = binary % 10 + decimal = decimal + dec * pow(2, i) + binary = binary//10 + i += 1 + return (decimal) + +def binaryToDec(n): + return int(n,2) + +print('Welcome to CheckSum') +message=input('Enter the message to send.: ') +print('Message entered is ',message) +print('Generating Dataword ...') +dataword=[] #length 7 +for i in range(len(message)): + if(message[i]!=' '): + res = ''.join(format(k, 'b') for k in bytearray(message[i], encoding ='utf-8')) + dataword.append(res) + else: + res = ''.join(format(k, 'b') for k in bytearray(message[i], encoding ='utf-8')) + res='0'+res + dataword.append(res) +print('calculating checksum......') +csum='0000000' +for i in dataword: + csum= bin(int(csum,2) + int(i,2))[2:] +dataword.append(csum) + +print('sending dataword......') +print(''.join(dataword)) +flag=int(input('1. To induce error\n2. To have no error')) +if(flag==1): + index=int(input('Enter Index: ')) + ak=''.join(dataword) + k=list(ak) + # print('k',k) + # print('ak',ak) + if(k[index]=='0'): + k[index]='1' + else: + k[index]='0' + a=[] + i=0 + while(i Date: Mon, 28 Sep 2020 23:03:36 +0530 Subject: [PATCH 2/2] Checksum added --- python/checksum.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/checksum.py b/python/checksum.py index dd72320..700fc3b 100644 --- a/python/checksum.py +++ b/python/checksum.py @@ -1,4 +1,4 @@ -# checksum +# checksum # author : Om Rawal # 15/09/2020 19:31 @@ -82,4 +82,4 @@ def binaryToDec(n): else: print('Error!!!\n Requesing Retransmission.....') # diff= bin(abs(int(csum,2) - int(dataword[i],2)))[2:] - # print(binaryToDec(diff)) \ No newline at end of file + # print(binaryToDec(diff))