Ask Your Question
1

How to make a hexadecimal number into a string

asked 2021-05-21 22:49:13 +0100

Sanu gravatar image

I generate a hexadecimal number 0xffffffffffffffffffffffffffffffff like

s=0

for i in range(128):

s=s+2^i

s=hex(s)

I want to make it string like 'ffffffffffffffffffffffffffffffff' so that I can pass it as follows:

from sage.crypto.mq.rijndael_gf import RijndaelGF

rgf = RijndaelGF(4, 4)

state = rgf._hex_to_GF('ffffffffffffffffffffffffffffffff')

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
2

answered 2021-05-21 23:20:59 +0100

Glenn Tesler gravatar image

For a Sage integer (vs. python int), s.hex() gives just the hex digits, without the prefix '0x':

sage: s=123456                                                                  
sage: s.hex()                                                                   
'1e240'

hex(s) includes the prefix '0x':

sage: hex(s)                                                                    
'0x1e240'

You could strip off '0x' with hex(s)[2:], but s.hex() is simpler.

sage: hex(s)[2:]                                                                
'1e240'
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2021-05-21 22:49:13 +0100

Seen: 1,517 times

Last updated: May 21 '21