-
Notifications
You must be signed in to change notification settings - Fork 4
/
cryptit
executable file
·70 lines (52 loc) · 1.31 KB
/
cryptit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env perl
##
## Written by Owen Taylor <otaylor@redhat.com>
##
use warnings;
BEGIN {
use POSIX qw(:termios_h);
my ($term, $oterm, $echo, $noecho, $fd_stdin);
$fd_stdin = fileno(STDIN);
$term = POSIX::Termios->new();
$term->getattr($fd_stdin);
$oterm = $term->getlflag();
$echo = ECHO | ECHOK | ICANON;
$noecho = $oterm & ~$echo;
sub noecho {
$term->setlflag($noecho);
$term->setattr($fd_stdin, TCSANOW);
}
sub echo {
$term->setlflag($oterm);
$term->setattr($fd_stdin, TCSANOW);
}
}
END { echo() }
# Get random seed
open(RANDOM, "/dev/random") || die "Can't open /dev/random: $!";
read(RANDOM, $a, 8) || die "Can't read: $!";
close RANDOM;
$a = join ("", map { chr(ord('0') + ord($_)%64) } split //,$a);
$a =~ s/[^A-Za-z0-9]//g;
my ($result1, $result2);
$| = 0;
while (1) {
print "Enter passwd: ";
noecho;
$password = <>;
chomp($password);
$result1 = crypt($password, substr($a,0,2));
echo;
print "\nReenter passwd to verify: ";
noecho;
$password = <>;
chomp($password);
$result2 = crypt($password, substr($a,0,2));
echo;
if ($result1 ne $result2) {
print "\nPasswords did not match, try again\n";
} else {
last;
}
}
print "\nCrypted value is: $result1\n";