Skip to content

Commit 4cdaf4a

Browse files
authored
Add Rot13 in Tcl (#5080)
1 parent 27464e9 commit 4cdaf4a

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

archive/t/tcl/rot13.tcl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
proc usage {} {
3+
puts "Usage: please provide a string to encrypt"
4+
exit 1
5+
}
6+
7+
if {$argc != 1} { usage }
8+
set input [lindex $argv 0]
9+
if {$input eq ""} { usage }
10+
11+
proc rot13 {text} {
12+
set upper "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
13+
set lower "abcdefghijklmnopqrstuvwxyz"
14+
15+
set map {}
16+
17+
for {set i 0} {$i < 26} {incr i} {
18+
lappend map [string index $upper $i] [string index $upper [expr {($i+13)%26}]]
19+
lappend map [string index $lower $i] [string index $lower [expr {($i+13)%26}]]
20+
}
21+
22+
return [string map $map $text]
23+
}
24+
25+
puts [rot13 $input]
26+

0 commit comments

Comments
 (0)