Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BitPolynom.__init__ does not allow bytes type #2385

Closed
marinelay opened this issue Apr 10, 2024 · 0 comments · Fixed by #2389
Closed

BitPolynom.__init__ does not allow bytes type #2385

marinelay opened this issue Apr 10, 2024 · 0 comments · Fixed by #2389

Comments

@marinelay
Copy link
Contributor

It is the same issue as #2384 that occurs in other method BitPolynom.__init__:

class BitPolynom(object):
"""Class for representing GF(2)[X], i.e. the field of polynomials over
GF(2).
In practice the polynomials are represented as numbers such that `x**n`
corresponds to `1 << n`. In this representation calculations are easy: Just
do everything as normal, but forget about everything the carries.
Addition becomes xor and multiplication becomes carry-less multiplication.
Examples:
>>> p1 = BitPolynom("x**3 + x + 1")
>>> p1
BitPolynom('x**3 + x + 1')
>>> int(p1)
11
>>> p1 == BitPolynom(11)
True
>>> p2 = BitPolynom("x**2 + x + 1")
>>> p1 + p2
BitPolynom('x**3 + x**2')
>>> p1 * p2
BitPolynom('x**5 + x**4 + 1')
>>> p1 // p2
BitPolynom('x + 1')
>>> p1 % p2
BitPolynom('x')
>>> d, r = divmod(p1, p2)
>>> d * p2 + r == p1
True
>>> BitPolynom(-1)
Traceback (most recent call last):
...
ValueError: Polynomials cannot be negative: -1
>>> BitPolynom('y')
Traceback (most recent call last):
...
ValueError: Not a valid polynomial: y
"""
def __init__(self, n):
if isinstance(n, (bytes, six.text_type)):
self.n = 0
x = BitPolynom(2)
try:
for p in n.split('+'):

This code handles that n is bytes, but it always raise the type error at line 80.
The way to fix it will be the same as #2384.

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants