Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View 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
}
}

View 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"