Hi all, Sometimes, especially with functions of 8 variables, the BooleanFunction.truth_table() method with format='hex" gives wrong values that are the wrong length. I don't yet have a login to Trac. Should I obtain one and report the bug there? All the best, Paul
*Bug in BooleanFunction.truth_table(format='hex")*To reproduce: ┌────────────────────────────────────────────────────────────────────┐ │ SageMath version 7.6, Release Date: 2017-03-25 │ │ Type "notebook()" for the browser-based notebook interface. │ │ Type "help()" for help. │ └────────────────────────────────────────────────────────────────────┘ sage: from sage.rings.integer_ring import ZZ sage: from sage.crypto.boolean_function import BooleanFunction sage: hex_str = "0123456789112345678921234567893123456789412345678951234567896123" sage: len(hex_str) 64 sage: bf = BooleanFunction(hex_str) sage: bf.nvariables() 8 sage: bf_tt_hex = bf.truth_table(format="hex") sage: bf_tt_hex '123456789112345678921234567893123456789412345670123456789112345678921234567893123456789412345678951234567896123' sage: len(bf_tt_hex) 111 sage: S = ZZ(bf.truth_table(), 2).str(16) sage: padding = "0" * ((1 << (bf.nvariables() - 2)) - len(S)) sage: tt_hex = padding + S sage: tt_hex '0123456789112345678921234567893123456789412345678951234567896123' sage: len(tt_hex) 64 Suspect source code: https://github.com/sagemath/sage/blob/develop/src/sage/crypto/boolean_function.pyx lines 566 to 576: if format == 'hex': S = "" S = ZZ(self.truth_table(),2).str(16) S = "0"*((1<<(self._nvariables-2)) - len(S)) + S for 1 <= i < self._truth_table.limbs: if sizeof(long)==4: t = "%04x"%self._truth_table.bits[i] if sizeof(long)==8: t = "%08x"%self._truth_table.bits[i] S = t + S return S This could simply be replaced by: if format == 'hex': S = ZZ(self.truth_table(),2).str(16) S = "0"*((1<<(self._nvariables-2)) - len(S)) + S return S -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/sage-support. For more options, visit https://groups.google.com/d/optout.
