Diffie-Hellman-Script

Aus xinux.net
Zur Navigation springen Zur Suche springen

Diffie-Hellman berechnen

#!/bin/bash
g=$1 ; p=$2 ; A=$3 ;B=$4
function dh()
{
 x=1
 X=$1
 while true
  do
   if [[ $(echo "$g ^ $x  % $p" | bc ) = $X ]]
    then
    echo $x
    return
  fi
  x=$((x+1))
 done
}
a=$(dh $A)
echo "$B ^ $a % $p" | bc