0
string h1;
StringSource ss ( 
    client.getPassword(),
    true,
    new HashFilter (sha256,
            new HexEncoder (new StringSink (h1)),
            false,
            secureParam / 8) // cut the formoal secureParam / 8 bytes
);
cout << endl;
cout << "h1: " << h1 << endl;

the output is: h1: 3551E136E4F167D1804B

In the above two pictures, h1 is the string form, I want to convert it into hex Integer, how can I do that?

H.M
  • 425
  • 2
  • 16
zhen liu
  • 13
  • 1
  • Actually your question is totally unrelated to crypto++ and to sha256, these tags are irrelevant. Your actual question is: _"How can I convert hexadecimal string representing a 80 bit number into an 80 bit integer?"_. For this you need an integer type that can contain more than 64 bits. There is no such thing in standard C. Read this: https://stackoverflow.com/questions/16088282/is-there-a-128-bit-integer-in-gcc. – Jabberwocky Mar 10 '23 at 09:09
  • Anyway, do you really need this 80 bit integer? What do you want to do with it? – Jabberwocky Mar 10 '23 at 09:13
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Mar 10 '23 at 19:07

1 Answers1

1

You should be able to use std::stoll or std::stoull to convert a hex string into a 64 bit integer.

https://en.cppreference.com/w/cpp/string/basic_string/stol

https://en.cppreference.com/w/cpp/string/basic_string/stoul


H1 is 80 bits. I missed that since I only took a quick look at the image.

You could split the string into two parts, then use std::stoull twice to convert the two strings into a structure with two 64 bit integers.

If your compiler supports something like __m128i or __m128d:

https://learn.microsoft.com/en-us/cpp/cpp/m128?source=recommendations&view=msvc-170

https://learn.microsoft.com/en-us/cpp/cpp/m128d?view=msvc-170

Despite the warning not to use the fields in the descriptions, you can use something like __m128i.u64[0] and __m128i.u64[1] for the two 64 bit integers. This is intended for use with XMM registers.

rcgldr
  • 27,407
  • 3
  • 36
  • 61