Back in the ITAR era, there was a popular sig that performed Diffie-Hellman key exchange:
#!/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`
With a modern dc, this can be reduced quite a bit to:
dc -e '16dio???|p'
While the modern dc form with the modular exponentiation command ('|' computes g^e % m via efficient exponential doubling) is likely unbeatable other than perhaps APL, can the original form be improved upon? Keep in mind that the e and m values will be very large; they will both be on the order of 1024 bits each for cryptographic security.