Upgrade yt-dlp from version stable@2023.07.06 to stable@2023.09.24
[sunny256-utils.git] / cryptit
blob88a786ecbbad6a74f637a903c6e5eb1ccdc90bd1
1 #!/usr/bin/env perl
3 ##
4 ## Written by Owen Taylor <otaylor@redhat.com>
5 ##
7 use warnings;
9 BEGIN {
10 use POSIX qw(:termios_h);
12 my ($term, $oterm, $echo, $noecho, $fd_stdin);
14 $fd_stdin = fileno(STDIN);
16 $term = POSIX::Termios->new();
17 $term->getattr($fd_stdin);
18 $oterm = $term->getlflag();
20 $echo = ECHO | ECHOK | ICANON;
21 $noecho = $oterm & ~$echo;
23 sub noecho {
24 $term->setlflag($noecho);
25 $term->setattr($fd_stdin, TCSANOW);
28 sub echo {
29 $term->setlflag($oterm);
30 $term->setattr($fd_stdin, TCSANOW);
34 END { echo() }
36 # Get random seed
38 open(RANDOM, "/dev/random") || die "Can't open /dev/random: $!";
39 read(RANDOM, $a, 8) || die "Can't read: $!";
40 close RANDOM;
42 $a = join ("", map { chr(ord('0') + ord($_)%64) } split //,$a);
43 $a =~ s/[^A-Za-z0-9]//g;
45 my ($result1, $result2);
47 $| = 0;
49 while (1) {
50 print "Enter passwd: ";
51 noecho;
52 $password = <>;
53 chomp($password);
54 $result1 = crypt($password, substr($a,0,2));
55 echo;
56 print "\nReenter passwd to verify: ";
57 noecho;
58 $password = <>;
59 chomp($password);
60 $result2 = crypt($password, substr($a,0,2));
61 echo;
63 if ($result1 ne $result2) {
64 print "\nPasswords did not match, try again\n";
65 } else {
66 last;
70 print "\nCrypted value is: $result1\n";