
02.06.2010, 16:06
|
 |
Местный
|
|
Регистрация: 12.03.2006
Адрес: Минск
Сообщения: 527
Репутация: 1336
|
|
http://ru.wikipedia.org/wiki/Полиалфавитный_шифр
http://articles.org.ru/cn/showdetail.php?cid=8341
Вообще если сдвигать по ключу, то это Не Цезарь, а шифр Вижинера.
Вот код:
Код:
function PosInVoc(Symbol : Char; Vocabulary : String) : Word;
var
i : Word;
begin
Result := 0;
for i := 1 to Length(Vocabulary) do
if Vocabulary[i] = Symbol then
begin
Result := i;
break;
end;
end;
function Viginer(Text : String; Key : String; Vocabulary : String; Encrypt : Boolean = True) : String;
var
i, k : LongWord;
n, pos, posk : Word;
begin
Result := '';
n := Length(Vocabulary);
k := 1;
if Length(Text) <> 0 then
for i := 1 to Length(Text) do
begin
pos := PosInVoc(Text[i], Vocabulary);
posk := PosInVoc(Key[k], Vocabulary);
if pos = 0 then break;
if Encrypt then Result := Result + Vocabulary[(pos + posk) mod n]
else Result := Result + Vocabulary[(pos - posk + n) mod n];
if k > Length(Key) then k := 1
else inc(k);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
Begin
Edit1.Text := Viginer(EditText.Text, EditKey.Text, 'abcdefghigklmnopqrstuvwxyz', true);
Edit2.Text := Viginer(Edit1.Text, EditKey.Text , 'abcdefghigklmnopqrstuvwxyz', false);
end;
__________________
Нет повести печальнее на свете, чем повесть о заклиневшем Resete.
|