Ask Your Question

Revision history [back]

unable to coerce <class 'sage.monoids.string_monoid_element.stringmonoidelement'=""> to an integer

In the following code snippet,

from sage.crypto.util import ascii_to_bin

arr = [12, 32, 40]

arr2 = [ascii_to_bin(chr(arr[i])) for i in range(0,len(arr))]

print(arr2)

print(type(arr2[0]))

Output: [00001100, 00100000, 00101000] <class 'sage.monoids.string_monoid_element.stringmonoidelement'="">

What I seek is the conversion of 00001100 to Integer, not like the ASCII from binary but more on the lines of a format that I can use for XORing later. I tried converting to Integer class which proved futile. What I want to do is eventually XOR each bit of the binary representation of each element of arr with something else.

click to hide/show revision 2
None

unable to coerce <class 'sage.monoids.string_monoid_element.stringmonoidelement'=""> to an integer

In the following code snippet,

from sage.crypto.util import ascii_to_bin

ascii_to_bin

arr = [12, 32, 40]

40]

arr2 = [ascii_to_bin(chr(arr[i])) for i in range(0,len(arr))]

range(0,len(arr))] print(arr2) print(type(arr2[0]))

print(arr2)

print(type(arr2[0]))

Output: [00001100, 00100000, 00101000] <class 'sage.monoids.string_monoid_element.stringmonoidelement'="">

'sage.monoids.string_monoid_element.StringMonoidElement'>

What I seek is the conversion of 00001100 to Integer, not like the ASCII from binary but more on the lines of a format that I can use for XORing later. I tried converting to Integer class which proved futile. What I want to do is eventually XOR each bit of the binary representation of each element of arr with something else.