3
は私が各行に進平文を含むテキストファイルを持って、私のファイルは、次のようになります。テキストファイルの16進数の行を配列(Python)に変換する方法は?
7a8e5dc390781eab8df2c090bf4bebca
dbac0fba55d3d4fc177161bfe24dc7fb
82e5a7a021197f6fbe94a867d4bb3895
850580c1ffec887c5000c9b3a0e6b39d
1526af37ce4b0b4e81f8af0647e37119
bab19c53fd86e6afc933276b286e0c36
b52e53007bebe8877ce569ad2494dd76
44fd87e9b1a40a929ab6135665c22d0f
a88e5141ddc99e0207a9e144f4010a22
58ff597819ea0aa37024a1f1f84c5224
は、私は、私は私のnumpyのファイルは次のように見なければならないということで意味配列にそれぞれの行を変換する必要があります。
[
[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
これは私が持っているエラーは、次のとおりです。
は、行の文字を出すので、あなたが各反復のためにそれらの2を必要とするだろう一方Plaintext=['{:02x}'.format(b) for b in line]
ValueError: Unknown format code 'x' for object of type 'str'
ご協力いただきありがとうございます。 – nass9801
文字列表示を避けるには? [7a、8e、5d、c3,90,78,1e、ab、8d、f2、c0,90、bf、4b、eb、ca]この形式ではない:['7a' 「8e」「5d」「c3」「90」「78」「1e」「ab」「8d」「f2」「c0」「90」「bf」 '4b'、 'eb'、 'ca']。numpyファイルをバイナリファイルに変換する際に問題があるためです。 – nass9801
あなたは16進数が欲しいという意味ですか?簡単ですが、リストに '0x'という接頭辞が付きます。私はそれがあなたが望むものだと思う:数字。私の答えを編集させてください。編集されました。 –