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,36 @@
package require Tcl 8.6
oo::class create Vigenere {
variable key
constructor {protoKey} {
foreach c [split $protoKey ""] {
if {[regexp {[A-Za-z]} $c]} {
lappend key [scan [string toupper $c] %c]
}
}
}
method encrypt {text} {
set out ""
set j 0
foreach c [split $text ""] {
if {[regexp {[^a-zA-Z]} $c]} continue
scan [string toupper $c] %c c
append out [format %c [expr {($c+[lindex $key $j]-130)%26+65}]]
set j [expr {($j+1) % [llength $key]}]
}
return $out
}
method decrypt {text} {
set out ""
set j 0
foreach c [split $text ""] {
if {[regexp {[^A-Z]} $c]} continue
scan $c %c c
append out [format %c [expr {($c-[lindex $key $j]+26)%26+65}]]
set j [expr {($j+1) % [llength $key]}]
}
return $out
}
}

View file

@ -0,0 +1,7 @@
set cypher [Vigenere new "Vigenere Cipher"]
set original "Beware the Jabberwock, my son! The jaws that bite, the claws that catch!"
set encrypted [$cypher encrypt $original]
set decrypted [$cypher decrypt $encrypted]
puts $original
puts "Encrypted: $encrypted"
puts "Decrypted: $decrypted"