2020-06-02 23:08:22 +0200 | asked a question | defining a function with input anything Hi I would like to define a function (call it Mlist) taking in principle anything (numbers, strings or symbols) and gives an output an array of two symbols A and B in such a way that if the ascii digit of the input is 0, the output will be A otherwise it will be B For example: Mlist(H)=ABAABAAA since the ascii code for H is 01001000. I wrote the following, but no success sage: def Mlist( ): ....: MatAB=[] ....: for i in range(len(ascii_to_bin( ))): ....: if ascii_to_bin()[i]==bin.encoding('0')[0]: ....: MatAB.append(A) ....: else: ....: MatAB.append(B) ....: return MatAB ....: sage: Calling the function, for ex. Mlist(a) gives me the following error. TypeError Traceback (most recent call last) <ipython-input-48-ebdfa1f89856> in <module>() ----> 1 Mlist(a) TypeError: Mlist() takes no arguments (1 given) sage: This is clearly the result of my limited programming experience and any help is appreciated. |
2020-06-02 13:23:35 +0200 | received badge | ● Student (source) |
2020-06-02 13:19:55 +0200 | asked a question | Ignoring binary string monoid I was just wondering what can I do to convert the binary digits (for ex. ASCII) shown below to integers. sage: from sage.crypto.util import ascii_to_bin sage: from sage.crypto.util import ascii_integer sage: bin=BinaryStrings() sage: B=bin.encoding("A"); B 01000001 sage: ascii_integer(B) 65 sage: parent(B) Free binary string monoid sage: parent(ascii_integer(B)) <type 'int'=""> sage: |
2020-06-02 13:19:55 +0200 | asked a question | How to identify binary digits as integers? I would like to know how to recognize the ASCII binary codes of a string as integers values. Look at the following example. sage: from sage.crypto.util import ascii_to_bin sage: ascii_to_bin('Hi') 0100100001101001 sage: ascii_to_bin('Hi')[4] 1 sage: ascii_to_bin('Hi')[4] in ZZ False sage: I would be thankful if I get some tips on how to identify the binary digits as integers. |