Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Unit2;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
- type
- TForm2 = class(TForm)
- Button1: TButton;
- Edit1: TEdit;
- memoEncrypt: TMemo;
- memoDecrypt: TMemo;
- Button2: TButton;
- Button3: TButton;
- procedure Button1Click(Sender: TObject);
- procedure Button2Click(Sender: TObject);
- procedure Button3Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- Form2: TForm2;
- implementation
- {$R *.dfm}
- function GetStr(var str: String): String;
- var
- i: Integer;
- newStr: String;
- begin
- for i := 1 to Length(str) do
- begin
- if (ord(str[i]) >= 1072) and (ord(str[i]) <= 1103) or (ord(str[i]) = 1105)then
- newStr := newStr + str[i];
- result := newStr;
- end;
- end;
- function LowerCase(Str: string): string;
- var
- i: integer;
- begin
- Result := Str;
- for i := 1 to length(Result) do
- begin
- if (Result[i] in ['А'..'Я']) then
- Result[i] := chr(ord(Result[i]) + 32);
- if Result[i] = 'Ё' then
- Result[i] := 'ё';
- end;
- end;
- function Encrypt(str: string; const Coolkey: string):string;
- const
- SizeAlphabet = 33;
- Alphabet = 'абвгдеёжзийклмнопрстуфхцчшщъыьэюя';
- var
- i, j, Position, KeyCounter, Offset: integer;
- temp, key: string;
- begin
- str := GetStr(Str);
- Key := Coolkey;
- KeyCounter := 0;
- for i := 1 to length(str) do
- begin
- inc(KeyCounter);
- if KeyCounter > length(key) then
- begin
- KeyCounter := 1;
- for j := 1 to Length(Key) do
- Key[j] := Alphabet[pos(Key[j], Alphabet) + 1];
- end;
- Position := pos(str[i], Alphabet) + pos(key[KeyCounter], Alphabet) - 1;
- if Position > SizeAlphabet then
- Position := Position - SizeAlphabet;
- Result:=Result + Alphabet[Position];
- end;
- end;
- function Decrypt(str, key: string): string;
- const
- SizeAlphabet = 33;
- Alphabet = 'абвгдеёжзийклмнопрстуфхцчшщъыьэюя';
- var
- i, j, Position, KeyCounter: integer;
- Temp: string;
- begin
- Str := GetStr(Str);
- Str := LowerCase(str);
- Key := LowerCase(key);
- KeyCounter := 0;
- for i := 1 to length(str) do
- begin
- inc(KeyCounter);
- if KeyCounter > length(Key) then
- begin
- KeyCounter := 1;
- for j := 1 to Length(Key) do
- Key[j] := Alphabet[pos(Key[j], Alphabet) + 1];
- end;
- Position := pos(Str[i], Alphabet) - pos(Key[KeyCounter], Alphabet) + 1;
- if Position <= 0 then
- Position := Position + SizeAlphabet;
- Result := Result + Alphabet[Position];
- end;
- end;
- procedure TForm2.Button1Click(Sender: TObject);
- begin
- memoDecrypt.Text := Encrypt(memoEncrypt.Text,edit1.Text);
- end;
- procedure TForm2.Button2Click(Sender: TObject);
- begin
- memoDecrypt.Text := Decrypt(memoDecrypt.Text,edit1.Text);
- end;
- procedure TForm2.Button3Click(Sender: TObject);
- begin
- memoEncrypt.Lines.Clear;
- memoDecrypt.Lines.Clear;
- edit1.Text:='';
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement