What is a quick method of string to integer conversion in Python 2.7 -


I am using Python 2.7.6. I am researching the author of the article to define a message and key:

  message = "hello world" key = "supersecret"   

To get my cipher text for the binary value of these two wires, I know that I can represent the string of hex value of the string like: / code> < P> However, hexMessage and hexkey are still strings I believe I should call them in Ijr Litrls should be if I want to native) XOR (dragon on them (please correct me if I'm wrong). In other words, I want to do something on the lines of the cipherText = hexMesage ^ hexKey

If i is print Hex Message, Hekski , I get:

48656c6c6f20576f726c64 7375706572736563726574

If I try this value, I get an error: TypeError: unsupported ^: operand type for 'str' and 'str' (S) This is not surprising for me, because I think that they are string representations of hexadecimal values. I can do this:

  realHexMessage = 0x48656c6c6f20576f726c64 realHexKey = 0x7375706572736563726574 cipher = realHexMessage ^ realHexKey   

Unfortunately, I string copy to achieve values used to paste the Heksmsej and Hekske my terminal, then he was prepaid with 0x in your code so that the XOR ed to the literal value clearly From, I am doing it wrong lot .

My question is, what is a quick way to change my message using ^ operator by XOR And can add key string variables to their literal counterpart <

Actually, it changes each character in the string for a numerical byte using the ord , and then this format in hex, hex characters join together, and Parses that a As a integer

  def convertor (A): return int ("" in x (x, 'x') format x (ord, a)], 16) message = "hello world" Print "0x% x"% convertToInteger (message)   

output:

  0x48656c6c6f20576f726c64    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -