################################################################ # proc encrypt {txt}-- # encrypt the input text. # Arguments # txt The text to be converted. # # Results # No side effects # # Fill the lookup table set alpha \ {a b c d e f g h i j k l m n o p q r s t u v w x y z} proc encrypt {txt} { global alpha # Iterate through characters foreach char [split $txt {}] { set pos [lsearch $alpha $char] # If character is in list, encrypt it, else keep the character if {$pos >= 0} { set pos2 [expr {($pos + 13) %26}] set char2 [lindex $alpha $pos2] } else { set char2 $char } append encrypt $char2 } return $encrypt } ################################################################ # proc encryptWin {inWin outWin}-- # Read characters from inWin and insert encrypted characters # into outWin # Arguments # inWin: Name of a text widget to read input from # outWin: Name of a text widget to write encrypted text to # Results # outWin widget contents are modified. # proc encryptWin {inWin outWin} { set txt [$inWin get 0.0 end] $outWin delete 0.0 end $outWin insert 0.0 [encrypt $txt] } set w [text .plain] grid $w -columnspan 3 set w [text .encrypt] grid $w -columnspan 3 set w1 [button .b_encrypt -text "Encrypt" -command {encryptWin .plain .encrypt }] set w2 [button .b_exit -text "Exit" -command exit] grid $w1 $w2