Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
36
Task/Vigen-re-cipher/Tcl/vigen-re-cipher-1.tcl
Normal file
36
Task/Vigen-re-cipher/Tcl/vigen-re-cipher-1.tcl
Normal 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
|
||||
}
|
||||
}
|
||||
7
Task/Vigen-re-cipher/Tcl/vigen-re-cipher-2.tcl
Normal file
7
Task/Vigen-re-cipher/Tcl/vigen-re-cipher-2.tcl
Normal 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"
|
||||
Loading…
Add table
Add a link
Reference in a new issue