Ask Your Question

Revision history [back]

If you want to XOR you can just use integers directly with the ^^ operator in SageMath (or ^ in Python). Integers can be displayed as binary using e.g. the bin function:

sage: 32 ^^ 40
8
sage: bin(32)
'0b100000'
sage: bin(40)
'0b101000'
sage: bin(8)
'0b1000'

If your input is given as a string of ASCII characters then you can turn each character into an integer using the ord function:

sage: ord('A')
65

If you want to turn the output of ascii_to_bin into an integer, use ascii_integer:

sage: from sage.crypto.util import ascii_to_bin, ascii_integer
sage: ascii_integer(ascii_to_bin('A'))
65