crypto 0.1.1

  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
program coder;
{var lib:array[1..242]of string;
libbytes:array[1..242]of string;
libnames:array[1..242]of string;
ls:array[1..11]of string;
lss:array[1..2]of string;}
begin
randomize;
var kj:array [,] of integer;
var ki:array [,] of integer;
var h := new System.IO.StreamReader('input.txt', System.Text.Encoding.Default);
var text,liba:string;
var n:integer;
var sc:=0;
text:=h.ReadLine;
n:=length(text);
writeln(text);
h.Close;
kj := new integer[n,3];
ki := new integer[n,3];
writeln('Тихо! Идёт кодировка!');
for var i:=0 to n-1 do begin
for var j:=0 to 2 do begin
randomize;
sc:=sc+1;
kj[i,j]:=random(7);
for var u:=1 to 1000 do begin
randomize;
for var m:=0 to 2 do begin
if j<>m then begin
randomize;
if kj[i,j]=kj[i,m] then kj[i,j]:=random(7);
if kj[i,m]=1 then begin
randomize;
if kj[i,j]=2 then kj[i,j]:=random(7);
end;
if kj[i,m]=7 then begin
randomize;
if kj[i,j]=6 then kj[i,j]:=random(7);
randomize;
end;
if kj[i,m]-1>0 then begin
randomize;
if kj[i,m]+1<7 then begin
randomize;
if kj[i,j]=(kj[i,m]-1) then kj[i,j]:=random(7);
randomize;
if kj[i,j]=(kj[i,m]+1) then kj[i,j]:=random(7);
end;
end;
end;
end;
end;
randomize;
if random(2)=0 then begin
if kj[i,j]>0 then ki[i,j]:=kj[i,j]-1;
if kj[i,j]=0 then ki[i,j]:=kj[i,j]+1;
end;
if random(2)=1 then begin
if kj[i,j]<6 then ki[i,j]:=kj[i,j]+1;
if kj[i,j]=6 then ki[i,j]:=kj[i,j]-1;
end;
// test writeln('kj:',kj[i,j],' / ki:',ki[i,j],' / num:',sc);
end;
end;
//writeln(n,' all right');
//шифруем теперь.
var p:array[,] of string;
var pe:array[,] of string;
var packs:array of string;
var simb:array of string;
var lib:array of string;
var simbt:array of string;
var l := new System.IO.StreamReader('lib.txt', System.Text.Encoding.Default);
var g:=128;var index:=1;
liba:=l.ReadLine;
l.Close;
setlength(lib,g);setlength(simb,g);
setlength(simbt,n*7);
//setlength(p,n*7);setlength(pe,n*7);
p:=new string[n,7];
pe:=new string[n,7];
setlength(packs,n);
for var i:=0 to g-1 do begin
lib[i]:=copy(liba,index,7);index:=index+7;
simb[i]:=copy(liba,index,1);index:=index+1;
// writeln(lib[i],'/',simb[i]);
end;index:=-1;
for var i:=0 to n-1 do begin
for var j:=0 to 6 do begin
index:=index+1;
simbt[index]:=copy(text,index,1);
end;
end;
//Парсим текст на наличие неизвестных символов и присваиваем на кодировку.
var tr:=false;
for var i:=0 to n-1 do begin
tr:=false;
for var j:=0 to g-1 do begin
if simbt[i]=simb[j] then begin
tr:=true;
packs[i]:=lib[j];
end;
end;
if tr=false then packs[i]:=lib[1];
// write(packs[i]);
end;
//присваимаем циферкам
writeln('');
for var i:=0 to n-1 do begin
for var j:=0 to 6 do begin
index:=index+1;
p[i,j]:=copy(packs[i],j,1);
pe[i,j]:=p[i,j];
// write(pe[i,j]);
end;
end;
sc:=0;
var num,num1:integer;
//var t1,t2:string;
for var i:=0 to n-1 do begin
for var j:=0 to 6 do begin
for var o:=0 to 2 do begin
if j=kj[i,o] then begin
num:=kj[i,o];
num1:=ki[i,o];
// writeln(num,'/',num1);
swap(pe[i,num],pe[i,num1]);
end;
end;
end;
end;
writeln('');
text:='';
for var i:=0 to n-1 do begin
for var j:=0 to 6 do begin
text:=text+pe[i,j];
end;
end;
// writeln(text);
index:=1;
for var i:=0 to n-1 do begin
packs[i]:=copy(text,index,7);
index:=index+7;
// writeln(packs[i]);
end;
//Переводим в норм текст
for var i:=0 to n-1 do begin
for var j:=0 to 127 do begin
if packs[i]=lib[j] then write(simb[j]);
end;
end;
writeln('');writeln('');
writeln('KEY:');writeln('');
for var i:=0 to n-1 do begin
for var j:=0 to 2 do begin
write(kj[i,j],ki[i,j]);
end;
end;
end.