x = "x8+x5+x3+x2+x0"
y = "x6+x5+x3+x2+x1"
m = "x8+x6+x5+x1+x0"
X = 0
Y = 0
M = 0
# converting polynomials to binary
for l in x:
    if l.isdigit() == True:
        X = X + 10**int(l)
for l in y:
    if l.isdigit() == True:
        Y = Y + 10**int(l)
for l in m:
    if l.isdigit() == True:
        M = M + 10**int(l)
sum=0 
# adding two binary values       
while X!=0 :
    d1 = X%10
    d2 = Y%10
    sum = (sum*10) + (d1^d2)
    Y = Y//10
    X = X//10
# reversing the sum coz the addition was performed reversed
rev_sum = 0
while sum != 0:
    digit = sum % 10
    rev_sum = rev_sum * 10 + digit
    sum //= 10 

Over here each character of the string polynomial is taken, checked if it is a digit, then I have performed 10**int(l) --> this is creating values like 1000 if it is x3 and so on, then it is added. Ofcourse the value is in integer datatype and looks like decimal value, but I couldn't think of a better way to get it in binary form. My idea is to convert the value to string and then actually convert to binary notation using any function (if it exists) when finding the modulus.

I have done the XOR sum of two polynomials after converting them to binary values. Now I have a binary value rev_sum and I have to mod it with variable M. Ofcourse we need XOR even during finding the modulus. I need the final answer as a polynomial, how do I proceed?

0

There are 0 best solutions below