Diffie–Hellman 鍵交換
出典: フリー百科事典『ウィキペディア(Wikipedia)』 (2021/12/13 00:36 UTC 版)
「dc (UNIX)」の記事における「Diffie–Hellman 鍵交換」の解説
より複雑な例では、Perl スクリプトに組み込まれている Diffie–Hellman 鍵交換がある。これは ITAR 議論のときにサイファーパンクたちの間で人気であった。このスクリプトは Unix ライクな OS にはどこにでもある Perl と dc だけで実行できる: #!/usr/bin/perl -- -export-a-crypto-system-sig Diffie-Hellman-2-lines($g, $e, $m) = @ARGV, $m || die "$0 gen exp mod\n";print `echo "16dio1[d2%Sa2/d0<X+d*La1=z\U$m%0]SX$e"[$g*]\EszlXx+p | dc` これのコメント付きのバージョンは少しわかりやすく、ループや条件分岐、マクロから脱出するための q コマンドなどの使い方が示されている。GNU の dc では、以下のコード中でレジスタ X に格納されるマクロを使う代わりに | コマンドで冪剰余を演算できる。 #!/usr/bin/perlmy ($g, $e, $m) = map { "\U$_" } @ARGV;die "$0 gen exp mod\n" unless $m;print `echo $g $e $m | dc -e '# Hex input and output16dio# Read m, e and g from stdin on one line?SmSeSg# Function z: return g * top of stack[lg*]sz# Function Q: remove the top of the stack and return 1[sb1q]sQ# Function X(e): recursively compute g^e % m# It is the same as Sm^Lm%, but handles arbitrarily large exponents.# Stack at entry: e# Stack at exit: g^e % m# Since e may be very large, this uses the property that g^e % m == # if( e == 0 )# return 1# x = (g^(e/2)) ^ 2# if( e % 2 == 1 )# x *= g# return x %[ d 0=Q # return 1 if e==0 (otherwise, stack: e) d 2% Sa # Store e%2 in a (stack: e) 2/ # compute e/2 lXx # call X(e/2) d* # compute X(e/2)^2 La1=z # multiply by g if e%2==1 lm % # compute (g^e) % m] SXle # Load e from the registerlXx # compute g^e % mp # Print the result'`;
※この「Diffie–Hellman 鍵交換」の解説は、「dc (UNIX)」の解説の一部です。
「Diffie–Hellman 鍵交換」を含む「dc (UNIX)」の記事については、「dc (UNIX)」の概要を参照ください。
- Diffie–Hellman 鍵交換のページへのリンク