#!/usr/bin/env tclsh gets stdin cpub gets stdin dpub # From rosettacode proc tcl::mathfunc::modexp {a b n} { if {$b == 0} {return 1} set c [expr {modexp($a, $b / 2, $n)**2 % $n}] if {$b & 1} { set c [expr {($c * $a) % $n}] } return $c } # Call the C program to find the private key (loop size) for one of the # inputs. Then use modexp to calculate the encryption key using the # other input. set cpriv [exec ./25c $cpub] puts [expr {modexp($dpub,$cpriv,20201227)}]