![]()  | 
	
 
  | 
		
			
  | 	
	
	
		
		|||||||
| Регистрация | << Правила форума >> | FAQ | Пользователи | Календарь | Поиск | Сообщения за сегодня | Все разделы прочитаны | 
![]()  | 
	
	
| 
		 | 
	Опции темы | Поиск в этой теме | Опции просмотра | 
| 
		 
			 
			#1  
			
			
			
			
		 
		
		
	 | 
|||
		
		
  | 
|||
| 
	
	
		
			
			 Здравствуйте, уважаемые знатоки. В чем я не прав? Программа шифровки-дешифровки текста, выбор метода реализовал через RadioGroup. Ошибок нет, но ничего не работает. Помогите, пожалуйста. Delphi 7. 
		
	
		
		
			Код: 
	unit Unit1;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls;
 
type
  TForm1 = class(TForm)
    mmo1: TMemo;
    mmo2: TMemo;
    btn1: TButton;
    btn2: TButton;
    lbl1: TLabel;
    lbl2: TLabel;
    edt1: TEdit;
    lbl3: TLabel;
    rg1: TRadioGroup;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
 
 
const alfa:array[0..65] of char = ('а','б','в','г','д','е','ё','ж','з','и','й','к','л','м','н','о','п','р','с','т','у','ф','х','ц','ч','ш','щ','ъ','ы','ь','э','ю','я','А','Б','В','Г','Д','Е','Ё','Ж','З','И','Й','К','Л','М','Н','О','П','Р','С','Т','У','Ф','Х','Ц','Ч','Ш','Щ','Ъ','Ы','Ь','Э','Ю','Я');
var
  Form1: TForm1;
  a:array[0..65] of char;
  i, j, k: integer;
  s, s2, stroki, Last:string;
  c:char;
implementation
 
{$R *.dfm}
 
procedure TForm1.Button1Click(Sender: TObject);
begin
  if rg1.ItemIndex=0
   then begin
  For i:=0 to 65 do
    begin
      a[i]:= alfa[(i+1) mod 66];
    end;
    // шифр
      k := StrToInt(edt1.Text);
      s := mmo1.Lines.Text;
      for i := 1 to length(s) do
        for j := 0 to 65 do
        if s[i] = a[j] then s2 := s2+a[(66+(j+k)) mod 66];
      mmo2.Lines.Text := s2;
      s2 := '';
      end;
 
   if rg1.ItemIndex=1
   then begin
 i := 1;
 if Length(mmo1.Text) mod 2 = 0
  then begin
        stroki := mmo1.Text;
        Last := '';
       end
  else begin
        stroki := Copy(mmo1.Text, 1, Length(mmo1.Text) - 1);
        Last := Copy(mmo1.Text, Length(mmo1.Text), 1);
       end;
 while i <= Length(stroki) do
  begin
   c := stroki[i];
   stroki[i] := stroki[i + 1];
   stroki[i + 1] := c;
   i := i + 2;
  end;
 mmo2.Text := stroki + Last;
end;
end;
 
procedure TForm1.Button2Click(Sender: TObject);
begin
  if rg1.ItemIndex=0
   then begin
      s2:='';
      k := StrToInt(edt1.Text);
      s := mmo1.Lines.Text;
      for i := 1 to length(s) do
        for j := 0 to 65 do
        if s[i] = a[j] then s2 := s2+a[(66+(j-k)) mod 66];
      mmo2.Lines.Text := s2;
      s2 := '';
if rg1.ItemIndex=1
   then begin
if rg1.ItemIndex=1
   then begin
 i := 1;
 if Length(mmo2.Text) mod 2 = 0
  then begin
        stroki := mmo2.Text;
        Last := '';
       end
  else begin
        stroki := Copy(mmo2.Text, 1, Length(mmo1.Text) + 1);
        Last := Copy(mmo2.Text, Length(mmo1.Text), 1);
       end;
 while i <= Length(stroki) do
  begin
   c := stroki[i];
   stroki[i] := stroki[i - 1];
   stroki[i - 1] := c;
   i := i - 2;
  end;
 mmo1.Text := stroki + Last;
end;
end;
end;
end;
end. | 
| 
		 
			 
			#2  
			
			
			
			
		 
		
		
	 | 
|||
		
		
  | 
|||
| 
	
	
		
			
			 Ну, давай на примере твоего кода. Берем один маленький кусочек: 
		
	
		
		
		
		
		
	
		
		
	
	
	Код: 
	  if rg1.ItemIndex=0
   then begin
  For i:=0 to 65 do
    begin
      a[i]:= alfa[(i+1) mod 66];
    end;
    // шифр
      k := StrToInt(edt1.Text);
      s := mmo1.Lines.Text;
      for i := 1 to length(s) do
        for j := 0 to 65 do
        if s[i] = a[j] then s2 := s2+a[(66+(j+k)) mod 66];
      mmo2.Lines.Text := s2;
      s2 := '';
      end;Даже не зная конкретный алгоритм шифрования, мы видим, что все операции происходять с переменной s, а во второе Memo ты выводишь переменную s2. Естественно, что ты ничего и не видишь... Вообще, я так понимаю, что это шифр циклической перестановкой. Тгда получается что-то типа такого: Код: 
	procedure TForm1.btEncodeClick(Sender: TObject);
var
  Pwd : Integer;
  Txt : AnsiString;
  Idx : Integer;
  I : Integer;
  Lng1 : Integer;
  Lng2 : Integer;
begin
  Lng1 := (Ord('Я')-Ord('А')+1);
  Lng2 := 2*Lng1;
  Pwd := StrToInt(edPwd.Text);
  Txt := edPlain.Lines.Text;
  For I := 1 To Length(Txt) Do
    Begin
      If (Txt[i] >= 'А') And (Txt[i] <= 'Я')
        Then Idx := Ord(Txt[i])-Ord('А')
      Else If (Txt[i] >= 'а') And (Txt[i] <= 'я')
        Then Idx := Ord(Txt[i])-Ord('я')+Lng1
      Else Idx := -1;
      If Idx > -1 Then
        Begin
          Idx := (Lng2 + Idx + Pwd) Mod Lng2;
          If (Idx <= Lng1)
            Then Idx := Idx + Ord(AnsiChar('А'))
            Else Idx := Idx -Lng1 + Ord(AnsiChar('а'));
          Txt[i] := AnsiChar(Chr(Idx));
        End;
    End;
  edCoded.Lines.Text := Txt;
end; |