URL
https://opencores.org/ocsvn/or1k/or1k/trunk
Subversion Repositories or1k
[/] [or1k/] [trunk/] [insight/] [expect/] [example/] [decryptdir] - Rev 1765
Compare with Previous | Blame | View Log
#!../expect --# Name: cryptdir# Author: Don Libes, NIST## Synopsis:# cryptdir [dir]# decryptdir [dir]## Encrypt or decrypts the current directory or named directory if given.if {[llength $argv] > 0} {cd $argv}# encrypt or decrypt?set decrypt [regexp "decrypt" $argv0]set timeout -1stty -echosend "Password:"expect -re "(.*)\n"send "\n"set passwd $expect_out(1,string)# wouldn't want to encrypt files with mistyped password!if !$decrypt {send "Again:"expect -re "(.*)\n"send "\n"if ![string match $passwd $expect_out(1,string)] {send_user "mistyped password?"stty echoexit}}stty echolog_user 0foreach f [glob *] {# strip shell metachars from filename to avoid problemsif [regsub -all {[]['`~<>:-]} $f "" newf] {exec mv $f $newfset f $newf}set strcmp [string compare .crypt [file extension $f]]if $decrypt {# skip files that don't end with ".crypt"if 0!=$strcmp continuespawn sh -c "exec crypt < $f > [file root $f]"} else {# skip files that already end with ".crypt"if 0==$strcmp continuespawn sh -c "exec crypt < $f > $f.crypt"}expect "key:"send "$passwd\r"expectwaitexec rm -f $fsend_tty "."}send_tty "\n"
