|
|
Регистрация | << Правила форума >> | FAQ | Пользователи | Календарь | Поиск | Сообщения за сегодня | Все разделы прочитаны |
|
Опции темы | Поиск в этой теме | Опции просмотра |
#1
|
|||
|
|||
программа не работает, но запускается
Код:
procedure TForm1.Button1Click(Sender: TObject); var m:integer; m1:string; begin s1 := ''; m1:=Memo3.Text; m := Strtoint(m1); s := Memo1.Text; y[1] := Strtoint(Memo5.Text); y[2] := Strtoint(Memo4.Text); for i := 3 to Length(s) do y := (y[i-1]+y[i-2]) mod m; for i := 1 to Length(s) do s1 :=s1 + chr(ord(s) XOR y); Memo2.Text:=('Исходный текст:'); Memo2.Lines.Add(s); Memo2.Lines.Add('Зашифрований текст:'); Memo2.Lines.Add(s1); Memo6.Text:=s1; end; procedure TForm1.N2Click(Sender: TObject); begin if OpenDialog1.Execute then Memo1.Lines.LoadFromFile(OpenDialog1.FileName); end; procedure TForm1.N3Click(Sender: TObject); begin if SaveDialog1.Execute then Memo2.Lines.SaveToFile(SaveDialog1.Filename); end; procedure TForm1.Button2Click(Sender: TObject); var m:integer; begin s2 := ''; m := Strtoint(Memo3.Text); s3 := Memo6.Text; y[1] := Strtoint(Memo5.Text); y[2] := Strtoint(Memo4.Text); for i := 3 to Length(s3) do y := (y[i-1]+y[i-2]) mod m; for i := 1 to Length(s3) do s2 :=s2 + chr(ord(s3) xor y); Memo7.Text:=('Зашифрований текст:'); Memo7.Lines.Add(s3); Memo7.Lines.Add('Исходный текст:'); Memo7.Lines.Add(s2); end; end. |
#2
|
||||
|
||||
Ну замечательно! А от нас то что требуется???
Пишу программы за еду. __________________ |
#3
|
||||
|
||||
Код:
(********************************************************************* How to use: var s: string; begin s := 'Carlos Alberto Longen'; s := Crypt(s,12345); ShowMessage(Format('Ciphered: %s', [s])); ShowMessage(Format('Deciphered: %s', [decrypt(s,12345)])); *********************************************************************) unit untCrypt; interface // ciphers the string "strText" with 32-bit "code" "intCode" function Crypt(const strText: string; const intKey: longint): string; // deciphers the string "strText" with 32-bit "code" "intCode" function Decrypt(const strText: string; const intKey: longint): string; const // "default key" - select a "standard" for you... intDefKey = -967283; implementation // ciphers the string "strText" with 32-bit "code" "intCode" function Crypt(const strText: string; const intKey: longint): string; var i: integer; strResult: string; begin // initialize result strResult := strText; // sync RandSeed key to generate Random chars RandSeed := intKey; // cipher for i := 1 to Length(strText) do strResult[i] := Chr(Ord(strResult[i]) xor Random(255)); // set results Crypt := strResult; end; // deciphers the string "strText" with 32-bit "code" "intCode" function Decrypt(const strText: string; const intKey: longint): string; begin // deciphers the string Decrypt := Crypt(strText, intKey); end; end. |
#4
|
||||
|
||||
Или я чего-то не вижу или лыжи не едут. Как функция предложенная Vayrus хоть что-то может правильно расшифровать? Но ведь работает, вот в чем парадокс.
Не врубаюсь. Ключ, который должен собственно шифровать/дешифровывать корректно, тут заменен рандомным значением Код:
strResult[i] := Chr(Ord(strResult[i]) xor Random(255)); Жизнь такова какова она есть и больше никакова. Помогаю за спасибо. |
#5
|
||||
|
||||
Ах вот оно что... Я даже не знал, что есть такая хитрая переменная RandSeed в System. После экспериментального втыкания Randomize в нужное место все встало на свои места.
Жизнь такова какова она есть и больше никакова. Помогаю за спасибо. |