digitalmars.D.learn - sha256 to bigint
- vc (5/5) Jun 11 2022 Hello, is there any way to represnts a sha256 hash like
- vc (3/7) Jun 11 2022 Ok i think is solved using "0x" infront, auto t = BigInt("0x"
- Paul Backus (9/13) Jun 11 2022 Just so you know, you can construct a `BigInt` directly from the
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
Jun 11 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 digitOk i think is solved using "0x" infront, auto t = BigInt("0x" ~"2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824")
Jun 11 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 digitJust 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
Jun 11 2022