OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [expect/] [example/] [decryptdir] - Blame information for rev 1774

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
#!../expect --
2
# Name: cryptdir
3
# Author: Don Libes, NIST
4
#
5
# Synopsis:
6
#         cryptdir [dir]
7
#       decryptdir [dir]
8
#
9
# Encrypt or decrypts the current directory or named directory if given.
10
 
11
if {[llength $argv] > 0} {
12
        cd $argv
13
}
14
 
15
# encrypt or decrypt?
16
set decrypt [regexp "decrypt" $argv0]
17
 
18
set timeout -1
19
stty -echo
20
send "Password:"
21
expect -re "(.*)\n"
22
send "\n"
23
set passwd $expect_out(1,string)
24
 
25
# wouldn't want to encrypt files with mistyped password!
26
if !$decrypt {
27
        send "Again:"
28
        expect -re "(.*)\n"
29
        send "\n"
30
        if ![string match $passwd $expect_out(1,string)] {
31
                send_user "mistyped password?"
32
                stty echo
33
                exit
34
        }
35
}
36
stty echo
37
 
38
log_user 0
39
foreach f [glob *] {
40
        # strip shell metachars from filename to avoid problems
41
        if [regsub -all {[]['`~<>:-]} $f "" newf] {
42
                exec mv $f $newf
43
                set f $newf
44
        }
45
 
46
        set strcmp [string compare .crypt [file extension $f]]
47
        if $decrypt {
48
                # skip files that don't end with ".crypt"
49
                if 0!=$strcmp continue
50
                spawn sh -c "exec crypt < $f > [file root $f]"
51
        } else {
52
                # skip files that already end with ".crypt"
53
                if 0==$strcmp continue
54
                spawn sh -c "exec crypt < $f > $f.crypt"
55
        }
56
        expect "key:"
57
        send "$passwd\r"
58
        expect
59
        wait
60
        exec rm -f $f
61
        send_tty "."
62
}
63
send_tty "\n"

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.