#!/usr/bin/perl use CGI qw(param); # Compute RSA encryption: m^a (mod n) print "Content-type: text/html\n\n"; print "Output
\n"; my $m = param("inputm"); my $a = param("inputa"); my $n = param("inputn"); $m=int($m); $a=int($a); $n=int($n); $errorm=0; $errora=0; $errorn=0; if($m<=0){$errorm=1; print "Your value of m must be an integer bigger than 0.
\n";} if($a<=0){$errora=1; print "Your value of a must be an integer bigger than 0.
\n";} if($n<=0){$errorn=1; print "Your value of n must be an integer bigger than 0.
\n";} if($m>10000000){$errorm=2; print "Your value of m must be an integer less than 10,000,000.
\n";} if($a>10000000){$errora=2; print "Your value of a must be an integer less than 10,000,000.
\n";} if($n>10000000){$errorn=2; print "Your value of n must be an integer less than 10,000,000.
\n";} if($errorm+$errora+$errorn>0){print "Please try again.
\n";} else {$gcf=EuclidAlg($m,$n); print "Note: gcf($m,$n)=$gcf.

\n"; $i=$a; $p=1; while($i>0){ $p=($p*$m)%$n; $i=$i-1; } print "Here is your answer: $m$a = $p (mod $n)\n\n\n\n\n"; } print "\n"; sub EuclidAlg { # This subroutine does Euclid's Algorithm and returns gcf(a, b) my($a,$b) = @_; my($r); $r = $a%$b; while($r>0){ $a=$b; $b=$r; $r=$a%$b; # print "$a, $b, $r\n"; } return ($b);}