1

crypto libs sha1戻り形式を変換するためのライブラリ呼び出しがどこかにあるかどうか疑問に思っています

15 ?- sha_hash('howdy', X , []), atom_codes(Y, X).
X = [239, 66, 186, 177, 25, 29, 162, 114, 241|...],
Y = 'ïBº±\031\\035\¢rñ95÷\214\@\036\=àÁ\032\û'.

Xを次のような形式に変換したい

「A34F890F16」

4

2 に答える 2

2
?- sha_hash('howdy', X , []),
 atom_codes(Y, X),
 maplist(\I^format('~16R',[I]),X).

出力

EF42BAB1191DA272F13935F78C401E3DE0C11AFB
X = [239, 66, 186, 177, 25, 29, 162, 114, 241|...],
Y = 'ïBº±\031\\035\¢rñ95÷\214\@\036\=àÁ\032\û'.

しかし、もちろん上の文字列はあいまいです...

別の方法として、「手動で」パディングをこの方法で行うこともできます (ここでは 1 つのコードのみ)。

?- phrase(xinteger(3), L, []),
   (L =[A] -> N = [48,A] ; N = L),
   format('~s',[N]).

出力

03
L = [51],
A = 51,
N = [48, 51] .

xinteger//1 にはこれを含める必要があります:- [library(http/dcg_basics)].

編集:パディングの仕様文字列を見つけました:

?- format('~`0t~16R~2|', [15]).
0F
true.

次に、元の例を書くことができます

?- sha_hash('howdy', X , []),
     atom_codes(Y, X),
     maplist(\I^format('~`0t~16R~2|',[I]),X).

そして、これは出力します

EF42BAB1191DA272F13935F78C401E3DE0C11AFB
X = [239, 66, 186, 177, 25, 29, 162, 114, 241|...],
Y = 'ïBº±\031\\035\¢rñ95÷\214\@\036\=àÁ\032\û'.

出力は with_output_to で簡単に取得できます

atom_to_hex(Atom, Hex) :-
    atom_codes(Atom, Codes),
    with_output_to(Hex, maplist(\I^format('~`0t~16R~2|',[I]), Codes)).

これらの例はすべてlibrary(lambda)を使用しています。

于 2012-02-24T19:05:10.390 に答える