class galua_multiply def __init__ self number None self number number

 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
class galua_multiply:
def __init__(self, number=None):
self.number = number
def __ror__(self, other):
return galua_multiply(other)
def __or__(self, other):
if other == 1:
return self.number
elif other == 2:
return self.mul_by_02(self.number)
elif other == 3:
return self.mul_by_03()
elif other == 0x09:
return self.mul_by_09()
elif other == 0x0b:
return self.mul_by_0b()
elif other == 0x0d:
return self.mul_by_0d()
elif other == 0x0e:
return self.mul_by_0e()
@staticmethod
def mul_by_02(number):
return ((number << 1) ^ (0 if number < 0x80 else 0x1b)) % 0x100
def mul_by_03(self):
return self.mul_by_02(self.number) ^ self.number
def mul_by_09(self):
return self.mul_by_02(self.mul_by_02(self.mul_by_02(self.number))) ^ self.number
def mul_by_0b(self):
return self.mul_by_02(self.mul_by_02(self.mul_by_02(self.number))) ^ self.mul_by_02(self.number) ^ self.number
def mul_by_0d(self):
return self.mul_by_02(self.mul_by_02(self.mul_by_02(self.number))) ^ \
self.mul_by_02(self.mul_by_02(self.number)) ^ self.number
def mul_by_0e(self):
return self.mul_by_02(self.mul_by_02(self.mul_by_02(self.number))) ^ \
self.mul_by_02(self.mul_by_02(self.number)) ^ self.mul_by_02(self.number)
def mul_by(self, other):
pass
multiply_operator = galua_multiply()