Cryptography hex,binaries and ascii python
Question: I am new to cryptography and when it comes to xor I get really confused. Given
a text in ascii and a cipher in hex how can I get them to be both in the same
format? My current code is:

    
    
    import binascii
    string = b'09e1c5f70a65ac519458e7e53f36'
    binary = binascii.unhexlify(string)
    #This make the hex string to raw bytes
    

My question is how can I get an ascii string to be in raw bytes also so I can
xor? or if it is not possible what should I do to xor?


Answer: ascii is simply a byte string

    
    
    XOR_WITH = 0x12
    
    def xor_encode(byte):
        if isinstance(byte,basestring):
            byte = ord(byte) #convert to ascii integer value
        byte = byte ^ XOR_WITH #encode
        return chr(byte) # convert it back to a string and return
    
    encoded_string = "".join(map(xor_encode,"Test String"))
    

maybe what you are looking for

