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
| //---------------------------------------------------------------------------
// Coded : Boolean ; Variable globale : vrai si le texte à été codé
//---------------------------------------------------------------------------
Function Alphanum : String ;
Var
I : Integer;
Chaine : String ;
Begin
// Alphanum :='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz .àèéç-_=,;:/\!?';
Chaine := '';
For I := 32 To 126 Do Chaine := Chaine + Char(I);
Chaine := Chaine + 'éèàçùûïê';
Result := Chaine ;
end;
//---------------------------------------------------------------------------
Function Code(S, Clef:String): String;
Var
S2:String ;
LClef, L, LLettres, i, j, k, n : Byte ;
Alpha : String ;
Begin
Alpha := AlphaNum ;
Result := S ;
LClef := Length(Clef) ;
// If Not Crypte Then Exit ;
LLettres := Length(Alpha) ;
L := Length(S) ;
S2 := '' ;
For i:= 1 To L Do
Begin
j := 1 + (i-1) Mod LClef ;
k := Pos(Clef[j], Alpha) - 1 ;
n := Pos(S[i], Alpha) ;
S2 := S2 + Alpha[1+(n + k - 1) Mod LLettres]
End;
Result := S2 ;
End;
//---------------------------------------------------------------------------
Function Decode(S, Clef:String):String;
Var
Alpha : String ;
S2 : String;
LClef, L, LLEttres, i, j, k, n : Byte ;
Begin
Alpha := AlphaNum ;
Result := S ;
LClef:=Length(Clef) ;
// If Not Crypte Then Exit ;
LLettres := Length(Alpha) ;
L := Length(S) ;
S2 := '' ;
For i := 1 To L Do
Begin
j := 1 + (i-1) Mod LClef ;
k := Pos(Clef[j], Alpha)-1 ;
n := Pos(S[i], Alpha) ;
S2 := S2 + Alphanum[1 + (LLettres + n - k - 1) Mod LLettres];
End;
Result := S2 ;
End;
//---------------------------------------------------------------------------
procedure TForm1.FormCreate(Sender: TObject);
begin
Coded := False ;
end;
//---------------------------------------------------------------------------
procedure TForm1.Button5Click(Sender: TObject);
// Codage et décodage de Edit5.text
begin
If Coded Then
Begin
Edit5.Text := Decode(Edit5.Text, 'Bizarre') ;
Coded := True ;
End
Else
Begin
Edit5.Text := Code(Edit5.Text, 'Bizarre') ;
Coded := False ;
End ;
end;
//--------------------------------------------------------------------------- |
Partager