I have written a simple python module that reads in a file and converts the read data to a list of hex values. I then incremented each value by 1. I was wondering how I could write this list of hex values to a new file.
Using python 3.x
Code:
inFilePath = input("Input File: ")
inFile = open(inFilePath, "rb")
data = inFile.read()
hexVals = []
for byte in data:
hexVals.append(hex(byte))
print("File Read")
print("Original Data: " + str(hexVals))
for x in range(hexVals.__len__()):
hexVals[x] = hex(int(hexVals[x], 16) + 1)
print("Altered Data: " + str(hexVals))
outFilePath = input("Output File: ")
outFile = open(outFilePath, "wb")
outFile.write(???)
You’re storing your bytes as hexadecimal strings. You can do that, but it already gives the result to you as integers. Just leave it as integers, although you may want to convert it into a list. After it’s been converted to a list, you can convert it back into
bytesin a rather simple way. For example: