1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 06:17:35 +00:00

LibCrypto: Define *BigInteger::to_base to convert big integers to String

This commit is contained in:
Timothy Flynn 2023-01-13 11:40:04 -05:00 committed by Linus Groh
parent 0ddc2e1f50
commit 3ad1f250e7
5 changed files with 28 additions and 12 deletions

View file

@ -241,9 +241,10 @@ TEST_CASE(test_unsigned_bigint_base10_from_string)
TEST_CASE(test_unsigned_bigint_base10_to_string)
{
auto result = Crypto::UnsignedBigInteger {
auto bigint = Crypto::UnsignedBigInteger {
Vector<u32> { 3806301393, 954919431, 3879607298, 721 }
}.to_base_deprecated(10);
};
auto result = MUST(bigint.to_base(10));
EXPECT_EQ(result, "57195071295721390579057195715793");
}
@ -386,10 +387,10 @@ TEST_CASE(test_bigint_random_distribution)
"100000000000000000000000000000"_bigint); // 10**29
if (actual_result < "100000000000000000000"_bigint) { // 10**20
FAIL("Too small");
outln("The generated number {} is extremely small. This *can* happen by pure chance, but should happen only once in a billion times. So it's probably an error.", actual_result.to_base_deprecated(10));
outln("The generated number {} is extremely small. This *can* happen by pure chance, but should happen only once in a billion times. So it's probably an error.", MUST(actual_result.to_base(10)));
} else if ("99999999900000000000000000000"_bigint < actual_result) { // 10**29 - 10**20
FAIL("Too large");
outln("The generated number {} is extremely large. This *can* happen by pure chance, but should happen only once in a billion times. So it's probably an error.", actual_result.to_base_deprecated(10));
outln("The generated number {} is extremely large. This *can* happen by pure chance, but should happen only once in a billion times. So it's probably an error.", MUST(actual_result.to_base(10)));
}
}