human
Cyclic Redundancy Check and Modulo | Returns XOR of ' a ' and ' b ' ( both of same length ).
initialize result.
Traverse all bits , if bits are same , then XOR is 0 , else 1.
Performs Modulo - 2 division.
Number of bits to be XORed at a time ..
Slicing the divident to appropriate length for particular step.
replace the divident by the result of XOR and pull 1 bit down.
else : If leftmost bit is '0' If the leftmost bit of the dividend ( or the part used in each step ) is 0 , the step cannot use the regular divisor.
we need to use an all - 0 s divisor ..
increment pick to move further.
For the last n bits , we have to carry it out normally as increased value of pick will cause Index Out of Bounds ..
Function used at the sender side to encode data by appending remainder of modular division at the end of data ..
Appends n - 1 zeroes at end of data.
Append remainder in the original data.
Driver code"
Solution in Python:
 Write me a code to cyclic Redundancy Check and Modulo and the other steps required?
assistant
#Here is code to cyclic Redundancy Check and Modulo and the other steps required.
 def xor ( a , b ) :
	result = [ ]
	for i in range ( 1 , len ( b ) ) :
		if a [ i ] == b [ i ] :
			result . append ( '0' )
		else :
			result . append ( '1' )
	return ' ' . join ( result )
def mod2div ( divident , divisor ) :
	pick = len ( divisor )
	tmp = divident [ 0 : pick ]
	while pick < len ( divident ) :
		if tmp [ 0 ] == '1' :
			tmp = xor ( divisor , tmp ) + divident [ pick ]
			tmp = xor ( '0' * pick , tmp ) + divident [ pick ]
		pick += 1
	if tmp [ 0 ] == '1' :
		tmp = xor ( divisor , tmp )
	else :
		tmp = xor ( '0' * pick , tmp )
	checkword = tmp
	return checkword
def encodeData ( data , key ) :
	l_key = len ( key )
	appended_data = data + '0' * ( l_key - 1 )
	remainder = mod2div ( appended_data , key )
	codeword = data + remainder
	print ( " Remainder ▁ : ▁ " , remainder )
	print ( " Encoded ▁ Data ▁ ( Data ▁ + ▁ Remainder ) ▁ : ▁ " , codeword )
data = "100100"
key = "1101"
encodeData ( data , key )