Esempio n. 1
0
 def test_BaseElement(self):
     self.assertEqual([{
         boolean.TRUE: boolean.TRUE
     }], boolean.truth_table(boolean.TRUE))
     self.assertEqual([{
         boolean.FALSE: boolean.FALSE
     }], boolean.truth_table(boolean.FALSE))
Esempio n. 2
0
 def test_format_str(self):
     expr = boolean.Symbol("A")
     table = boolean.truth_table(expr, True)
     for row in table:
         for k, v in row.items():
             self.assertIsInstance(k, str)
             self.assertIsInstance(v, str)
             self.assertTrue(v in (str(boolean.TRUE), str(boolean.FALSE)))
Esempio n. 3
0
 def table(self, table):
     if isinstance(table, str):
         table = boolean.parse(table, False)
     if isinstance(table, boolean.Expression):
         table = boolean.truth_table(table)
     else:
         raise TypeError("Argument must be Expression but it is {}".format(
             table.__class__))
     # Table should not be directly modified
     return tuple(table)
Esempio n. 4
0
    def test_correct_permutations(self):
        expr_list = (boolean.Symbol("A") + boolean.Symbol("B"),
                     boolean.Symbol("A"),
                     boolean.Symbol(None) * boolean.Symbol("B"),
                     ~boolean.Symbol("A") + boolean.Symbol("B"))

        for expr in expr_list:
            table = boolean.truth_table(expr)
            self.assertEqual(len(table), 2**len(expr.symbols))

            for i in range(1, len(table)):
                self.assertEqual(table[1].keys(), table[i].keys())
                self.assertNotEqual(table[0].values(), table[i].values())
                for v in table[0].values():
                    self.assertTrue(v in (boolean.TRUE, boolean.FALSE))

            for s in expr.symbols:
                self.assertTrue(s in table[0].keys())
            self.assertTrue(s in table[0].keys())
        sums ^= (coef[i] & x[i])
    return sums ^ const


def xor(x, y):
    xor = []
    for i in range(len(x)):
        xor.append(x[i] ^ y[i])
    return xor


size = 8
inputs = bo.convert_to_binary(size)

#Truth Table
fonk_input = bo.truth_table(f, inputs)
print("Truth table: ", fonk_input)
print("Weight:", fonk_input.count(1))
#Non linearity
aft = bo.non_linearity(f, affine, size, inputs)
print("Non linearity: ", aft)
#Non homomoprpicity
x = bo.non_homo(f, size, inputs)
print("Non homomorpicity: ", x)
#Correlation immunity
cor = bo.correlation_im1(f, affine, size, inputs)
print("Not correlation immune because of ", cor)

# Propogation characteristics of f
prop = bo.pc1(f, xor, size, inputs)
print("Not prop. characteristic because of ", prop)