unit GDH512 xGDH Gleb Rodin Daria Burminova GNU General Public License

  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
unit GDH512;
{
xGDH (c) Gleb Rodin, Daria Burminova
GNU General Public License, version 2:
http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
}
interface
uses
functions,
sysutils;
type
T512 = int64;
TByteArray = array of byte;
{Ѓ §®ўлҐ «®ЈЁзҐбЄЁҐ дг­ЄжЁЁ}
function FuncA512(B, C, D, E, F, G, H : T512) : T512;
function FuncB512(C, D, E, F, G, H, A : T512) : T512;
function FuncC512(D, E, F, G, H, A, B : T512) : T512;
function FuncD512(E, F, G, H, A, B, C : T512) : T512;
function FuncE512(F, G, H, A, B, C, D : T512) : T512;
function FuncF512(G, H, A, B, C, D, E : T512) : T512;
function FuncG512(H, A, B, C, D, E, F : T512) : T512;
function FuncH512(A, B, C, D, E, F, G : T512) : T512;
{Ѓ §®ўлҐ «®ЈЁзҐбЄЁҐ дг­ЄжЁЁ}
{”г­ЄжЁп ¤®Ї®«­Ґ­Ёп}
function addition512(x, y, z, r : T512) : T512;
{”г­ЄжЁп ¤®Ї®«­Ґ­Ёп}
{”г­ЄжЁп ЇҐаҐў®¤  §­ зҐ­Ё© ў иҐбв­ ¤ж вЁаЁз­го бЁб⥬г бзЁб«­ҐЁп}
{”г­ЄжЁп Є®­Є вҐ­ жЁЁ §­ зҐ­Ё© ў бва®Єг}
function strhash512(A, B, C, D, E, F, G, H : T512) : string;
{”г­ЄжЁп Є®­Є вҐ­ жЁЁ §­ зҐ­Ё© ў бва®Єг}
{”г­ЄжЁп ЇҐаҐў®¤  §­ зҐ­Ё© ў иҐбв­ ¤ж вЁаЁз­го бЁб⥬г бзЁб«­ҐЁп}
{”г­ЄжЁп ениЁа®ў ­Ёп}
function hashing512(temp : TByteArray; inputlength : int64; A, B, C, D, E, F, G, H : T512; o : byte) : string;
{”г­ЄжЁп ениЁа®ў ­Ёп}
implementation
{Ѓ §®ўлҐ «®ЈЁзҐбЄЁҐ дг­ЄжЁЁ}
function FuncA512(B, C, D, E, F, G, H : T512) : T512;
begin
FuncA512 := ((B xor G) and (not(H) or C) or (F and E)) xor D;
end;
function FuncB512(C, D, E, F, G, H, A : T512) : T512;
begin
FuncB512 := not((A and E) xor (C xor F) and ((D or H) and G));
end;
function FuncC512(D, E, F, G, H, A, B : T512) : T512;
begin
FuncC512 := ((F and not(G)) xor A) or (H and D) and (B xor E);
end;
function FuncD512(E, F, G, H, A, B, C : T512) : T512;
begin
FuncD512 := not(A and C) xor (G and (B and F and E xor H));
end;
function FuncE512(F, G, H, A, B, C, D : T512) : T512;
begin
FuncE512 := G and not(H and (C xor A)) and (B or D) and F;
end;
function FuncF512(G, H, A, B, C, D, E : T512) : T512;
begin
FuncF512 := (B and C) xor (D or E) xor not(G xor (H xor A));
end;
function FuncG512(H, A, B, C, D, E, F : T512) : T512;
begin
FuncG512 := (D xor not(F)) or (A and (B and E)) and (H and C);
end;
function FuncH512(A, B, C, D, E, F, G : T512) : T512;
begin
FuncH512 := A and (F or not(E)) and (B or G) or (C xor D);
end;
{Ѓ §®ўлҐ «®ЈЁзҐбЄЁҐ дг­ЄжЁЁ}
{”г­ЄжЁп ¤®Ї®«­Ґ­Ёп}
function addition512(x, y, z, r : T512) : T512;
var
s, c : extended;
begin
case odd(z) of
TRUE :
begin
s := sin(x + y + z + r) * 1000000000;
addition512 := round(s);
end;
FALSE :
begin
c := cos(x + y + z + r) * 1000000000;
addition512 := round(c);
end;
end;
end;
{”г­ЄжЁп ¤®Ї®«­Ґ­Ёп}
{”г­ЄжЁп ЇҐаҐў®¤  §­ зҐ­Ё© ў иҐбв­ ¤ж вЁаЁз­го бЁб⥬г бзЁб«­ҐЁп}
{”г­ЄжЁп Є®­Є вҐ­ жЁЁ §­ зҐ­Ё© ў бва®Єг}
function strhash512(A, B, C, D, E, F, G, H : T512) : string;
var
hash512 : string[128];
begin
hash512 := '';
hash512 := inttohex(H,16) + inttohex(A,16);
hash512 := hash512 + inttohex(G,16) + inttohex(B,16);
hash512 := hash512 + inttohex(F,16) + inttohex(C,16);
hash512 := hash512 + inttohex(E,16) + inttohex(D,16);
strhash512 := hash512;
end;
{”г­ЄжЁп Є®­Є вҐ­ жЁЁ §­ зҐ­Ё© ў бва®Єг}
{”г­ЄжЁп ЇҐаҐў®¤  §­ зҐ­Ё© ў иҐбв­ ¤ж вЁаЁз­го бЁб⥬г бзЁб«­ҐЁп}
{”г­ЄжЁп ениЁа®ў ­Ёп}
function hashing512(temp : TByteArray; inputlength : int64; A, B, C, D, E, F, G, H : T512; o : byte) : string;
var
x, y, z, i, j, k, templength : int64;
p, w : real;
percent, v0, v1, v2, tbyte0, tbyte1, tbyte2, tbyte3 : byte;
begin
x := 0;
y := 0;
z := 1;
k := 1;
percent := 0;
w := 2.5;
v1 := 1;
v2 := 40;
j := 32;
templength := length(temp);
p := templength / 100;
while x <= templength do
begin
while z <= 7 do
begin
tbyte0 := temp[x + (2 * z) + y];
inc(y);
tbyte1 := temp[x + (2 * z) + y];
inc(y);
tbyte2 := temp[x + (2 * z) + y];
inc(y);
tbyte3 := temp[x + (2 * z) + y];
case z of
0 : A := A + (tbyte0 shl 24) + (tbyte1 shl 16) + (tbyte2 shl 8) + tbyte3;
1 : B := B + (tbyte0 shl 24) + (tbyte1 shl 16) + (tbyte2 shl 8) + tbyte3;
2 : C := C + (tbyte0 shl 24) + (tbyte1 shl 16) + (tbyte2 shl 8) + tbyte3;
3 : D := D + (tbyte0 shl 24) + (tbyte1 shl 16) + (tbyte2 shl 8) + tbyte3;
4 : E := E + (tbyte0 shl 24) + (tbyte1 shl 16) + (tbyte2 shl 8) + tbyte3;
5 : F := F + (tbyte0 shl 24) + (tbyte1 shl 16) + (tbyte2 shl 8) + tbyte3;
6 : G := G + (tbyte0 shl 24) + (tbyte1 shl 16) + (tbyte2 shl 8) + tbyte3;
7 : H := H + (tbyte0 shl 24) + (tbyte1 shl 16) + (tbyte2 shl 8) + tbyte3;
end;
inc(z);
y := 0;
end;
i := 1;
while i <= j do
begin
A := H + (A + FuncA512(B, C, D, E, F, G, H) + addition512(i, x, k, E)) shr 2;
inc(k);
B := G + (B + FuncB512(C, D, E, F, G, H, A) + addition512(i, x, k, D)) shl 3;
inc(k);
C := F + (C + FuncC512(D, E, F, G, H, A, B) + addition512(i, x, k, C)) shr 5;
inc(k);
D := E + (D + FuncD512(E, F, G, H, A, B, C) + addition512(i, x, k, B)) shl 7;
inc(k);
E := D + (E + FuncE512(F, G, H, A, B, C, D) + addition512(i, x, k, H)) shr 2;
inc(k);
F := C + (F + FuncF512(G, H, A, B, C, D, E) + addition512(i, x, k, G)) shl 3;
inc(k);
G := B + (G + FuncG512(H, A, B, C, D, E, F) + addition512(i, x, k, F)) shr 5;
inc(k);
H := A + (H + FuncH512(A, B, C, D, E, F, G) + addition512(i, x, k, A)) shl 7;
inc(i);
inc(k);
end;
inc(x,32);
z := 1;
case o of
1 :
begin
case x > (percent + 1) * p of
TRUE : inc(percent);
end;
case percent > w of
TRUE :
begin
w := w + 2.5;
inc(v1);
dec(v2);
end;
end;
write(#13,'‚лЇ®«­Ґ­® : ');
v0 := 1;
while v0 < v1 do
begin
write(#219);
inc(v0);
end;
v0 := 1;
while v0 < v2 do
begin
write(#177);
inc(v0)
end;
write(' ',percent,'%');
end;
end;
end;
case o of
1 :
begin
writeln;
writeln;
end;
end;
hashing512 := strhash512(A, B, C, D, E, F, G, H);
A := 0;
B := 0;
C := 0;
D := 0;
E := 0;
F := 0;
G := 0;
H := 0;
end;
{”г­ЄжЁп ениЁа®ў ­Ёп}
end.