-
Notifications
You must be signed in to change notification settings - Fork 4
/
de_crypt_simple1.tcl
70 lines (54 loc) · 1.44 KB
/
de_crypt_simple1.tcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#===========================================
# de_crypt_simple1.tcl :
# ֌, 2004 year
# êîäèðîâàíèå-ðàñêîäèðîâàíèå.
# ïðîñòîé ñïîñîá - òèïà XOR
#===========================================
proc de_crypt { src_file dst_file } {
if {![file exists $src_file]} { return -1 ; }
set src [ open $src_file "r" ] ;
set dc [ open $dst_file "w" ] ;
while { ![ eof $src ] } {
gets $src line ;
set c '' ;
set sl [ string length $line ] ;
set line2 "";
for { set i 0 } { $i<$sl } { incr i } {
set j [ expr ($sl - $i - 1) ] ;
set c [ string index $line $j ] ;
set c [ expr 158 - [ scan $c "%c" ] ];
set c [ format "%c" $c ]
append line2 $c ;
}
set line2 [ string range $line2 0 $sl ]
puts $dc $line2
}
close $src
flush $dc
close $dc
puts "\n $src_file -> $dst_file ........ done\n" ;
return 0;
}
proc fileDialog { t } {
set types {
{"Tcl\Tk Files" {.tcl .tk} }
{"Text files" {.txt .dat} }
{"All files" *}
}
switch $t {
1 { set file [ tk_getOpenFile -initialdir "" -title "Âûáåðèòå ôàéë...." -filetypes $types ] ; }
2 { set file [ tk_getSaveFile -initialdir "" -title "Âûáåðèòå ôàéë...." -filetypes $types ] ; }
}
if {$file==""} {
tk_messageBox -message "Âû íå âûáðàëè\çàäàëè ôàéë."
exit ;
}
return $file
}
proc main { } {
set fileopen [ fileDialog 1 ]
set filesave [ fileDialog 2 ]
de_crypt $fileopen $filesave ;
return 0;
}
main