Thread overview
sha256 to bigint
Jun 11, 2022
vc
Jun 11, 2022
vc
Jun 11, 2022
Paul Backus
June 11, 2022

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

June 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 digit

Ok i think is solved using "0x" infront, auto t = BigInt("0x" ~"2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824")

June 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 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:

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