I am currently beginning python, and writing a program that will convert a given long string of hex numbers, that should be separated into pairs. I am having a hard time utilizing pythons encoding function.
So far, I have:
import base64
def splitByTwo(str):
return [i+j for i,j in zip(list(str)[::2], list(str)[1::2])]
def bytesToBase64(str):
b64List = []
stringsByTwo = splitByTwo(str.upper())
for x in stringsByTwo:
b64List.insert(stringsByTwo.index(x), base64.b16decode(x))
return b64List
print(bytesToBase64("49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d"))
I can get it to print [b'I', b"'", b'm', b'm', b'm', b' ', b' ',.....] but I am not sure what is wrong with my encode/decode to base64 section of the bytesToBase64() method.