#!/usr/bin/perl use strict; use warnings; use Math::BigInt; sub input; my @id; push @id, input "Alice's secret key" => 28; push @id, input "Bob's secret key" => 28; my $sh=input "the public key" => 50; my @mid=map $_*$sh, @id; for (@mid) { substr $_, 0, 11 => ''; substr $_, -11, 11 => ''; } my ($pwa,$pwb)=map { substr $id[$_]*$mid[1-$_], -55, 10 } 0,1; print $pwa eq $pwb ? "The passwords match: <$pwa>\n" : "The passwords don't match:\n<$pwa>\n<$pwb>\n"; sub input { local $\="\n"; my ($msg,$n)=@_; my $m=$n-1; print "Please input $msg, a $n digits number, ", "or for a random one"; my $in; { print '-' x $n; chomp($in=); if (lc $in eq 'r') { $in = 1 + int rand 9; $in .= int rand 10 for 1..$m; print $in; last; } print "Wrong input, retry" and redo unless $in =~ /^[1-9][0-9]{$m}$/; } print ''; Math::BigInt->new($in); } __END__