www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - sha256 to bigint

reply vc <dandondendinmpum gmail.com> writes:
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
next sibling parent vc <dandondendinmpum gmail.com> writes:
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")
Jun 11 2022
prev sibling parent Paul Backus <snarwin gmail.com> writes:
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
Jun 11 2022