line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package TXTCOD; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
TXTCOD - Encoding module using the SAC system. |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use TXTCOD; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
TXTCOD::codage($source, |
12
|
|
|
|
|
|
|
$destination, |
13
|
|
|
|
|
|
|
<$file.cod>, |
14
|
|
|
|
|
|
|
<$algorithm.alc>, |
15
|
|
|
|
|
|
|
<$param>); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
$param = TXTCOD::decodage($source, |
18
|
|
|
|
|
|
|
$destination, |
19
|
|
|
|
|
|
|
$file.cod, |
20
|
|
|
|
|
|
|
<$algorithm.alc>); |
21
|
|
|
|
|
|
|
$file.cod = TXTCOD::createcod; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 DESCRIPTION |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
TXTCOD 4.7 encodes files with the SAC system, 2.4 version.. |
26
|
|
|
|
|
|
|
The SAC system consists in several algorithms : a default algorithm who can be remplaced by user-written algorithms. Every algorithm uses a .cod file generated by the module and who contains a list of random numbers used by the module in order to ensure a maximal protection. |
27
|
|
|
|
|
|
|
B<< A file must be encoded with the same algorithm and the same .cod file !!! . >> |
28
|
|
|
|
|
|
|
This version of the SAC system can encode any type of file (binary files, text) and recognizes automatically their type. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
In the first part you will see the module's how-to and in the second part how to program an algorithm. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 FIRST PART : TXTCOD Module |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
These functions will be accessible after you have typed B<< use TXTCOD; >> |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head2 1) Encoding |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
You call the encoding function by typing : |
40
|
|
|
|
|
|
|
TXTCOD::codage($source, |
41
|
|
|
|
|
|
|
$destination, |
42
|
|
|
|
|
|
|
<$file.cod>, |
43
|
|
|
|
|
|
|
<$algorithm.alc>, |
44
|
|
|
|
|
|
|
<$param>); |
45
|
|
|
|
|
|
|
This function doesn't return any value. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
$source is the file you want to encode. |
48
|
|
|
|
|
|
|
$destination is the file where TXTCOD will send the result of the encoding. |
49
|
|
|
|
|
|
|
These two parameters are B<< obligatory >>. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
$file.cod is the .cod file who is indispensable for the encoding and the decoding. If you don't specify this parameter, will search a "[year].cod" file, for example "2003.cod". A .cod file MUST be changed every year at least in order to assure an optimal protection. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
$algorithm.alc is the used algorithm. If you don't put anything, TXTCOD will use the default algorithm. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
$param is an user-defined parameter who won't be crypted. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head2 2) Decoding |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
You call the decoding function by typing : |
60
|
|
|
|
|
|
|
$param = TXTCOD::decodage($source, |
61
|
|
|
|
|
|
|
$destination, |
62
|
|
|
|
|
|
|
$file.cod, |
63
|
|
|
|
|
|
|
<$algorithm.alc>); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
$source in the file you want to decode. |
66
|
|
|
|
|
|
|
$destination is the result of the decoding |
67
|
|
|
|
|
|
|
$file.cod et $algorithm.alc -> see the encoding function description. |
68
|
|
|
|
|
|
|
The returned value is the parameter you optionnally defined while the encoding and which isn't crypted. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head2 3) .cod files creation |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
To create a .cod file type : |
73
|
|
|
|
|
|
|
$file.cod = TXTCOD::createcod; |
74
|
|
|
|
|
|
|
The returned value is the file's name ("[year].cod") |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 SECOND PART : algorithms |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Writing an algorithm is simple : create a file ended by ".alc". This file will contain one-line commands who will tell the module the way to encode and decode your files. |
79
|
|
|
|
|
|
|
=head2 1) encoding |
80
|
|
|
|
|
|
|
The first part of the file will contain the encoding algorithm. |
81
|
|
|
|
|
|
|
This algorithm will have a few variables : |
82
|
|
|
|
|
|
|
- X, each encoded letter |
83
|
|
|
|
|
|
|
- A,B,C,D,E,F,G,H,I,J, script-defined variables. |
84
|
|
|
|
|
|
|
- T,M,P more secured variables |
85
|
|
|
|
|
|
|
There are many operators : |
86
|
|
|
|
|
|
|
- addition: "+" |
87
|
|
|
|
|
|
|
- subtraction: "-" |
88
|
|
|
|
|
|
|
- multiplication: "*" |
89
|
|
|
|
|
|
|
- division: "/" |
90
|
|
|
|
|
|
|
- power: "**" |
91
|
|
|
|
|
|
|
For example, we'll use the line : "X*(A+2)" in order to multiply the variable by (A+2). The compilation will be done internally by the module |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head2 2) decoding |
94
|
|
|
|
|
|
|
After the encoding part of the file, we will put a line containing only the word "end" without any blank or invisible character. After this word there is the decoding part. The variables of this part are the same thn in the first part. |
95
|
|
|
|
|
|
|
For example, if in the first part you put "X*(M+2)" you will type in the second part "X/(M+2)" in order to make the X variable becoming what she were before the encoding |
96
|
|
|
|
|
|
|
The root is done by this operation : for a "X**A" in the first part you will put "X**(1/A)" in the second. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head2 3) comments |
99
|
|
|
|
|
|
|
You can comment your algorithm by any line beginning with a sharp #. |
100
|
|
|
|
|
|
|
=head2 4) Notes |
101
|
|
|
|
|
|
|
You should not do operations who will make mubers (initial numbers up to 255) becoming too small or too big : perl will round the final numbers and the decoded letter will be very approximative. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 TO DO |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
* increase the velocity of the users' algorithm which is REALLY slower than the default algorithm :( |
106
|
|
|
|
|
|
|
* correct my poor english faults ;) and comment the script in english |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=cut |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
$VERSION = 4.71; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub codage{ |
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
0
|
0
|
|
$fic_sou = shift;#fichier source |
115
|
0
|
|
|
|
|
|
$fic_dest = shift;#fichier de destination |
116
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
$annee = (gmtime(time))[5] + 1900;#recherche de l'annŽe |
118
|
0
|
|
|
|
|
|
$codingfile = shift;#fichier .cod |
119
|
0
|
0
|
0
|
|
|
|
if(!$codingfile || $codingfile == "" || $codingfile == 0){ |
|
|
|
0
|
|
|
|
|
120
|
0
|
|
|
|
|
|
$codingfile = "$annee.cod"; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
0
|
|
0
|
|
|
|
$algorithm = shift || ""; |
124
|
|
|
|
|
|
|
|
125
|
0
|
|
0
|
|
|
|
$is_binary = (-B $fic_sou) || 0; |
126
|
0
|
|
0
|
|
|
|
$old_name = shift || $fic_sou; |
127
|
|
|
|
|
|
|
|
128
|
0
|
0
|
|
|
|
|
open(FICSOU, "<", $fic_sou) || die "Error: $!"; |
129
|
|
|
|
|
|
|
|
130
|
0
|
0
|
|
|
|
|
if($is_binary == 1){ binmode FICSOU; } #le fichier est un fichier binaire |
|
0
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
|
@text2conv = (); # initialisation du tableau général |
133
|
0
|
|
|
|
|
|
my $buf; |
134
|
0
|
|
|
|
|
|
while (sysread(FICSOU, $buf, 1024)){ |
135
|
0
|
|
|
|
|
|
push @text2conv, $buf; # lecture dans le fichier de lecture |
136
|
|
|
|
|
|
|
} |
137
|
0
|
|
|
|
|
|
close FICSOU; # Fermeture du fichier de lecture |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
# encryptage |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
#****************CHARGEMENT DU SYSTEME DE CODAGE********************# |
142
|
|
|
|
|
|
|
# Le script lit le fichier de codage spŽcifiŽ pour coder le fichier |
143
|
|
|
|
|
|
|
|
144
|
0
|
|
|
|
|
|
open(CODINGFILE, "$codingfile"); |
145
|
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
|
$count = 1; |
147
|
|
|
|
|
|
|
|
148
|
0
|
|
|
|
|
|
@codejours = (); |
149
|
0
|
|
|
|
|
|
@codejourm = (); |
150
|
0
|
|
|
|
|
|
@codemois = (); |
151
|
0
|
|
|
|
|
|
$codeannee = 0; |
152
|
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
|
foreach $x (){ |
154
|
0
|
|
|
|
|
|
chomp($x); |
155
|
0
|
0
|
|
|
|
|
if($count <= 7){ |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
156
|
0
|
|
|
|
|
|
push @codejours, $x; |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
elsif($count <= 38){ |
159
|
0
|
|
|
|
|
|
push @codejourm, $x; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
elsif($count <= 50){ |
162
|
0
|
|
|
|
|
|
push @codemois, $x; |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
elsif($count <= 51){ |
165
|
0
|
|
|
|
|
|
$codeannee = $x; |
166
|
|
|
|
|
|
|
} |
167
|
0
|
|
|
|
|
|
$count++; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
0
|
|
|
|
|
|
close CODINGFILE; |
171
|
|
|
|
|
|
|
|
172
|
0
|
|
|
|
|
|
$jours = (gmtime(time))[6]; |
173
|
0
|
|
|
|
|
|
$jourm = (gmtime(time))[3]; |
174
|
0
|
|
|
|
|
|
$mois = (gmtime(time))[4]; |
175
|
|
|
|
|
|
|
|
176
|
0
|
|
|
|
|
|
$thiscodejours = $codejours[$jours]; |
177
|
0
|
|
|
|
|
|
$thiscodejourm = $codejourm[$jourm]; |
178
|
0
|
|
|
|
|
|
$thiscodemois = $codemois[$mois]; |
179
|
0
|
|
|
|
|
|
$thiscodeannee = $codeannee; |
180
|
|
|
|
|
|
|
|
181
|
0
|
|
|
|
|
|
$nbrmodifcod1 = $thiscodejours + 1; |
182
|
0
|
|
|
|
|
|
$nbrmodifcod2 = $thiscodejourm + 1; |
183
|
0
|
|
|
|
|
|
$nbrmodifcod3 = int($thiscodemois / 100) + 1; |
184
|
0
|
|
|
|
|
|
$nbrmodifcod4 = int($thiscodejourm / 9) + 1; |
185
|
0
|
|
|
|
|
|
$nbrmodifcod5 = int($thiscodemois / 94) + 1; |
186
|
0
|
|
|
|
|
|
$nbrmodifcod6 = int($thiscodeannee / 125) + 1; |
187
|
0
|
|
|
|
|
|
$nbrmodifcod7 = int($thiscodejours + 3) + 1; |
188
|
0
|
|
|
|
|
|
$nbrmodifcod8 = int($thiscodejourm + 13) + 1; |
189
|
0
|
|
|
|
|
|
$nbrmodifcod9 = int($thiscodejours + 4) + 1; |
190
|
0
|
|
|
|
|
|
$nbrmodifcod10 = int($thiscodeannee + 73) + 1; |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
#*****************************SYSTEME DE CODAGE CHARGE*******************# |
194
|
0
|
|
|
|
|
|
$time = time; |
195
|
|
|
|
|
|
|
#***************************CHARGEMENT DE L'ALGORITHME*******************# |
196
|
0
|
|
|
|
|
|
$algo = ""; |
197
|
0
|
0
|
|
|
|
|
unless($algorithm eq ""){ |
198
|
0
|
0
|
|
|
|
|
open (ALGO, "$algorithm") || die "Algorithme $algorithm inexistant"; |
199
|
0
|
|
|
|
|
|
foreach (){ |
200
|
0
|
|
|
|
|
|
chomp; |
201
|
0
|
0
|
|
|
|
|
last if $_ eq "end"; |
202
|
0
|
0
|
|
|
|
|
next if $_ =~ /^\#/; |
203
|
0
|
0
|
|
|
|
|
next if $_ eq ""; |
204
|
0
|
0
|
|
|
|
|
$_ =~ s/X/(\$lettre)/gmo if $algo eq ""; |
205
|
0
|
0
|
|
|
|
|
$_ =~ s/X/($algo)/gmo if $algo ne ""; |
206
|
0
|
|
|
|
|
|
$_ =~ s/A/($nbrmodifcod1)/gmo; |
207
|
0
|
|
|
|
|
|
$_ =~ s/B/($nbrmodifcod2)/gmo; |
208
|
0
|
|
|
|
|
|
$_ =~ s/C/($nbrmodifcod3)/gmo; |
209
|
0
|
|
|
|
|
|
$_ =~ s/D/($nbrmodifcod4)/gmo; |
210
|
0
|
|
|
|
|
|
$_ =~ s/E/($nbrmodifcod5)/gmo; |
211
|
0
|
|
|
|
|
|
$_ =~ s/F/($nbrmodifcod6)/gmo; |
212
|
0
|
|
|
|
|
|
$_ =~ s/G/($nbrmodifcod7)/gmo; |
213
|
0
|
|
|
|
|
|
$_ =~ s/H/($nbrmodifcod8)/gmo; |
214
|
0
|
|
|
|
|
|
$_ =~ s/I/($nbrmodifcod9)/gmo; |
215
|
0
|
|
|
|
|
|
$_ =~ s/J/($nbrmodifcod10)/gmo; |
216
|
0
|
|
|
|
|
|
$_ =~ s/T/(\$phrs_cnt)/gmo; |
217
|
0
|
|
|
|
|
|
$_ =~ s/P/(\$mots_cnt)/gmo; |
218
|
0
|
|
|
|
|
|
$_ =~ s/M/(\$lettres_cnt)/gmo; |
219
|
0
|
|
|
|
|
|
$algo = $_; |
220
|
|
|
|
|
|
|
} |
221
|
0
|
|
|
|
|
|
close ALGO; |
222
|
|
|
|
|
|
|
} |
223
|
|
|
|
|
|
|
|
224
|
0
|
|
|
|
|
|
@mots = (); |
225
|
0
|
|
|
|
|
|
@lettres = (); |
226
|
|
|
|
|
|
|
|
227
|
0
|
|
|
|
|
|
$phrs_cnt = 1; |
228
|
0
|
|
|
|
|
|
$mots_cnt = 1; |
229
|
0
|
|
|
|
|
|
$lettres_cnt = 1; |
230
|
|
|
|
|
|
|
|
231
|
0
|
|
|
|
|
|
@tout = (); |
232
|
0
|
|
|
|
|
|
@total = (); |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
|
235
|
0
|
0
|
|
|
|
|
open(FICDEST, ">$fic_dest") || die "$!"; |
236
|
0
|
|
|
|
|
|
print FICDEST $jours. " " . $jourm . " " . $mois . " " . $annee . " " . $is_binary . " " . $old_name ."\n"; |
237
|
|
|
|
|
|
|
|
238
|
0
|
|
|
|
|
|
foreach $phr (@text2conv){ |
239
|
0
|
|
|
|
|
|
$mots_cnt = 1; |
240
|
0
|
|
|
|
|
|
@mots = $phr =~ m/([\s|\S]{1,7})/gm; |
241
|
|
|
|
|
|
|
|
242
|
0
|
|
|
|
|
|
foreach $mot (@mots) { |
243
|
0
|
|
|
|
|
|
$lettres_cnt = 1; |
244
|
0
|
|
|
|
|
|
@lettres = split //, $mot; |
245
|
|
|
|
|
|
|
|
246
|
0
|
|
|
|
|
|
foreach $lettre (@lettres){ |
247
|
0
|
|
|
|
|
|
$lettre = ord($lettre); |
248
|
0
|
0
|
|
|
|
|
if($algorithm eq ""){ &defcodalgo } |
|
0
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
else{ |
250
|
0
|
|
|
|
|
|
$lettre = (eval $algo); |
251
|
|
|
|
|
|
|
} |
252
|
|
|
|
|
|
|
|
253
|
0
|
|
|
|
|
|
print FICDEST $lettre . "~"; # rentre le chiffre correspondant à la lettre et ~(signifiant la fin de lettre) |
254
|
0
|
|
|
|
|
|
$lettres_cnt++; |
255
|
|
|
|
|
|
|
} |
256
|
0
|
|
|
|
|
|
print FICDEST "|"; |
257
|
0
|
|
|
|
|
|
$mots_cnt++; |
258
|
|
|
|
|
|
|
} |
259
|
0
|
|
|
|
|
|
print FICDEST "\n"; |
260
|
0
|
|
|
|
|
|
$phrs_cnt++; |
261
|
|
|
|
|
|
|
}#**************************************FIN SECONDE BOUCLE*********************************# |
262
|
|
|
|
|
|
|
|
263
|
0
|
|
|
|
|
|
close FICDEST; |
264
|
|
|
|
|
|
|
|
265
|
0
|
|
|
|
|
|
print ($time-time)/1000; |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
} # fin codage |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
sub decodage{ |
270
|
|
|
|
|
|
|
|
271
|
0
|
|
|
0
|
0
|
|
$fic_sou = shift;#fichier source |
272
|
0
|
|
|
|
|
|
$fic_dest = shift;#fichier de destination |
273
|
|
|
|
|
|
|
|
274
|
0
|
0
|
|
|
|
|
open(FICSOU, $fic_sou) || die "Error: $!"; |
275
|
0
|
|
|
|
|
|
@text2conv = (); # initialisation du tableau général |
276
|
0
|
|
|
|
|
|
$firstline = ; |
277
|
0
|
|
|
|
|
|
foreach $line (){ |
278
|
0
|
|
|
|
|
|
chomp($line); |
279
|
0
|
|
|
|
|
|
push @text2conv, $line; # lecture dans le fichier de lecture |
280
|
|
|
|
|
|
|
} |
281
|
0
|
|
|
|
|
|
close FICSOU; # Fermeture du fichier de lecture |
282
|
|
|
|
|
|
|
|
283
|
0
|
|
|
|
|
|
chomp($firstline); |
284
|
0
|
|
|
|
|
|
($jours, $jourm, $mois, $annee, $is_binary, $old_name) = split / /, $firstline; |
285
|
0
|
|
|
|
|
|
$codingfile = shift;#fichier .cod |
286
|
0
|
0
|
0
|
|
|
|
if(!$codingfile || $codingfile == "" || $codingfile == 0){ |
|
|
|
0
|
|
|
|
|
287
|
0
|
|
|
|
|
|
$codingfile = "$annee.cod"; |
288
|
|
|
|
|
|
|
} |
289
|
|
|
|
|
|
|
|
290
|
0
|
|
0
|
|
|
|
$algorithm = shift || ""; |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
#****************CHARGEMENT DU SYSTEME DE DECODAGE********************# |
293
|
|
|
|
|
|
|
# Le script lit le fichier de deccodage correspondant à l'année pour coder le fichier |
294
|
|
|
|
|
|
|
|
295
|
0
|
0
|
|
|
|
|
open(CODINGFILE, "$codingfile") || die "Erreur (ouverture $codingfile): $!"; |
296
|
|
|
|
|
|
|
|
297
|
0
|
|
|
|
|
|
$count = 1; |
298
|
|
|
|
|
|
|
|
299
|
0
|
|
|
|
|
|
@codejours = (); |
300
|
0
|
|
|
|
|
|
@codejourm = (); |
301
|
0
|
|
|
|
|
|
@codemois = (); |
302
|
0
|
|
|
|
|
|
$codeannee = 0; |
303
|
|
|
|
|
|
|
|
304
|
0
|
|
|
|
|
|
foreach $x (){ |
305
|
0
|
|
|
|
|
|
chomp($x); |
306
|
0
|
0
|
|
|
|
|
if($count <= 7){ |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
307
|
0
|
|
|
|
|
|
push @codejours, $x; |
308
|
|
|
|
|
|
|
} |
309
|
|
|
|
|
|
|
elsif($count <= 38){ |
310
|
0
|
|
|
|
|
|
push @codejourm, $x; |
311
|
|
|
|
|
|
|
} |
312
|
|
|
|
|
|
|
elsif($count <= 50){ |
313
|
0
|
|
|
|
|
|
push @codemois, $x; |
314
|
|
|
|
|
|
|
} |
315
|
|
|
|
|
|
|
elsif($count <= 51){ |
316
|
0
|
|
|
|
|
|
$codeannee = $x; |
317
|
|
|
|
|
|
|
} |
318
|
0
|
|
|
|
|
|
$count++; |
319
|
|
|
|
|
|
|
} |
320
|
|
|
|
|
|
|
|
321
|
0
|
|
|
|
|
|
close CODINGFILE; |
322
|
|
|
|
|
|
|
|
323
|
0
|
|
|
|
|
|
$goodcodejours = $codejours[$jours]; |
324
|
0
|
|
|
|
|
|
$goodcodejourm = $codejourm[$jourm]; |
325
|
0
|
|
|
|
|
|
$goodcodemois = $codemois[$mois]; |
326
|
0
|
|
|
|
|
|
$goodcodeannee = $codeannee; |
327
|
|
|
|
|
|
|
|
328
|
0
|
|
|
|
|
|
$nbrmodifdec1 = $goodcodejours + 1; |
329
|
0
|
|
|
|
|
|
$nbrmodifdec2 = $goodcodejourm + 1; |
330
|
0
|
|
|
|
|
|
$nbrmodifdec3 = int($goodcodemois / 100) + 1; |
331
|
0
|
|
|
|
|
|
$nbrmodifdec4 = int($goodcodejourm / 9) + 1; |
332
|
0
|
|
|
|
|
|
$nbrmodifdec5 = int($goodcodemois / 94) + 1; |
333
|
0
|
|
|
|
|
|
$nbrmodifdec6 = int($goodcodeannee / 125) + 1; |
334
|
0
|
|
|
|
|
|
$nbrmodifdec7 = int($goodcodejours + 3) + 1; |
335
|
0
|
|
|
|
|
|
$nbrmodifdec8 = int($goodcodejourm + 13) + 1; |
336
|
0
|
|
|
|
|
|
$nbrmodifdec9 = int($goodcodejours + 4) + 1; |
337
|
0
|
|
|
|
|
|
$nbrmodifdec10 = int($goodcodeannee + 73) + 1; |
338
|
|
|
|
|
|
|
#*****************************SYSTEME DE DECODAGE CHARGE*******************# |
339
|
|
|
|
|
|
|
#***************************CHARGEMENT DE L'ALGORITHME*******************# |
340
|
0
|
|
|
|
|
|
$algo = (); |
341
|
0
|
0
|
|
|
|
|
unless($algorithm eq ""){ |
342
|
0
|
0
|
|
|
|
|
open (ALGO, "$algorithm") || die "Algorithme $algorithm inexistant"; |
343
|
0
|
|
|
|
|
|
foreach (){ |
344
|
0
|
|
|
|
|
|
chomp; |
345
|
0
|
0
|
|
|
|
|
$test = 2 if $test == 1; |
346
|
0
|
0
|
|
|
|
|
$test = 1 if $_ eq "end"; |
347
|
0
|
0
|
|
|
|
|
next unless $test == 2; |
348
|
0
|
0
|
|
|
|
|
next if $_ =~ /^\#/; |
349
|
0
|
0
|
|
|
|
|
next if $_ eq ""; |
350
|
0
|
0
|
|
|
|
|
$_ =~ s/X/(\$lettre)/gmo if $algo eq ""; |
351
|
0
|
0
|
|
|
|
|
$_ =~ s/X/($algo)/gmo if $algo ne ""; |
352
|
0
|
|
|
|
|
|
$_ =~ s/A/($nbrmodifdec1)/gmo; |
353
|
0
|
|
|
|
|
|
$_ =~ s/B/($nbrmodifdec2)/gmo; |
354
|
0
|
|
|
|
|
|
$_ =~ s/C/($nbrmodifdec3)/gmo; |
355
|
0
|
|
|
|
|
|
$_ =~ s/D/($nbrmodifdec4)/gmo; |
356
|
0
|
|
|
|
|
|
$_ =~ s/E/($nbrmodifdec5)/gmo; |
357
|
0
|
|
|
|
|
|
$_ =~ s/F/($nbrmodifdec6)/gmo; |
358
|
0
|
|
|
|
|
|
$_ =~ s/G/($nbrmodifdec7)/gmo; |
359
|
0
|
|
|
|
|
|
$_ =~ s/H/($nbrmodifdec8)/gmo; |
360
|
0
|
|
|
|
|
|
$_ =~ s/I/($nbrmodifdec9)/gmo; |
361
|
0
|
|
|
|
|
|
$_ =~ s/J/($nbrmodifdec10)/gmo; |
362
|
0
|
|
|
|
|
|
$_ =~ s/T/(\$phrs_cnt)/gmo; |
363
|
0
|
|
|
|
|
|
$_ =~ s/P/(\$mots_cnt)/gmo; |
364
|
0
|
|
|
|
|
|
$_ =~ s/M/(\$lettres_cnt)/gmo; |
365
|
0
|
|
|
|
|
|
$algo = $_; |
366
|
|
|
|
|
|
|
} |
367
|
0
|
|
|
|
|
|
close ALGO; |
368
|
|
|
|
|
|
|
} |
369
|
|
|
|
|
|
|
|
370
|
|
|
|
|
|
|
|
371
|
0
|
|
|
|
|
|
@mots = (); |
372
|
0
|
|
|
|
|
|
@lettres = (); |
373
|
|
|
|
|
|
|
|
374
|
0
|
|
|
|
|
|
$phrs_cnt = 1; |
375
|
0
|
|
|
|
|
|
$mots_cnt = 1; |
376
|
0
|
|
|
|
|
|
$lettres_cnt = 1; |
377
|
|
|
|
|
|
|
|
378
|
|
|
|
|
|
|
# décryptage |
379
|
|
|
|
|
|
|
|
380
|
0
|
|
|
|
|
|
$pourlesmots = ""; #pour stocker les lettres |
381
|
0
|
|
|
|
|
|
@total = (); |
382
|
|
|
|
|
|
|
|
383
|
0
|
|
|
|
|
|
open(FICDEST, ">", "$fic_dest"); |
384
|
|
|
|
|
|
|
|
385
|
0
|
0
|
|
|
|
|
if($is_binary == 1){ binmode FICDEST; } #le fichier est un fichier binaire |
|
0
|
|
|
|
|
|
|
386
|
|
|
|
|
|
|
|
387
|
|
|
|
|
|
|
#**************************************BOUCLE UNIQUE: CHANGEMENTS LETTRE PAR LETTRE*********************************# |
388
|
0
|
|
|
|
|
|
foreach $phr (@text2conv){ |
389
|
0
|
|
|
|
|
|
$mots_cnt = 1; |
390
|
0
|
|
|
|
|
|
@mots = split /\|/, $phr; |
391
|
|
|
|
|
|
|
|
392
|
0
|
|
|
|
|
|
foreach $mot (@mots) { |
393
|
0
|
|
|
|
|
|
$lettres_cnt = 1; |
394
|
0
|
|
|
|
|
|
@lettres = split /\~/, $mot; |
395
|
|
|
|
|
|
|
|
396
|
0
|
|
|
|
|
|
foreach $lettre (@lettres){ |
397
|
|
|
|
|
|
|
|
398
|
0
|
0
|
|
|
|
|
if($algorithm eq ""){ &defdecalgo } |
|
0
|
|
|
|
|
|
|
399
|
|
|
|
|
|
|
else{ |
400
|
0
|
|
|
|
|
|
$lettre = (eval $algo); |
401
|
|
|
|
|
|
|
} |
402
|
|
|
|
|
|
|
|
403
|
|
|
|
|
|
|
#**************************************TRANSFORMATION EN LETTRES*********************************# |
404
|
0
|
|
|
|
|
|
$lettre .= "!"; |
405
|
0
|
|
|
|
|
|
chop $lettre; |
406
|
0
|
|
|
|
|
|
$lettre = chr($lettre); |
407
|
0
|
|
|
|
|
|
print FICDEST $lettre; |
408
|
0
|
|
|
|
|
|
$lettres_cnt++; |
409
|
|
|
|
|
|
|
} |
410
|
0
|
|
|
|
|
|
$mots_cnt++; |
411
|
|
|
|
|
|
|
} |
412
|
0
|
|
|
|
|
|
$phrs_cnt++; |
413
|
|
|
|
|
|
|
}#**************************************FIN BOUCLE UNIQUE*********************************# |
414
|
|
|
|
|
|
|
|
415
|
0
|
|
|
|
|
|
close FICDEST; |
416
|
|
|
|
|
|
|
|
417
|
0
|
|
|
|
|
|
return $old_name; |
418
|
|
|
|
|
|
|
|
419
|
|
|
|
|
|
|
} # fin decodage |
420
|
|
|
|
|
|
|
|
421
|
|
|
|
|
|
|
sub createcod{ |
422
|
0
|
|
|
0
|
0
|
|
$file = (gmtime(time))[5]+1900 . ".cod"; |
423
|
|
|
|
|
|
|
|
424
|
0
|
0
|
|
|
|
|
open (FILEOPENED, ">$file") || destructscript("Le fichier n'a pas pu être créé"); |
425
|
0
|
|
|
|
|
|
for($a = 1;$a <= 7;$a++){ |
426
|
|
|
|
|
|
|
|
427
|
0
|
|
|
|
|
|
print FILEOPENED int(rand(9) + 1), "\n" || destructscript("Le fichier ne peut pas être écrit"); |
428
|
|
|
|
|
|
|
|
429
|
|
|
|
|
|
|
} |
430
|
|
|
|
|
|
|
|
431
|
0
|
|
|
|
|
|
for($a = 1;$a <= 31;$a++){ |
432
|
|
|
|
|
|
|
|
433
|
0
|
|
|
|
|
|
print FILEOPENED int(rand(99) + 1), "\n" || destructscript("Le fichier ne peut pas être écrit"); |
434
|
|
|
|
|
|
|
|
435
|
|
|
|
|
|
|
} |
436
|
|
|
|
|
|
|
|
437
|
0
|
|
|
|
|
|
for($a = 1;$a <= 12;$a++){ |
438
|
|
|
|
|
|
|
|
439
|
0
|
|
|
|
|
|
print FILEOPENED int(rand(999) + 1), "\n" || destructscript("Le fichier ne peut pas être écrit"); |
440
|
|
|
|
|
|
|
|
441
|
|
|
|
|
|
|
} |
442
|
|
|
|
|
|
|
|
443
|
0
|
|
|
|
|
|
print FILEOPENED int(rand(9999) + 1), "\n" || destructscript("Le fichier ne peut pas être écrit"); |
444
|
|
|
|
|
|
|
|
445
|
|
|
|
|
|
|
sub destructscript{ |
446
|
0
|
|
|
0
|
0
|
|
die "Erreur dans la création de fichier.cod: ", shift, " (erreur système: $!)"; |
447
|
|
|
|
|
|
|
} |
448
|
|
|
|
|
|
|
|
449
|
0
|
|
|
|
|
|
close FILEOPENED; |
450
|
0
|
|
|
|
|
|
return $file; |
451
|
|
|
|
|
|
|
|
452
|
|
|
|
|
|
|
} |
453
|
|
|
|
|
|
|
|
454
|
|
|
|
|
|
|
sub defcodalgo{ |
455
|
0
|
|
|
0
|
0
|
|
$lettre += $nbrmodifcod1; |
456
|
0
|
|
|
|
|
|
$lettre *= (($mots_cnt + 1) * $nbrmodifcod2); |
457
|
0
|
|
|
|
|
|
$lettre *= $nbrmodifcod3; |
458
|
0
|
|
|
|
|
|
$lettre *= $nbrmodifcod4; |
459
|
0
|
|
|
|
|
|
$lettre += (($lettres_cnt + 1) * $nbrmodifcod5); |
460
|
0
|
|
|
|
|
|
$lettre -= $nbrmodifcod6; |
461
|
0
|
|
|
|
|
|
$lettre *= $nbrmodifcod7; |
462
|
0
|
|
|
|
|
|
$lettre -= ($nbrmodifcod8 * ($phrs_cnt + 1)); |
463
|
0
|
|
|
|
|
|
$lettre *= $nbrmodifcod9; |
464
|
0
|
|
|
|
|
|
$lettre -= $nbrmodifcod10; |
465
|
|
|
|
|
|
|
} |
466
|
|
|
|
|
|
|
|
467
|
|
|
|
|
|
|
sub defdecalgo{ |
468
|
0
|
|
|
0
|
0
|
|
$lettre += $nbrmodifdec10; |
469
|
0
|
|
|
|
|
|
$lettre /= $nbrmodifdec9; |
470
|
0
|
|
|
|
|
|
$lettre += ($nbrmodifdec8 * ($phrs_cnt + 1)); |
471
|
0
|
|
|
|
|
|
$lettre /= $nbrmodifdec7; |
472
|
0
|
|
|
|
|
|
$lettre += $nbrmodifdec6; |
473
|
0
|
|
|
|
|
|
$lettre -= (($lettres_cnt + 1) * $nbrmodifdec5); |
474
|
0
|
|
|
|
|
|
$lettre /= $nbrmodifdec4; |
475
|
0
|
|
|
|
|
|
$lettre /= $nbrmodifdec3; |
476
|
0
|
|
|
|
|
|
$lettre /= (($mots_cnt + 1) * $nbrmodifdec2); |
477
|
0
|
|
|
|
|
|
$lettre -= $nbrmodifdec1; |
478
|
|
|
|
|
|
|
} |
479
|
|
|
|
|
|
|
|
480
|
|
|
|
|
|
|
1; |