,   CyberForum.ru

- C++


 
C++ http://www.cyberforum.ru/cpp-beginners/thread428589.html
, .
C++ , . : //pos , pos_1=pos->previous; // pos_1 pos... http://www.cyberforum.ru/cpp-beginners/thread428579.html
C++ ( )
#include <dos.h> #include <conio.h> #include <stdio.h> #include <stdlib.h> #include <graphics.h> #define color_close 14 #define color_st_end 12
C++
. : 2 (a N*M b K*M). , , ( ), ...
C++ static_cast http://www.cyberforum.ru/cpp-beginners/thread428568.html
׸ ? ?
C++ - , ( . : , ! ? - ; ), , . , ....

zagainovps
-11 / 0 / 0
: 14.01.2009
: 25
22.01.2012, 15:33  []
, () , ????

1

Delphi
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
unit Uni;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ComCtrls, ActnList;
type
  TForm1 = class(TForm)
    Button1: TButton;
    LabeledEdit1: TLabeledEdit;
    Button2: TButton;
    RadioGroup1: TRadioGroup;
    OpenDialog1: TOpenDialog;
    ActionList1: TActionList;
    Coding: TAction;
    Decoding: TAction;
    LabeledEdit3: TLabeledEdit;
    Button3: TButton;
    procedure Button1Click(Sender: TObject);
    procedure RadioGroup1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure CodingExecute(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure DecodingExecute(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
  in_file,out_file:file;
  key:array[1..8] of longint;
  x1,x2,y1,y2:longint;
  fp1:string;
  i,i1:integer;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
 case RadioGroup1.ItemIndex of
   0:Coding.Execute;
   1:Decoding.Execute;
 end;
end;
procedure TForm1.RadioGroup1Click(Sender: TObject);
begin
 case RadioGroup1.ItemIndex of
   0:
    begin
     Button1.Caption:='Êîäèðîâ*òü';
     Form1.Caption:='Ðåæèì êîäèðîâ**èÿ';
    end;
   1:
    begin
     Button1.Caption:='Äåêîäèðîâ*òü';
     Form1.Caption:='Ðåæèì äåêîäèðîâ**èÿ';
    end;
 end;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
 OpenDialog1.Filter:='Ô*éë êëþ÷*|*.kf';
 if OpenDialog1.Execute=true
 then
  if FileExists(OpenDialog1.FileName)=false
  then
   begin
    AssignFile(in_file,OpenDialog1.FileName+'.kf');
    rewrite(in_file,1);
    randomize;
    for i:=1 to 32 do
     begin
      i1:=random(255);
      BlockWrite(in_file,i1,1);
     end;
    Closefile(in_file);
    AssignFile(in_file,OpenDialog1.FileName+'.kf');
    reset(in_file,1);
    for i:=1 to 8 do
     BlockRead(in_file,key[i],4);
    Closefile(in_file);
    LabeledEdit3.Text:=OpenDialog1.FileName+'.kf';
   end
  else
   begin
    AssignFile(in_file,OpenDialog1.FileName);
    reset(in_file,1);
    for i:=1 to 8 do
     BlockRead(in_file,key[i],4);
    CloseFile(in_file);
    LabeledEdit3.Text:=OpenDialog1.FileName;
   end;
end;
procedure TForm1.CodingExecute(Sender: TObject);
begin
 if FileExists(LabeledEdit1.Text)=false
 then
  begin
   MessageDlg('Íå âûáð** êîäèðóåìûé ô*éë',mtError,[mbOK],1);
   Exit;
  end
 else
  if FileExists(LabeledEdit3.Text)=false
  then
   begin
    MessageDlg('Íå âûáð** êëþ÷åâîé ô*éë',mtError,[mbOK],1);
    Exit;
   end
 else AssignFile(in_file,fp1);
 AssignFile(out_file,fp1+'cf');
 Reset(in_file,1);
 Rewrite(out_file,1);
 for i:=1 to FileSize(in_file) div 8 do
  begin
   BlockRead(in_file,x1,4);
   BlockRead(in_file,x2,4);
   for i1:=1 to 8 do
    begin
     y2:=x1 xor key[i1];
     y1:=x2 xor y2;
     x1:=y1;
     x2:=y2;
    end;
   BlockWrite(out_file,y1,4);
   BlockWrite(out_file,y2,4);
  end;
 i:=filesize(in_file)-filepos(in_file);
 case i of
  1,2,3,4:
   begin
    BlockRead(in_file,x1,i);
    x2:=0;
    for i1:=1 to 8 do
     begin
      y2:=x1 xor key[i1];
      y1:=x2 xor y2;
      x1:=y1;
      x2:=y2;
     end;
    BlockWrite(out_file,y1,4);
    BlockWrite(out_file,y2,4);
   end;
  5,6,7:
   begin
    BlockRead(in_file,x1,4);
    BlockRead(in_file,x2,i-4);
    for i1:=1 to 8 do
     begin
      y2:=x1 xor key[i1];
      y1:=x2 xor y2;
      x1:=y1;
      x2:=y2;
     end;
    BlockWrite(out_file,y1,4);
    BlockWrite(out_file,y2,4);
   end;
 end;
 Closefile(in_file);
 Closefile(out_file);
 MessageDlg('Êîäèðîâ**èå ç*êî*÷å**î',mtWarning,[mbok],1);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
 case RadioGroup1.ItemIndex of
   0:
    begin
     OpenDialog1.Filter:='Âñå ô*éëû |*.*';
     if OpenDialog1.Execute=true
     then fp1:=OpenDialog1.FileName
    end;
  1:
   begin
    OpenDialog1.Filter:='Âñå ç*êîäèðîâ***ûå ô*éëû |*.*cf';
    if OpenDialog1.Execute=true
    then fp1:=OpenDialog1.FileName
   end;
 end;
 LabeledEdit1.Text:=fp1;
end;
procedure TForm1.DecodingExecute(Sender: TObject);
begin
 if FileExists(LabeledEdit1.Text)=false
 then
  begin
   MessageDlg('Íå âûáð** äåêîäèðóåìûé ô*éë',mtError,[mbOK],1);
   Exit;
  end
 else
  if FileExists(LabeledEdit3.Text)=false
  then
   begin
    MessageDlg('Íå âûáð** êëþ÷åâîé ô*éë',mtError,[mbOK],1);
    Exit;
  end
 else AssignFile(in_file,fp1);
 AssignFile(out_file,copy(fp1,1,length(fp1)-2));
 Reset(in_file,1);
 Rewrite(out_file,1);
 for i:=1 to FileSize(in_file) div 8 do
  begin
   BlockRead(in_file,y1,4);
   BlockRead(in_file,y2,4);
   for i1:=8 downto 1 do
    begin
     x1:=y2 xor key[i1];
     x2:=y2 xor y1;
     y1:=x1;
     y2:=x2;
    end;
   BlockWrite(out_file,x1,4);
   BlockWrite(out_file,x2,4);
  end;
 i:=filesize(in_file)-filepos(in_file);
 case i of
  1,2,3,4:
   begin
    BlockRead(in_file,y1,i);
    y2:=0;
    for i1:=8 downto 1 do
     begin
      x1:=y2 xor key[i1];
      x2:=y2 xor y1;
      y1:=x1;
      y2:=x2;
     end;
    BlockWrite(out_file,x1,4);
    BlockWrite(out_file,x2,4);
   end;
  5,6,7:
   begin
    BlockRead(in_file,y1,4);
    BlockRead(in_file,y2,i-4);
    for i1:=8 downto 1 do
     begin
      x1:=y2 xor key[i1];
      x2:=y2 xor y1;
      y1:=x1;
      y2:=x2;
     end;
    BlockWrite(out_file,x1,4);
    BlockWrite(out_file,x2,4);
  end;
 end;
 Closefile(in_file);
 Closefile(out_file);
 MessageDlg('Äåêîäèðîâ**èå ç*êî*÷å**î',mtWarning,[mbok],1);
end;
end.
2
Delphi
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, Grids, XPMan;
type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    Knopka1: TBitBtn;
    Edit1: TEdit;
    XPManifest1: TXPManifest;
    Shifr: TButton;
    MainMemo: TMemo;
    Save: TButton;
    Label1: TLabel;
    procedure FormActivate(Sender: TObject);
    procedure Knopka1Click(Sender: TObject);
    procedure ShifrClick(Sender: TObject);
    procedure SaveClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
  i,x,y,z,r,o,a,a2,a3,m,mx,m0: byte;
  Text0,Text1: String;
  ShifrStolb: array [1..7] of byte = (1,2,3,7,6,5,4); //êëþ÷ ê ñòîëáö*ì 7 öèôð
  ShifrStrok: array [1..6] of byte = (1,2,6,3,5,4); //êëþ÷ ê ñòðîê*ì 6 öèôð
  Hash: array [1..42] of string;
//---Save-----------------------------------------------------------------------
  F:TextFile;
  u,g:integer;
  so:string;
implementation
{$R *.dfm}
//-----------------------Íóìåð*öèÿ StringGrid-----------------------------------
procedure TForm1.FormActivate(Sender: TObject);
begin
  for x := 1 to StringGrid1.RowCount-1 do
    StringGrid1.Cells[0,x]:= inttostr(StringGrid1.Row+x-1);
  for y := 1 to StringGrid1.ColCount-1 do
    StringGrid1.Cells[y,0]:= inttostr(StringGrid1.Col+y-1);
  Shifr.Enabled:= False;//âûêë.ê*. øèôð
  Save.Enabled := False;
end;
// -Ïðîâåðê* ñèìâîëîâ ** êîëè÷åñâî è èçìå*å*èå ïðîáåëîâ ** äðóãèå ñèìâîëû-------
procedure TForm1.Knopka1Click(Sender: TObject);
begin
  m :=(StringGrid1.RowCount-1)*(StringGrid1.ColCount-1); m0 :=m-1;
  Shifr.Enabled:= True;
  Text0 := edit1.Text;
  i := length(Text0);
  if i > m then ShowMessage ('Âû ââåëè áîëüøå '+inttostr(m)+' ñèìâîëîâ.Ëèø*èå îáðåç**û!');
  if i < m then ShowMessage ('Âû ââåëè ìå*üøå '+inttostr(m)+' ñèìâîëîâ. Ä***ûå ñîõð**å*û.');
    SetLength (Text0,m);
  for mx := 0 to m0 do
  begin
  if Text0[mx] = ' ' then Text0[mx] := #63;//ç*ïîë*å*èå ? ìåæäó ñëîâ*ìè
  end ;
  for mx := i to m0 do Text0[mx+1] := #63; //ç*ïîë*å*èå ? ëèø*åãî ïðîñòð**ñòâ*
end;
//------------------ Ñîðòèðîâê* ïî ñòîëáö*ì ------------------------------------
procedure TForm1.ShifrClick(Sender: TObject);
begin
 y:=1; x:=1; o:=1; a:=1; a2:=1; a3:=1;
for y := 1 to StringGrid1.RowCount-1 do
  begin
    for x := 1 to StringGrid1.ColCount-1 do
     begin
     StringGrid1.Cells[ShifrStolb[x],y]:= Text0[o];
     o:=o+1;
    end
   end;
//---------------------êîïèðîâ**èå ñòðîêè â êåø---------------------------------
  begin
    for y := 1 to StringGrid1.RowCount-1 do
  begin
    for x := 1 to StringGrid1.ColCount-1 do
     begin
     Hash[a]:=StringGrid1.Cells[x,y];
     a:=a+1;
   end ;
  end;
//------------------ Ñîðòèðîâê* ïî ñòðîê*ì -------------------------------------
  begin
  for x := 1 to  StringGrid1.ColCount-1 do
  begin
    for y := 1 to StringGrid1.RowCount-1 do
     begin
     StringGrid1.Cells[x,ShifrStrok[y]]:= Hash[a2];
     a2:=a2+1;
    end;
   end;
//-----------------------Âûâîä øèôð*--------------------------------------------
 begin
    for y := 1 to StringGrid1.RowCount-1 do
    begin
      for x := 1 to StringGrid1.ColCount-1 do
      begin
      Text1:= Text1+(StringGrid1.Cells[x,y]);
      a3:=a3+1 ;
     end;
     end;
     MainMemo.Lines.Add(text1);
     SetLength(Text1,0);
     Shifr.Enabled:= False;
     Save.Enabled := True;
    end;
   end;
 end;
end;
//---------------Ç*ïèñü â Ô*éë--------------------------------------------------
procedure TForm1.SaveClick(Sender: TObject);
begin
  AssignFile(f,'Result.txt');
  Rewrite(f);
  for u:=0 to StringGrid1.RowCount-1 do begin
    so:='';
    For g:=0 to StringGrid1.ColCount-1 do
      so:=so+StringGrid1.Cells[g,u]+' ';
    writeln(f,so);
    writeln(f,'');
  end;
  CloseFile(f);
  Save.Enabled := False;
  end;
end.
   
!
0
 
- , ,
-
Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
@Mail.ru