-
Notifications
You must be signed in to change notification settings - Fork 0
/
ROT13.PAS
136 lines (129 loc) · 3.43 KB
/
ROT13.PAS
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
{ @author: Sylvain Maltais (support@gladir.com)
@created: 2024
@website(https://www.gladir.com/rot13-tools)
@abstract(Target: Turbo Pascal 7, Free Pascal 3.2)
}
Program ROT13;
Uses DOS;
Var
I:Integer;
OutputFileName,CurrLine:String;
FileRot13,OutputFileRot13:Text;
Function StrToUpper(S:String):String;
Var
I:Byte;
Begin
For I:=1 to Length(S)do Begin
If S[I] in['a'..'z']Then S[I]:=Chr(Ord(S[I])-32);
End;
StrToUpper:=S;
End;
Function FileExist(Name:String):Boolean;
Var
Rec:SearchRec;
Begin
FindFirst(Name,AnyFile,Rec);
FileExist:=DosError=0;
End;
Function Rot13ToString(someText:String):String;
Var
I:Integer;
Ch:Char;
R:String;
Begin
R:='';
For I:=1 to Length(someText) do Begin
Ch:=SomeText[i];
Case ch of
'A'..'M','a'..'m':Ch:=Chr(Ord(Ch)+13);
'N'..'Z','n'..'z':Ch:=Chr(Ord(Ch)-13);
End;
R:=R+Ch;
End;
Rot13ToString:=R;
End;
BEGIN
If(ParamStr(1)='/?')or(ParamStr(1)='--help')or(ParamStr(1)='-h')or
(ParamStr(1)='/h')or(ParamStr(1)='/H')Then Begin
WriteLn('ROT13 : Cette commande permet d''effectuer une rotation de ',
'13 lettres de l''alphabet latin.');
WriteLn;
WriteLn('Syntaxe : ROT13 ["message"] [/OUTPUTFILE:fichier2]');
WriteLn(' ROT13 fichier [/OUTPUTFILE:fichier2]');
WriteLn;
WriteLn(' message Le message … chiffrer avec ROT13');
WriteLn(' fichier Le nom du fichier … traiter avec ROT13');
WriteLn(' /OUTPUTFILE:fichier2 Le nom du fichier allant contenir le r‚sultat');
End
Else
If ParamCount>0 Then Begin
OutputFileName:='';
For I:=1 to ParamCount do Begin
If(StrToUpper(Copy(ParamStr(I),1,Length('/OUTPUTFILE:')))='/OUTPUTFILE:')Then Begin
OutputFileName:=Copy(ParamStr(I),Length('/OUTPUTFILE:')+1,255);
End;
End;
For I:=1 to ParamCount do Begin
If(StrToUpper(Copy(ParamStr(I),1,Length('/OUTPUTFILE:')))='/OUTPUTFILE:')Then Begin
{ Saut ... }
End
Else
If FileExist(ParamStr(I))Then Begin
If OutputFileName<>''Then Begin
{$I-}Assign(FileRot13,ParamStr(I));
Reset(FileRot13);{$I+}
If IOResult<>0 Then Begin
WriteLn('Impossible de lire le fichier : ',ParamStr(I),'!');
Halt(1);
End;
{$I-}Assign(OutputFileRot13,OutputFileName);
Rewrite(OutputFileRot13);{$I+}
If IOResult<>0 Then Begin
WriteLn('Impossible de cr‚er le fichier : ',OutputFileName,'!');
Halt(2);
End;
While Not EOF(FileRot13)do Begin
ReadLn(FileRot13,CurrLine);
WriteLn(OutputFileRot13,Rot13ToString(CurrLine));
End;
Close(OutputFileRot13);
Close(FileRot13);
End
Else
Begin
{$I-}Assign(FileRot13,ParamStr(I));
Reset(FileRot13);{$I+}
If IOResult<>0 Then Begin
WriteLn('Impossible de lire le fichier : ',ParamStr(I),'!');
Halt(1);
End;
While Not EOF(FileRot13)do Begin
ReadLn(FileRot13,CurrLine);
WriteLn(Rot13ToString(CurrLine));
End;
Close(FileRot13);
End;
End
Else
Begin
If OutputFileName<>''Then Begin
{$I-}Assign(OutputFileRot13,OutputFileName);
Rewrite(OutputFileRot13);{$I+}
If IOResult<>0 Then Begin
WriteLn('Impossible de cr‚er le fichier : ',OutputFileName,'!');
Halt(2);
End;
WriteLn(OutputFileRot13,Rot13ToString(ParamStr(I)));
Close(OutputFileRot13);
End
Else
WriteLn(Rot13ToString(ParamStr(I)));
End;
End;
End
Else
While Not EOF(Input) do Begin
ReadLn(CurrLine);
WriteLn(Rot13ToString(CurrLine));
End;
END.