sha256 to bigint
Paul Backus
snarwin at gmail.com
Sat Jun 11 16:15:48 UTC 2022
On Saturday, 11 June 2022 at 13:09:44 UTC, vc wrote:
>
> Hello, is there any way to represnts a sha256 hash like
> 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824 in BigInt ?
>
> I've try so far auto t =
> BigInt("2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824") and it gives me invalid digit
Just so you know, you can construct a `BigInt` directly from the
raw bytes of a sha256 hash, without converting to a string first:
```d
import std.digest.sha, std.bigint;
ubyte[32] hash = sha256Of(whatever);
auto t = BigInt(false, hash[]); // sign + magnitude
```
Docs: https://phobos.dpldocs.info/std.bigint.BigInt.this.3.html
More information about the Digitalmars-d-learn
mailing list