#1 Re: mORMot 2 » TAESPRNG manual seed » 2024-11-09 21:01:20

ab wrote:

Use Lecuyer + mormot.core.text for hexa.

If you can, please provide an example of the code, otherwise it’s not clear at all smile

#2 Re: mORMot 2 » TAESPRNG manual seed » 2024-11-09 09:14:02

ab wrote:

There is no point.

Use directly an AES-CTR generator with a fixed key and IV.

Or use mormot.core.base Lecuyer generator, which allows a 32-bit seed and is good enough as generator.

Hello, I tested Lecuyer, it doesn’t have the FillRandomHex I need like in TAESPRNG sad

#3 Re: mORMot 2 » TAESPRNG manual seed » 2024-11-09 07:39:53

Are you a fool? These properties are not assigned; they are read-only!

#4 mORMot 2 » TAESPRNG manual seed » 2024-11-08 23:23:59

Uefi
Replies: 6

Hi how can I assign to manually seed for TAESPRNG Random Generator ?

function GenRandom: integer;
var
prng:TAESPRNG;
begin
prng:=TAESPRNG.Create;
prng.Seed:=57454654; // ????????????
Result:= prng.Random64;
prng.Free;
end;

#5 mORMot 2 » RIPEMD160 available in Mormot ? » 2024-09-12 06:36:11

Uefi
Replies: 1

Hello, is there any work with RIPEMD160 in the mormot library, I just can’t find it?

#6 Re: mORMot 2 » How to parse command line parameters ? » 2024-07-27 07:26:55

ab wrote:

This is how pascal strings and pointers work.

I have already tried with pointers and all sorts of transformations, more than one option directly and it didn’t work, why I don’t know

#7 Re: mORMot 2 » How to parse command line parameters ? » 2024-07-27 04:49:50

Strange, I tried direct conversion and it doesn’t work sad

uses mormot.core.text, mormot.core.base;

function ParseCommandLine(const param: string; out acount: Integer): PPWideChar;
var
par:TRawUtf8DynArray;
j:integer;
begin
par:=CsvToRawUtf8DynArray(param, ' -');
acount:=Length(par);
for j:=1 to acount-1 do
par[j]:=Trim('-'+par[j]));
Result:=PPWideChar(par);
end;

#8 Re: mORMot 2 » How to parse command line parameters ? » 2024-07-26 14:47:54

Well, if you could tell me how to do it better, I’m not very quick-witted

#9 Re: mORMot 2 » How to parse command line parameters ? » 2024-07-26 11:41:06

Yeah, I think I did it and it works well, but I don’t like that there are a lot of transformations sad

uses mormot.core.text, mormot.core.base;

function ParseCommandLine(const param: string; out acount: Integer): PPWideChar;
var
par:TRawUtf8DynArray;
arg:array of PWideChar;
j:integer;
begin
par:=CsvToRawUtf8DynArray(param, ' -');
acount:=Length(par);
SetLength(arg, acount);
arg[0]:=PWideChar(wideString(Trim(par[0])));
for j:=1 to acount-1 do
arg[j]:=PWideChar(wideString(Trim('-'+par[j])));
Result:=PPWideChar(arg);
end;

Maybe it will be useful to someone

#10 Re: mORMot 2 » How to parse command line parameters ? » 2024-07-25 12:20:42

ab wrote:

Yes because there is no plain argument!

I still don’t understand how to parse it correctly smile

I think I did it, only the problem remains: I don't know how to properly convert to PPWideChar smile

function ParseCommandLine(const param: string): PPWideChar;
var
ar:TRawUtf8DynArray;
j:integer;
begin
ar:=CsvToRawUtf8DynArray(param, ' -');
for j:=1 to High(ar) do
ar[j]:='-'+ar[j];
Result:=ar;
end;

#11 Re: mORMot 2 » How to parse command line parameters ? » 2024-07-25 10:31:27

I also noticed that when using c.Args[0]); an error is thrown (

#12 Re: mORMot 2 » How to parse command line parameters ? » 2024-07-25 08:11:35

Okay I will explain why this is needed. There is a python4delphi library. I need to run the .py script through it, passing it launch parameters:

PythonEngine.PySys_SetArgv(ArgvCount, Argv);
PythonEngine.ExecFile(mypathtofile);

And here the launch parameters must be in an array and you also need to specify the length of the array

upd:
Thanks I tested the new method, it parses slightly incorrectly:

program Project2;

{$APPTYPE CONSOLE}

uses
  System.SysUtils, mormot.core.os, mormot.core.text;

var
c:TExecutableCommandLine;
begin
c:=TExecutableCommandLine.Create;
c.Clear;
c.RawParams := CsvToRawUtf8DynArray('-o file.txt --y -v -t 1', ' ');
c.Parse(#10, '-', '--');
Writeln(c.Values[0]);
c.Free;
Readln;
end.

I got the result "file.txt" but it probably should be "-o file.txt"

#13 Re: mORMot 2 » How to parse command line parameters ? » 2024-07-25 07:29:17

ab wrote:

You can parse your command line with it.

No, I need to parse it so that each parameter is in an array

Example:

params:string:='-o file.txt --y -v -t 1';

after parse

array[0]= -o file.txt
array[1]= --y
array[2]= -v
array[3]= -t 1

And I don’t really know how to do this sad

#14 Re: mORMot 2 » How to parse command line parameters ? » 2024-07-25 07:04:27

No, firstly, I still don’t understand how to use it, and secondly, it doesn’t seem to suit my task

#15 mORMot 2 » How to parse command line parameters ? » 2024-07-25 04:56:37

Uefi
Replies: 17

Hello, can I use mORMot or something else to parse command line elements from a string, like string into an array ?

var
arg:Tarray<string>;
params:string
begin
params:='-o file.txt --y -v -t 1';
//parsing here
end;

Each element must be in an array

#16 Re: mORMot 2 » Is it possible to make https requests through mORMot ? » 2024-06-27 16:39:35

ab wrote:

Sadly, only HTTP (or HTTPS) proxies are supported yet.

Hello, should you submit a proxy directly :

h.Proxy:='0.0.0.0:8080'; // ?

I would also put KeepAlive, Header, Data, DataMimeType into separate entries since this is more convenient than:
http.Request(URL, 'GET', '', '', '', 100);

And it would be:
http.KeepAlive:=100;
http.Header.Add('Content-Type: text/html; charset=utf-8'); // Better here TStringlist
http.Data:='';
http.DataMimeType:='application/json';

Please reconsider this as I have found that http requests in mORMot are fast, much faster than Synapse!

#17 Re: mORMot 2 » Is it possible to make https requests through mORMot ? » 2024-06-26 21:41:25

Thanks a lot, but for example I need to use my own user agent and proxy ?

I figured it all out, but I didn’t understand one thing: does it automatically determine the type of proxy HTTP, SOCKS4, SOCKS5 ?

procedure TForm2.Button1Click(Sender: TObject);
var
H:TSimpleHttpClient;
begin
H:=TSimpleHttpClient.Create(False);
h.UserAgent:='.....................';
h.Proxy:=????;
h.Request('https://', 'GET');
Memo1.Lines.Add(h.Body);
h.Free;
end;

#18 mORMot 2 » Is it possible to make https requests through mORMot ? » 2024-06-26 18:03:02

Uefi
Replies: 10

Hello, I don’t understand how to make https requests via mORMot to get the source code of the page, can you please tell me an example of the code and which library to include?

#19 Re: mORMot 2 » Cryptocurrency in mORMot ? » 2024-05-28 11:58:55

ab wrote:

For sure, cryptocurencies are such a huge matter, with so many branches and algorithms, it is a whole another project...

But of course, since mORMot cryptography is now stable, well supported and efficient, making a cryptocurrency library in top of it could make sense.
No plan for it from my personal point of view. But if someone starts this work, I would be pleased to help, if some crypto primitive is missing or a bug is identified.

Yes, indeed, I myself noticed that sha256-sha512 works perfectly and quickly in the mORMot library !

#20 mORMot 2 » Cryptocurrency in mORMot ? » 2024-05-28 01:21:35

Uefi
Replies: 3

Hello, is it possible to add some convenient functions to the mORMot library for working with cryptocurrency, for example, converting private keys to wallet addresses ?

Example:

privatekey: 0000000000000000000000000000000000000000000000000000000000000001

ethereum wallet:0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf
bitcoin wallet1: 1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH
bitcoin wallet2: 3JvL6Ymt8MVWiCNHC7oWU6nLeHNJKLZGLN
bitcoin wallet3: bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4
bitcoin wallet4: 1EHNa6Q4Jz2uvNExL497mE43ikXhwF6kZm

It would be very cool if you implemented this, otherwise there are huge difficulties with this in Delphi, I think a lot of people would thank you

#21 Re: mORMot 2 » SynBloomFilter doesn't work correctly » 2024-05-11 18:49:56

ab wrote:

Just stop trying to use a Bloom filter when you don't need one!

Use MD5 + a single hash bit buffer and GetBitPtr() + SetBitPtr().

Hello, I forgot to answer, I think I did as you advised and now the results are normal:

function MyHasher(crc: cardinal; buf: PAnsiChar; len: cardinal): cardinal;
var
Hasher:Thasher;
begin
Hasher:=cryptCrc32(caMd5);
SetBitPtr(buf, 2);
Result:=Hasher(crc, buf, len);
end;

Now there are about 12-15 duplicates in file displacement seems to help a lot, I would like to somehow transfer SynBloomFilter to 64-bit hashes; in theory, there will be even fewer collisions

#22 Re: mORMot 2 » SynBloomFilter doesn't work correctly » 2024-04-26 12:18:44

ab wrote:

Just stop trying to use a Bloom filter when you don't need one!

Use MD5 + a single hash bit buffer and GetBitPtr() + SetBitPtr().

If it's not too difficult, could you write an example in Delphi smile?

#23 Re: mORMot 2 » SynBloomFilter doesn't work correctly » 2024-04-26 11:34:01

ab wrote:

You have all the cryptographic hashes you need in mormot.crypt.core.pas.

Hello, here are the test results for the standard TSynBloomFilter hashing and our own:

Hashing out of the box:

BloomFilter:=TSynBloomFilter.Create(100000000,0.00001);

FluxBB bbcode test

Hashing with your own function:

function MyHasher(crc: cardinal; buf: PAnsiChar; len: cardinal): cardinal;
begin
Result:=BobJenkinsHash(buf[0], len, MurMurHash3(buf[0], len, crc xor len));
end;

BloomFilter:=TSynBloomFilter.Create(100000000,0.00001, MyHasher);

FluxBB bbcode test

As you can see, standard hashing is much worse, both tests were carried out on the same file without duplicates

#24 Re: mORMot 2 » SynBloomFilter doesn't work correctly » 2024-04-24 04:29:32

ab wrote:

You have all the cryptographic hashes you need in mormot.crypt.core.pas.

Is it even possible to make a BloomFilter without false positives?

#25 Re: mORMot 2 » SynBloomFilter doesn't work correctly » 2024-04-23 10:36:40

ab wrote:

You just don't read or understand what I wrote.

I did not say that your results were wrong.
I said that your assumptions are wrong, about how hash reduction, e.g. in bloom filters, works.
TSynBloomFilter works correctly for a Bloom Filter. You just misuse it, and have misconceptions about this algorithm, and hashes or cryptography in general.

Okay, here the debate can actually drag on for a long time, I would like to try something like SHA256, SHA512 So I can do it like this:

uses
HlpHashFactory // module HashLib4Pascal

function MyHasher(crc: cardinal; buf: PAnsiChar; len: cardinal): cardinal;
begin
Result:=THashFactory.TCrypto.CreateSHA3_256.ComputeUntyped(buf, len).GetInt32;
end;

BloomFilter:=TSynBloomFilter.Create(100000000,0.00001, MyHasher);

Can I do something similar using just mORMot? Because HashLib4Pascal hashes very slowly

#26 Re: mORMot 2 » SynBloomFilter doesn't work correctly » 2024-04-23 10:14:10

ab wrote:

You are thinking the wrong way around.

In fact, for some reason not, please check for yourself if you don't trust me smile

#27 Re: mORMot 2 » SynBloomFilter doesn't work correctly » 2024-04-23 10:08:49

Even any one hash from the MOrmot set is significantly inferior to BobJenkinsHash or xxHash32 please check this, is there any hashing error ?
I really don’t understand why, in fact, cryptographic hashes are suddenly inferior to the old non-cryptographic hashes ?

#28 Re: mORMot 2 » SynBloomFilter doesn't work correctly » 2024-04-23 09:46:40

Thank you, I already realized that these hash functions already imply cryptographic strength. I tested BobJenkinsHash, MurmurHash3 and xxHash32 with a standard set of mORMot caMd5, caSha1, caCrc32 and others, in fact for some reason they lose a lot with them by an order of magnitude more collisions  sad

For example with hybrid BobJenkinsHash and xxHash32 only 15 collisions, and with hybrid caMd5 and caSha1 539 collisions of course with the same settings TsynBloomFilter and the same file

function MyHasher(crc: cardinal; buf: PAnsiChar; len: cardinal): cardinal;
begin
Result:=BobJenkinsHash(buf[0], len, xxHash32(buf[0], len, crc)); // Spring4D module
end;

function MyHasher(crc: cardinal; buf: PAnsiChar; len: cardinal): cardinal;
var
H1,H2: Thasher;
begin
H1:=CryptCrc32(caMd5);
H2:=CryptCrc32(caSha1);
Result:=H1(h2(crc, buf, len), buf, len);
end;

BloomFilter:=TSynBloomFilter.Create(100000000,0.00001, MyHasher);

#29 Re: mORMot 2 » SynBloomFilter doesn't work correctly » 2024-04-23 07:57:01

Thank you very much for your great desire to help, what I don’t understand is how to use sha256 or sha512 for TSynBloomFilter for the newest version mORMot2 )?

#30 Re: mORMot 2 » SynBloomFilter doesn't work correctly » 2024-04-23 04:25:30

TPrami wrote:
Uefi wrote:

Can you please tell me how I can achieve 0% collisions without taking up too much RAM?

Why are you so worried about RAM?

Most computers have gigabytes of free RAM, and it is pretty cheap to get more. Your mileage might vary, it all depends on everything for sure.

-Tee-

Because the files that I process are very large 32-100 gigabytes, now imagine how much RAM the same THashSet will steal ?
By smaller standards, THashSet steals three times more RAM than the file itself 32*3 or 100*3 = 100-300 gigabytes RAM

#31 Re: mORMot 2 » SynBloomFilter doesn't work correctly » 2024-04-22 20:32:16

ab wrote:

For a true collision-less algorithm, I would use a binary tree of SHA-256 hashes.
That is: collision-less hash and perfectly balanced efficient storage of the hashes.

Or perhaps a Merkle Tree if you want to store the content.
https://en.wikipedia.org/wiki/Merkle_tree
https://www.codementor.io/blog/merkle-trees-5h9arzd3n8

I have just started to understand the new BloomFilter arsenal and I still don’t understand how to specify sha256 , sha512 in it smile

BloomFilter:=TSynBloomFilter.Create(100000000,0.00001, SHA3_512)); // NOT )

Tell me how I can find Merkle Tree in mORMot lib ?

#32 Re: mORMot 2 » SynBloomFilter doesn't work correctly » 2024-04-22 19:05:53

Can you please tell me how I can achieve 0% collisions without taking up too much RAM?

#33 Re: mORMot 2 » SynBloomFilter doesn't work correctly » 2024-04-22 08:01:51

Hello, I’m very glad that you are also interested in this question,
It seems that I was able to achieve almost 0% collisions with the hybrid use of hashes:

function crc32c(crc: cardinal; buf: PAnsiChar; len: cardinal): cardinal;
begin
Result:=BobJenkinsHash(buf[1], len, xxHash32(buf[1], len, crc)); // Spring4D module
end;

In mormot.core.search.pas:

uses
  classes,
  sysutils,
  mormot.core.base,
  mormot.core.os,
  mormot.core.rtti,
  mormot.core.unicode,
  mormot.core.text,
  mormot.core.buffers,
  mormot.core.datetime,
  mormot.core.data,
  mormot.core.json,
  System.Generics.Defaults, // Add this
  Spring.Hash; // And This (Spring4D Module)

.......

{ ****************** Bloom Filter Probabilistic Index }

{ TSynBloomFilter }


function crc32c(crc: cardinal; buf: PAnsiChar; len: cardinal): cardinal;
begin
Result:=BobJenkinsHash(buf[1], len, xxHash32(buf[1], len, crc)); // Spring4D module
end;

const
  BLOOM_VERSION = 0;
  BLOOM_MAXHASH = 32; // only 7 is needed for 1% false positive ratio

And I create TSynBloomFilter like this:

BloomFilter:=TSynBloomFilter.Create(100000000,0.000001); // If you put less 0.000001 then there will be collisions Seems 0.000001 this is the limit =(

Please check this as well and report the results !

#34 Re: mORMot 2 » SynBloomFilter doesn't work correctly » 2024-04-21 19:37:02

ab wrote:

If you have 1% of lines which are notified, it is just as expected with the default aFalsePositivePercent=1 value.

https://en.wikipedia.org/wiki/Bloom_filter
https://en.wikipedia.org/wiki/False_pos … _negatives

I achieved an order of magnitude fewer collisions by adding my crc32c function:

function crc32c(crc: cardinal; buf: PAnsiChar; len: cardinal): cardinal;
begin
Result:=BobJenkinsHash(buf[1], len, crc);
end;

Please try to study and check this:

in mormot.core.search.pas:

interface

{$I ..\mormot.defines.inc}

uses
  classes,
  sysutils,
  System.Generics.Defaults, // Add This module
  mormot.core.base,
  mormot.core.os,
  mormot.core.rtti,
  mormot.core.unicode,
  mormot.core.text,
  mormot.core.buffers,
  mormot.core.datetime,
  mormot.core.data,
  mormot.core.json;

...

{ ****************** Bloom Filter Probabilistic Index }

{ TSynBloomFilter }

function crc32c(crc: cardinal; buf: PAnsiChar; len: cardinal): cardinal; // Add my function here
begin
Result:=BobJenkinsHash(buf[1], len, crc);
end;

const
  BLOOM_VERSION = 0;
  BLOOM_MAXHASH = 32; // only 7 is needed for 1% false positive ratio

Murmurhash3 also performed well:

in mormot.core.search.pas:

interface

{$I ..\mormot.defines.inc}

uses
  classes,
  sysutils,
  FastCompare, // Add This module
  mormot.core.base,
  mormot.core.os,
  mormot.core.rtti,
  mormot.core.unicode,
  mormot.core.text,
  mormot.core.buffers,
  mormot.core.datetime,
  mormot.core.data,
  mormot.core.json;

...

{ ****************** Bloom Filter Probabilistic Index }

{ TSynBloomFilter }

function crc32c(crc: cardinal; buf: PAnsiChar; len: cardinal): cardinal;
begin
Result:=MurMurHash3(buf[1], len, crc);
end;

const
  BLOOM_VERSION = 0;
  BLOOM_MAXHASH = 32; // only 7 is needed for 1% false positive ratio

With my function I now get as it should be 0 duplicates in the file with no duplicates !

#35 Re: mORMot 2 » SynBloomFilter doesn't work correctly » 2024-04-21 08:32:50

ab wrote:

Please define "it incorrectly identifies duplicate lines" and "results are very different".

Note that by design, Bloom filters will return false positives, i.e. false duplicates, in range of the BloomFilter.FalsePositivePercent property (as supplied to Create).

And use RawByteString instead of string types.

Hello, I mean that there is a very large number of collisions in a file that has no duplicates; it finds more than 1000 duplicates sad
Converting to the RawByteString type changes absolutely doesn't change anything

#36 mORMot 2 » SynBloomFilter doesn't work correctly » 2024-04-20 23:35:35

Uefi
Replies: 30

Hello, first of all I want to express my deep gratitude for your wonderful libraries mORMot and  mORMot2, I noticed that TSynBloomFilter in both libraries works somehow incorrectly, namely, it incorrectly identifies duplicate lines from large files over 600 megabytes.

So I have the following code:

program Project2;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils,
  System.Classes,
  System.Diagnostics,
  mormot.core.search, // or SynTable
  VCL.Dialogs;

procedure ReadFile(const fpath:string); inline;
var
  uniq,dup:integer;
  BloomFilter:TSynBloomFilter;
  Reader: TStreamReader;
  Line:string;
begin
dup:=0;
uniq:=0;
BloomFilter:=TSynBloomFilter.Create(5000000);
try
  Reader := TStreamReader.Create(fpath, TEncoding.Default, True, 2048);
  while not Reader.EndOfStream do begin
  Line:=Trim(Reader.ReadLine);
  if not BloomFilter.MayExist(Line) then begin
  BloomFilter.Insert(Line);
  inc(uniq);
  end else
  inc(dup);
  end;
  finally
  Reader.Close;
  FreeAndNil(Reader);
  FreeAndNil(BloomFilter);
  end;
writeln(Format('Duplicates:%d Uniq:%d',[dup, uniq]));
readln;
end;

var
op:Topendialog;
FF:string;
begin
op:=Topendialog.Create(nil);
if op.Execute then
FF:=op.FileName;
op.Free;
ReadFile(FF);
end.

Before I upload .txt files, I check them with other programs to remove duplicates and the results are very different,
Please check whether this is really a bug in the library itself or am I doing something wrong?

#37 Re: mORMot 1 » TSynBloomFilter skips duplicate rows » 2024-02-14 20:14:07

ab wrote:

Which version of Delphi are you using?
Which version of mORMot 1 do you use?
Did you try with mORMot 2?

Don't use s: string but RawUtF8.

The TTestCoreBase.BloomFilters regression tests work with no problem with SIZ = 2000000.

Hail, mORMot version 1, well look, I need, for example, from a file of 100 gigabytes in size to clear duplicate lines using TSynBloomFilter, I read the file line by line using TStreamReader I can do that ?
p.s Delphi XE2

#38 mORMot 1 » TSynBloomFilter skips duplicate rows » 2024-02-14 16:55:36

Uefi
Replies: 2

Hello, sometimes TSynBloomFilter still misses duplicate rows, this is especially noticeable when working with large amounts of data of several million rows, maybe I'm doing something wrong ?

uses
SynTable;

function GenerateRandomLetters(Length: Integer): string;
var
  i: Integer;
begin
Result := '';
for i := 1 to Length do
Result := Result + Chr(Ord('a') + Random(Ord('c') - Ord('a') + 1));
end;

procedure Duplicates;
var
BloomFilter:TSynBloomFilter;
I:integer;
s:string;
begin
BloomFilter:=TSynBloomFilter.Create(100000,0);
for i:=1 to 1000000 do begin
s:=GenerateRandomLetters(5);
if not BloomFilter.MayExist(s) then begin
BloomFilter.Insert(s);
Form2.Memo1.Lines.Add(s);
end;
end;
BloomFilter.Free;
end;

procedure TForm2.Button1Click(Sender: TObject);
begin
Randomize;
Duplicates;
end;

Board footer

Powered by FluxBB