new files
This commit is contained in:
parent
3af7344581
commit
86c034bb8b
1364 changed files with 21352 additions and 0 deletions
23
Task/Caesar-cipher/Tcl/caesar-cipher-1.tcl
Normal file
23
Task/Caesar-cipher/Tcl/caesar-cipher-1.tcl
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
package require Tcl 8.6; # Or TclOO package for 8.5
|
||||
|
||||
oo::class create Caesar {
|
||||
variable encryptMap decryptMap
|
||||
constructor shift {
|
||||
for {set i 0} {$i < 26} {incr i} {
|
||||
# Play fast and loose with string/list duality for shorter code
|
||||
append encryptMap [format "%c %c %c %c " \
|
||||
[expr {$i+65}] [expr {($i+$shift)%26+65}] \
|
||||
[expr {$i+97}] [expr {($i+$shift)%26+97}]]
|
||||
append decryptMap [format "%c %c %c %c " \
|
||||
[expr {$i+65}] [expr {($i-$shift)%26+65}] \
|
||||
[expr {$i+97}] [expr {($i-$shift)%26+97}]]
|
||||
}
|
||||
}
|
||||
|
||||
method encrypt text {
|
||||
string map $encryptMap $text
|
||||
}
|
||||
method decrypt text {
|
||||
string map $decryptMap $text
|
||||
}
|
||||
}
|
||||
7
Task/Caesar-cipher/Tcl/caesar-cipher-2.tcl
Normal file
7
Task/Caesar-cipher/Tcl/caesar-cipher-2.tcl
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
set caesar [Caesar new 3]
|
||||
set txt "The five boxing wizards jump quickly."
|
||||
set enc [$caesar encrypt $txt]
|
||||
set dec [$caesar decrypt $enc]
|
||||
puts "Original message = $txt"
|
||||
puts "Encrypted message = $enc"
|
||||
puts "Decrypted message = $dec"
|
||||
Loading…
Add table
Add a link
Reference in a new issue