Version:0.9 StartHTML:0000000105 EndHTML:0000183708 StartFragment:0000000141 EndFragment:0000183672
Program Top5_Algorithm_Console5_Refactor;     //the big 5 algos
2 
3  //http://www.rosettacode.org/wiki/Prime_decomposition#Pascal ☮ ✞ π 📌 🐞   
4  //https://rosettacode.org/wiki/Happy_numbers#DWScript
5  //https://rosettacode.org/wiki/Fivenum#Delphi   - QSort
6  
7  {Purpose: to show the top 5 algorithms in one script:
8  https://sourceforge.net/projects/maxbox5/files/examples/1362_top_5_algorithm1_uc.txt/download
9     - 1.RSA cipher
10     - 2.Page Rank Method
11     - 3.Dijkstra Search
12     - 4.Q-Sort
13     - 5.ZCompression______________________________ }
14 
15 //http://rosettacode.org/wiki/RSA_code#Python  - message to 18 signs crypto system
16 
17 const _n = '9516311845790656153499716760847001433441357';  //# p*q = modulus = pub key
18       _e = '65537';                                        //2^16+1 as exponent
19       _d = '5617843187844953170308463622230283376298685';  //private key
20       
21 const message='@Rosetta Code!';
22
   
23 procedure compute_RSA(message: string);
24
 var abig: TInteger;  
25     s_encrypt, s_decrypt: string;
26
 begin
27    print('message to encrypt:   '+message) 
28    writeln('hex data: '+strtoHex1(message))
29
    writeln('test hex: '+Hextostr(strtoHex1(message)))
30
    
31    abig:= TInteger.create(1); 
32    abig.Assignhex(strtoHex1(message));
33
    writeln('convert_to_abigstring: '+abig.Tostring(normal))
34
     
35    s_encrypt:= BigPowMod(abig.Tostring(normal),_e, _n)    //bigmulu(ap,aq));
36    writeln('encrypted text integer '+s_encrypt)
37
    s_decrypt:= BigPowMod(s_encrypt,_d,_n)                 //bigmulu(ap,aq))
38    writeln('decrypted text integer '+s_decrypt)
39
    //amessage:= bytesof(s_decrypt);
40    abig.Assign2(s_decrypt);
41
    //writeln('decrypt message: '+HextoASCII(abig.ConvertToHexString))
42    writeln('decrypted text message: '+Hextostr(abig.ConvertToHexString))
43
    abig.Free;
44
 end;  
45 
46 procedure Show_CryptoSystem;
47
   //writeln(RSAencrypt('message', _e, _n));
48     // the asciivalue of A as 65 is 65!
49     // 549(c) = 65^675 mod 1012
50     // A = c(549)^3 mod 1012
51 begin   
52    //Crypt with public-key - decrypt with private 
53    writeln(RSADecrypt(RSAEncrypt('65','3','1012'),'675','1012'))
54
    //Sign with private-key - decrypt with public
55    writeln(RSADecrypt(RSAEncrypt('65','675','1012'),'3','1012'))
56
    
57    //Alternate Crypto Systems for a single sign 'A' as ASCII 65
58    writeln(RSADec(RSAEnc('65','7','221'),'55','221'))
59
    writeln(RSADec(RSAEnc('65','103','143'),'7','143'))
60
 end;  
61 
62 //PageRank_________________________________________________________
63 
64 const
65   DampingFactor = 0.85;
66
   MaxIterations = 100;
67
   Tolerance = 1.0e-6;
68
 
69 type
70   TTMatrix = array of array of Double;
71
   TTVector = array of Double;
72
 
73 Procedure SetArrayLength2Matrix(var arr: TTMatrix; asize1, asize2: Integer);
74
 var i: Integer;
75
 begin setlength(arr, asize1);
76
    for i:= 0 to asize1-1 do SetLength(arr[i], asize2);
77
 end;
78
 
79 function InitializeMatrix(N: Integer): TTMatrix;
80
 var
81   i, j: Integer;
82
 begin
83   //SetLength(Result, N, N);
84   SetArrayLength2Matrix(Result, N, N);
85
   for i:= 0 to N - 1 do
86     for j:= 0 to N - 1 do
87       Result[i][j]:= 0.0;
88
 end;
89
 
90 function InitializeVector(N: Integer): TTVector;
91
 var i: Integer;
92
 begin
93   SetLength(Result, N);
94
   for i:= 0 to N - 1 do
95     Result[i]:= 1.0 / N;
96
 end;
97
 
98 function MultiplyMatrixVector(const M: TTMatrix; const V: TTVector): TTVector;
99
 var
100   i, j: Integer;
101
   Sum: Double;
102
 begin
103   SetLength(Result, Length(V));
104
   for i:= 0 to High(M) do begin
105     Sum:= 0.0;
106
     for j:= 0 to High(M[i]) do
107       Sum:= Sum + M[i][j] * V[j];
108
     Result[i]:= Sum;
109
   end;
110
 end;
111
 
112 function PageRank(const Links: TTMatrix; N: Integer): TTVector;
113
 var
114   Rank, NewRank: TTVector;
115
   i, Iter: Integer;
116
   Delta: Double;
117
 begin
118   Rank:= InitializeVector(N);
119
   for Iter:= 1 to MaxIterations do begin
120     NewRank:= MultiplyMatrixVector(Links, Rank);
121
     for i:= 0 to N - 1 do
122       NewRank[i]:= (1 - DampingFactor) / N + DampingFactor * NewRank[i];
123
 
124     Delta:= 0.0;
125
     for i:= 0 to N - 1 do
126       Delta:= Delta + Abs(NewRank[i] - Rank[i]);
127
     Rank:= NewRank;
128
     if Delta < Tolerance then Break;
129
   end;
130
   Result:= Rank;
131
 end;
132
 
133 procedure PrintVector(const V: TTVector);
134
 var  i: Integer;
135
 begin
136   for i:= 0 to High(V) do
137     WriteLn(Format('Page %d: %.6f',[+ 1, V[i]]));
138
 end;
139
 
140 procedure pageRankMainMethod;
141
  var Links: TTMatrix;
142
      Ranks: TTVector;
143
 begin
144   // Ex.ample with 3 web pages
145   Links:= InitializeMatrix(3);
146
   Links[0][1]:= 1.0;
147
   Links[1][2]:= 1.0;
148
   Links[2][0]:= 1.0;
149
   Links[2][1]:= 1.0;
150
   Ranks:= PageRank(Links, 3);
151
   PrintVector(Ranks);
152
 end;
153
 
154 //Dijkstra Search_________________________________________________________ 
155 
156 // Conventional values (any negative values would do)
157 const
158   AINFINITY  = -1;
159
   NO_VERTEX = -2;
160
   NR_VERTICES = 6;
161
   
162 // DISTANCE_MATRIX[u, v] = length of directed edge from u to v, or -1 if no such edge exists.
163 // A simple way to represent a directed graph with not many vertices.
164 //var DISTANCE_MATRIX : array [0..(NR_VERTICES - 1), 0..(NR_VERTICES - 1)] of integer
165 var D_X : array [0..(NR_VERTICES - 1)] of array[0..(NR_VERTICES - 1)] of integer;
166
 {
167 = ((-1,  7,  9, -1, -1, -1),
168    (-1, -1, 10, 15, -1, -1),
169    (-1, -1, -1, 11, -1,  2),
170    (-1, -1, -1, -1,  6, -1),
171    (-1, -1, -1, -1, -1,  9),
172    (-1, -1, -1, -1, -1, -1)); }
173 
174 procedure fillDMatrix;
175
 begin
176 
177  d_X[0][0]:=-1;D_X[0][1]:=7;D_X[0][2]:=9;D_X[0][3]:=-1;D_X[0][4]:=-1;D_X[0][5]:=-1;
178
  D_X[1][0]:=-1;d_X[1][1]:=-1;D_X[1][2]:=10;D_X[1][3]:=15;D_X[1][4]:=-1;D_X[1][5]:=-1;
179
  D_X[2][0]:=-1;D_X[2][1]:=-1;d_X[2][2]:=-1;D_X[2][3]:=11;D_X[2][4]:=-1;D_X[2][5]:=2;
180
  D_X[3][0]:=-1;D_X[3][1]:=-1;D_X[3][2]:=-1;d_X[3][3]:=-1;D_X[3][4]:=6;D_X[3][5]:=-1;
181
  D_X[4][0]:=-1;D_X[4][1]:=-1;D_X[4][2]:=-1;D_X[4][3]:=-1;d_X[4][4]:=-1;D_X[4][5]:=9;
182
  D_X[5][0]:=-1;D_X[5][1]:=-1;d_X[5][2]:=-1;D_X[5][3]:=-1;D_X[5][4]:=-1;D_X[5][5]:=-1;
183
 
184 end;  
185 
186 type TTVertex = record
187   Distance: integer; // distance from vertex 0; infinity if a path has not yet been found
188   Previous: integer; // previous vertex in the path from vertex 0
189   Visited : boolean; // as defined in the algorithm
190 end;
191
 
192 // For distances x and y, test whether x < y, using the convention that -1 means infinity.
193 function IsLess( x, y : integer) : boolean;
194
 begin
195   result:= (<> AINFINITY)
196
         and ( (= AINFINITY) or (< y) );
197
 end;
198
 
199 Procedure DijkstraMainRoutine;
200
 // Main routine
201 var
202   v : array [0..NR_VERTICES - 1] of TTVertex; // array of vertices
203   c : integer; // index of current vertex
204   j : integer; // loop counter
205   trialDistance, minDistance : integer;
206
   // Variables for printing the result
207   p: integer;
208
   lineOut: string;
209
 begin
210   // Initialize the vertices
211   for j:= 0 to NR_VERTICES - 1 do begin
212     v[j].Distance:= AINFINITY;
213
     v[j].Previous:= NO_VERTEX;
214
     v[j].Visited:= false;
215
   end;
216
   // Start with vertex 0 as the current vertex
217   c:= 0;
218
   v[c].Distance:= 0;
219
 
220   // Main loop of Dijkstra's algorithm
221   repeat
222     // Work through unvisited neighbours of current vertex, updating them where possible.
223     // "Neighbour" means the end of a directed edge from the current vertex.
224     // Note that v[c].Distance is always finite.
225     for j:= 0 to NR_VERTICES - 1 do begin
226       if (not v[j].Visited) and (D_X[c][ j] >= 0) then begin
227         trialDistance:= v[c].Distance + D_X[c][ j];
228
         if IsLess( trialDistance, v[j].Distance) then begin
229           v[j].Distance:= trialDistance;
230
           v[j].Previous:= c;
231
         end;
232
       end;
233
     end;
234
     // When all neighbours have been tested, mark the current vertex as visited.
235     v[c].Visited:= true;
236
     // The new current vertex is the unvisited vertex with the smallest finite distance.
237     // If there is no such vertex, the algorithm is finished.
238     c:= NO_VERTEX;
239
     minDistance := AINFINITY;
240
     for j:= 0 to NR_VERTICES - 1 do begin
241       if (not v[j].Visited) and IsLess( v[j].Distance, minDistance) then begin
242         minDistance:= v[j].Distance;
243
         c:= j;
244
       end;
245
     end;
246
   until (= NO_VERTEX);
247
 
248   // Print the result
249   for j:= 0 to NR_VERTICES - 1 do begin
250     if (v[j].Distance = AINFINITY) then begin
251       // The algorithm never found a path to v[j]
252       lineOut:= {SysUtils.}Format( '%2d: inaccessible', [j]);
253
     end else begin
254       // Build up the path of vertices, working backwards from v[j]
255       lineOut:= {SysUtils.}Format( '%2d', [j]);
256
       p := v[j].Previous;
257
       while (<> NO_VERTEX) do begin
258         lineOut:= {SysUtils.}Format( '%2d --> ',[p]) + lineOut;
259
         p:= v[p].Previous;
260
       end;
261
       // Print the path of vertices, preceded by distance from vertex 0
262       lineOut:= {SysUtils.}Format('%2d: distance = %3d, ',[j,v[j].Distance])+ lineOut;
263
     end;
264
     WriteLn(lineOut);
265
   end;
266
 end;
267
 
268 //Free Pascal Solution // Free Pascal (Lazarus), console application.
269 type
270   TNodeSet = (setA, setB, setC);
271
   TTNode = record
272     NodeSet : TNodeSet;
273
     PrevIndex : integer;  // previous node in path leading to this node
274     PathLength : integer; // total length of path to this node
275   end;
276
   
277   const
278 // Rosetta code task
279   NR_NODES = 6;
280
   START_INDEX = 0;
281
   var
282   NODE_NAMES: array [0..NR_NODES - 1] of string;
283
   // = ('a','b','c','d','e','f');
284   // LENGTHS[j,k] = length of branch j -> k, or -1 if no such branch exists.
285  { LENGTHS : array [0..NR_NODES - 1] of array [0..NR_NODES - 1] of integer
286   = ((-1, 7, 9,-1,-1,14),
287      (-1,-1,10,15,-1,-1),
288      (-1,-1,-1,11,-1, 2),
289      (-1,-1,-1,-1, 6,-1),
290      (-1,-1,-1,-1,-1, 9),
291      (-1,-1,-1,-1,-1,-1));   }
292      
293    procedure initDNodes;
294
    begin  
295      // = ('a','b','c','d','e','f');
296       NODE_NAMES[0]:= 'a'; NODE_NAMES[1]:= 'b'; NODE_NAMES[2]:= 'c';
297
       NODE_NAMES[3]:= 'd'; NODE_NAMES[4]:= 'e';  NODE_NAMES[5]:= 'f';
298
       FillDMatrix;
299
    end; 
300    
301  procedure fpDijkstra_Main;
302
  var
303   nodes: array [0..NR_NODES - 1] of TTNode;
304
   j, j_min, k : integer;
305
   lastToSetA, nrInSetA: integer;
306
   branchLength, trialLength, minLength : integer;
307
   lineOut : string;
308
 begin
309   // Initialize nodes: all in set C
310   for j:= 0 to NR_NODES - 1 do begin
311     nodes[j].NodeSet:= setC;
312
     // No need to initialize PrevIndex and PathLength, as they are
313     //   not used until a value has been assigned by the algorithm.
314   end;
315
   // Begin by transferring the start node to set A
316   nodes[START_INDEX].NodeSet := setA;
317
   nodes[START_INDEX].PathLength := 0;
318
   nrInSetA:= 1;
319
   lastToSetA:= START_INDEX;
320
   // Transfer nodes to set A one at a time, until all have been transferred
321   while (nrInSetA < NR_NODES) do begin
322     // Step 1: Work through branches leading from the node that was most recently
323     //         transferred to set A, and deal with end nodes in set B or set C.
324     for j:= 0 to NR_NODES - 1 do begin
325       branchLength:= D_X[ lastToSetA][ j];
326
       if (branchLength >= 0) then begin
327         // If the end node is in set B, and the path to the end node via lastToSetA
328         //   is shorter than the existing path, then update the path.
329         if (nodes[j].NodeSet = setB) then begin
330           trialLength:= nodes[lastToSetA].PathLength + branchLength;
331
           if (trialLength < nodes[j].PathLength) then begin
332             nodes[j].PrevIndex:= lastToSetA;
333
             nodes[j].PathLength:= trialLength;
334
           end;
335
         end
336         // If the end node is in set C, transfer it to set B.
337         else if (nodes[j].NodeSet = setC) then begin
338           nodes[j].NodeSet:= setB;
339
           nodes[j].PrevIndex:= lastToSetA;
340
           nodes[j].PathLength:= nodes[lastToSetA].PathLength + branchLength;
341
         end;
342
       end;
343
     end;
344
     // Step 2: Find the node in set B with the smallest path length,
345     //         and transfer that node to set A.
346     //         (Note that set B cannot be empty at this point.)
347     minLength:= -1; // just to stop compiler warning "might not have been initialized"
348     j_min:= -1; // index of node with smallest path length; will become >= 0
349     for j:= 0 to NR_NODES - 1 do begin
350       if (nodes[j].NodeSet = setB) then begin
351         if (j_min < 0) or (nodes[j].PathLength < minLength) then begin
352           j_min:= j;
353
           minLength:= nodes[j].PathLength;
354
         end;
355
       end;
356
     end;
357
     nodes[j_min].NodeSet:= setA;
358
     inc( nrInSetA);
359
     lastToSetA:= j_min;
360
   end;
361
   // Write result to console
362   WriteLn({SysUtils.}Format('Shortest paths from node %s:',[NODE_NAMES[START_INDEX]]));
363
   for j:= 0 to NR_NODES - 1 do begin
364     if (<> START_INDEX) then begin
365       k:= j;
366
       lineOut:= NODE_NAMES[k];
367
       repeat
368         k:= nodes[k].PrevIndex;
369
         lineOut:= NODE_NAMES[k] + ' -> ' + lineOut;
370
       until (= START_INDEX);
371
       lineOut:= {SysUtils.}Format( '%3s: length %3d,  ',
372
                  [NODE_NAMES[j],nodes[j].PathLength])+ lineOut;
373
       WriteLn(lineOut);
374
     end;
375
   end;
376
 end;  
377 
378 //QSort_________________________________________________________ 
379 
380  var x,x2,x3,x4: array of double;   //x: TArray<double>;
381 
382 procedure InitData;
383
 begin
384  { xl:= [[15.0, 6.0, 42.0, 41.0, 7.0, 36.0, 49.0, 40.0,
385     39.0, 47.0, 43.0], [36.0, 40.0, 7.0, 39.0, 41.0, 15.0], [0.14082834,
386     0.09748790, 1.73131507, 0.87636009, -1.95059594, 0.73438555, -0.03035726,
387     1.46675970, -0.74621349, -0.72588772, 0.63905160, 0.61501527, -0.98983780, -
388     1.00447874, -0.62759469, 0.66206163, 1.04312009, -0.10305385, 0.75775634,
389     0.32566578]]; }
390     x2:= [15.0, 6.0, 42.0, 41.0, 7.0, 36.0, 49.0, 40.0, 39.0, 47.0, 43.0];
391
     x3:= [36.0, 40.0, 7.0, 39.0, 41.0, 15.0];
392
     x4:= [0.14082834, 0.09748790,1.73131507,0.87636009,-1.95059594,0.73438555,-0.03035726,
393
     1.46675970,-0.74621349, -0.72588772, 0.63905160, 0.61501527, -0.98983780,-
394
     1.00447874,-0.62759469, 0.66206163, 1.04312009, -0.10305385, 0.75775634,
395
     0.32566578];
396
 end;  
397 
398 { uses
399   System.SysUtils,
400   System.Generics.Collections;  }
401 
402 //function Median(x: TArray<Double>; start, endInclusive: Integer): Double;
403 function Median(x: array of double; start, endInclusive: Integer): Double;
404
 var size, m: Integer;
405
 begin
406   size:= endInclusive - start + 1;
407
   if (size <= 0) then
408     xraise (Exception.Create('Array slice cannot be empty')); //EArgumentException
409   m:= start + size div 2;
410
   if (odd(size)) then
411     Result:= x[m]
412
   else
413     Result:= (x[- 1] + x[m]) / 2;
414
 end;
415
 
416 procedure QuickSortD(var A: array of Double; iLo, iHi: Integer);
417
 var
418   Lo, Hi: Integer;
419
   Pivot, T: Double;
420
 begin
421   Lo := iLo;
422
   Hi := iHi;
423
   Pivot := A[(Lo + Hi) div 2];
424
   repeat
425     while A[Lo] < Pivot do Inc(Lo);
426
     while A[Hi] > Pivot do Dec(Hi);
427
     if Lo <= Hi then begin
428       T := A[Lo];
429
       A[Lo] := A[Hi];
430
       A[Hi] := T;
431
       Inc(Lo);
432
       Dec(Hi);
433
     end;
434
   until Lo > Hi;
435
   if Hi > iLo then QuickSortD(A, iLo, Hi);
436
   if Lo < iHi then QuickSortD(A, Lo, iHi);
437
 end;
438
 
439 //function FiveNumber(x: TArray<Double>): TArray<Double>;
440 function FiveNumber(x: array of double): array of double;
441
 var m, lowerEnd: Integer;
442
     adbl: TALBaseQuickSortList; //TALDoubleList;
443     slist: TSingleListClass;
444
 begin
445   SetLength(result, 5);
446
   //TArray.Sort<double>(x);
447   //glSortArrayAscending(sortx);
448   //adbl:= TALBaseQuickSortList.create; //TALDoubleList.create;
449  { slist:= TSingleListClass.create;  
450   for it:= 0 to length(x)-1 do 
451         slist.add(x[it]);
452    slist.sortup;  
453    for it:= 0 to length(x)-1 do 
454         x[it]:= slist.items[it];   
455   ///adbl.free;
456   slist.free;  }
457   writeln('4. Q-Sort Algorithm starts...');
458
   QuickSortD(x, Low(x), High(x));
459
   result[0]:= x[0];
460
   result[2]:= median(x, 0, length(x) - 1);
461
   result[4]:= x[length(x) - 1];
462
   m:= length(x) div 2;
463
   if odd(length(x)) then
464     lowerEnd:= m
465   else lowerEnd:= m - 1;
466
   result[1]:= median(x, 0, lowerEnd);
467
   result[3]:= median(x, m, length(x) - 1);
468
 end;
469
 
470 //function ArrayToString(x: TArray<double>): string;
471 function ArrayToString(x: array of double): string;
472
 var i: Integer;
473
 begin
474   Result:= '[';
475
   for i:= 0 to High(x) do begin
476     if i > 0 then
477       Result:= Result + ',';
478
     Result:= Result + format('%.4f', [x[i]]);
479
   end;
480
   Result:= Result + ']';
481
 end;
482
 
483 procedure showQSortResult;
484
 begin
485 //for x in xl do
486     SetLength(x, length(x2));
487
     for it:= 0 to length(x2)-1 do 
488                               x[it]:= x2[it];
489
     writeln(ArrayToString(FiveNumber(x))+ #10#13);
490
     SetLength(x, length(x3));
491
     for it:= 0 to length(x3)-1 do 
492                               x[it]:= x3[it];
493
     writeln(ArrayToString(FiveNumber(x))+ #10#13);
494
     SetLength(x, length(x4));
495
     for it:= 0 to length(x4)-1 do 
496                               x[it]:= x4[it];
497
     writeln(ArrayToString(FiveNumber(x))+ #10#13);
498
 end;
499
   
500     
501 const  //Z Compression_________________________________________________________ 
502 
503   SHCONTCH_NOPROGRESSBOX = 4;
504
   SHCONTCH_AUTORENAME = 8;
505
   SHCONTCH_RESPONDYESTOALL = 16;
506
   SHCONTF_INCLUDEHIDDEN = 128;
507
   SHCONTF_FOLDERS = 32;
508
   SHCONTF_NONFOLDERS = 64;
509
     
510 function TShellZipFolder5(sourcefolder,azipfile:string; filter: string {= ''}): boolean;
511
 //const
512   //emptyzip: array[0..23] of byte=(80,75,5,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
513 var
514   emptyzip: TByteDynArray;
515
   ms: TMemoryStream;
516
   shellobj, srcfldr, destfldr, shellfldritems: variant;
517
   numt: integer;
518
 begin
519   SetLength(emptyzip, 23);   //for ZIP Header Def.
520   emptyzip:= [80,75,5,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
521
   if not FileExists(azipfile) then begin
522     //do create a new empty ZIP file
523     ms:= TMemoryStream.Create;
524
     try
525       ms.WriteBufferABD(emptyzip, length(emptyzip));
526
       ms.SaveToFile(azipfile);
527
     finally  
528       ms.Free;
529
     end;  //}
530   end;
531
 
532   numt:= NumProcessThreads;
533
   shellobj:= CreateOleObject('Shell.Application');
534
   srcfldr:= shellobj.NameSpace(sourcefolder);
535
   destfldr:= shellobj.NameSpace(azipfile);
536
   shellfldritems:= srcfldr.Items;
537
   if (filter <> '') then
538     shellfldritems.Filter(SHCONTF_INCLUDEHIDDEN or 
539                               SHCONTF_NONFOLDERS or SHCONTF_FOLDERS,filter);
540
   destfldr.CopyHere(shellfldritems, 0);
541
   // wait till all shell threads are terminated
542   while NumProcessThreads <> numt do begin
543     sleep(150);
544
   end;
545
 end;
546
 
547 procedure TShellZip_Unzip4(const tarfolder, Azipfile: String);
548
 var varzipfile, shellObj: OlEVariant;
549
 begin
550   shellobj:= CreateOleObject('Shell.Application');
551
   if DirectoryExists(tarfolder) = false then  //in case of
552                CreateDir(tarfolder);
553
   varzipfile:= AZIPFILE;
554
   Shellobj.namespace(tarfolder).CopyHere(Shellobj.namespace(varzipfile).Items)
555
   shellobj:= unassigned;  //}
556 end;
557
 
558 var dc: array of TInteger;
559
  //Feel free to adapt and expand this code to suit your specific training needs!
560   
561 begin   //@main - note: define your archive-path first for compression!
562 
563    Writeln('1. RSA Algo___________________')
564
     maXcalcF('2^16+1')
565
     //compute_RSA(message);
566     compute_RSA('@Rosetta Code!123'); 
567   
568   //function RSAEnc(aval, apow, amod: string): string;');
569   //function RSADec(aval, apow, amod: string): string;');
570     Show_CryptoSystem();
571
     
572     Writeln('2. Page Rank Algo___________________')
573
     pageRankMainMethod();
574
   
575     Writeln('3. Dijkstra Algo___________________')
576
     FillDMatrix();
577
     DijkstraMainRoutine();
578
     //FreePascal
579     initDNodes();
580
     fpDijkstra_Main();
581
     
582     Writeln('4. QSort Algo___________________')
583
     //glSortArrayAscending( var a : array of Extended)
584     InitData();
585
     showQSortResult();
586
 
587     //Fivenum_PySolution('Baden');
588     Writeln('5. Z-Compression Algo___________________')
589
 
590     {TShellZipFolder5(exepath+'web',
591                      exepath+'examples\maxboxziptest5.zip', '');
592     sleep(1000)
593     TShellZip_Unzip4(exepath+'crypt\Decompress5', 
594                      exepath+'examples\maxboxziptest5.zip');  //}
595 End.
596
 
597 
598 Doc: How does Zip works:
599
 ------------------------------------
600
 ZIP is an archive file format that supports lossless data compression. 
601 A ZIP file may contain one or more files or directories that may have 
602 been compressed. The ZIP file format permits a number of compression algorithms, 
603 though DEFLATE is the most common. 
604 https://en.wikipedia.org/wiki/ZIP_(file_format)
605 
606 Doc: How QSort works:
607
 ------------------------------------
608
 qsort is a C standard library function that implements a sorting algorithm for arrays of 
609 arbitrary objects according to a user-provided comparison function. It is named after
610  the "quicker sort" algorithm[1] (a quicksort variant due to R. S. Scowen), which 
611  was originally used to implement it in the Unix C library, although the C standard 
612  does not require it to implement quicksort.[2]
613
 
614 Doc: How Dijkstra works:
615
 ------------------------------------
616
 In this article, we will be discussing one of the most commonly known shortest-path algorithms
617  i.e. Dijkstras Shortest Path Algorithm which was developed by Dutch computer scientist 
618  Edsger W. Dijkstra in 1956. Moreover, we will do a complexity analysis for this 
619  algorithm and also see how it differs from other shortest-path algorithms.
620
 https://www.geeksforgeeks.org/introduction-to-dijkstras-shortest-path-algorithm/ 
621 
622 Doc: How PageRank works:
623
 ------------------------------------
624
 //2. Page Rank Algo_________________
625 The PageRank algorithm, originally developed by Larry Page and Sergey Brin, is used by search engines 
626 to rank web pages in their search results. 
627 Below is a simplified implementation of the PageRank algorithm in Delphi:  
628 This script program initializes a simple web graph with three pages and computes their PageRank values. The PageRank 
629 function iteratively updates the rank values until convergence is achieved. The results are then printed to the console. }
630
 
631 https://www.searchenginewatch.com/2018/10/25/googles-pagerank-algorithm-explained/
632 
633 ref: 2. Page Rank Algo___________________
634 Page 1: 0.333333
635 Page 2: 0.574167
636 Page 3: 0.857500
637  mX5  executed: 12/01/2025 09:49:39  Runtime: 0:0:2.167  Memload: 69% use
638 
639 Doc: How RSA works
640 ------------------------------------
641
 Generating the public and private keys. Pick two large prime numbers, p and q. 
642 Let n=pq. Typically, n is a number which in binary is written with 1024 bits (in decimal, 
643 that's about 308 digits). Pick e relatively prime to (p-1)(q-1). 
644 Now find d such that ed=1 mod (p-1)(q-1). You can use Euclid's algorithm to find this d. 
645 The pair of numbers (e, n) is the public key. The pair of numbers (d, n) is the private key. 
646 The two primes p,q are no longer needed, and can be discarded, but should never be revealed.
647
 
648 Ref aus Herdt S.119 Ausgabe 10 Netzwerk Sicherheit
649 
650 1. Modulus Prime1: 23  &  Prime2: 47
651
 2. RSA Modul Public [p*q] as N: 1081
652
 3. Phi(N) Private: 1012 = 22*46
653
 4. Public RSA Exponent: 3
654
 5. Private D: 675
655
 6. Public (3,1081) - Private (675,1081)
656
 
657 Ref Second Crypto System:
658
 1. Prime1: 13  &  Prime2: 17
659
 2. RSA Modul Public [p*q] as N: 221
660
 3. Phi(N) Private: 192 = 12*16
661
 4. Public RSA Exponent: 7
662
 5. Private D: 55
663
 6. Public (7,221) - Private (55,221)
664
 
665     https://soundcloud.com/max-kleiner-481715070
666     https://soundcloud.com/max-kleiner-481715070/g9-zeitraum-fm-127bpm-441hz?si=fe9fd03b58314bdb8621ebf9106b9184&utm_source=clipboard&utm_medium=text&utm_campaign=social_sharing
667     https://www.youtube.com/watch?v=904JoHPWcek
668     https://grandbrothers.bandcamp.com/album/late-reflections
669   
670 Doc: In mathematics and computer science, an algorithm (/ˈælɡərɪðəm/ ⓘ) is a finite sequence of 
671 mathematically rigorous instructions, typically used to solve a class of specific 
672 problems or to perform a computation.[1]
673
 Doc: Ein Algorithmus (benannt nach dem Mathematiker und Universalgelehrten al-Chwarizmi, 
674 von arabisch: الخوارزمی al-Ḫwārizmī, deutsch der Choresmier‘) ist eine 
675 eindeutige Handlungsvorschrift zur Lösung eines Problems oder einer Klasse von Problemen. 
676 
677 Netzdienlichkeit: Soweit Strompreise 
678 mit hohen Netzbelastungen korrelieren, können dynamische Strompreise 
679 dazu beitragen, die für die Netzauslegung maßgebliche Jahreshöchstlast 
680 zu reduzieren. K
681 https://energy-charts.info/charts/price_spot_market/chart.htm?l=de&c=DE&minuteInterval=empty&zoom=plus&timezone=user
682 [notice] A new release of pip is available: 24.0 -> 24.3.1
683 [notice] To update, run: python.exe -m pip install --upgrade pip
684 
685 C:\maxbox\maxbox5\ekon29\EKON29_Materials_2025_solution3_64>
686
 
687 ----app_template_loaded_code----
688
 ----File newtemplate.txt not exists - now saved!----