I have a text file containing in each line an hexadecimal plaintext, My file looks like this:
7a8e5dc390781eab8df2c090bf4bebca
dbac0fba55d3d4fc177161bfe24dc7fb
82e5a7a021197f6fbe94a867d4bb3895
850580c1ffec887c5000c9b3a0e6b39d
1526af37ce4b0b4e81f8af0647e37119
bab19c53fd86e6afc933276b286e0c36
b52e53007bebe8877ce569ad2494dd76
44fd87e9b1a40a929ab6135665c22d0f
a88e5141ddc99e0207a9e144f4010a22
58ff597819ea0aa37024a1f1f84c5224
I need to convert each line to an array, I mean by that my numpy file must look like this:
[
[7a,8e,5d,c3,90,78,1e,ab,8d,f2,c0,90,bf,4b,eb,ca],[db,ac,0f,ba,55,d3,d4,fc,17,71,61,bf,e2,4d,c7,fb],
......., ]
import numpy as np
In_path= "/home/msmache/Bureau/testPlaintext.txt"
Out_path= "/home/msmache/Bureau/testPlaintext.npy"
with open(In_path, "r") as In_f:
all_arrays = []
Plaintext=[]
for line in In_f:
Plaintext=['{:02x}'.format(b) for b in line]
all_arrays.append(Plaintext)
print all_arrays
with open(Out_path, "wb") as Out_f:
np.save(Out_path, all_arrays)
data = np.load(Out_path)
print data
This is the error that I have:
Plaintext=['{:02x}'.format(b) for b in line]
ValueError: Unknown format code 'x' for object of type 'str'