Skip to content

Conversation

@sahmad98
Copy link
Contributor

Added a function to convert BigInt string representation into Base64 magnitudes. It starts from back of string and checks for overflow if saved into a 64-bit variable, which means we have reached at a point in string which is a component in magnitude vector, push this component into the vector and then start over again from the current point in string to check for next component.

@sahmad98 sahmad98 force-pushed the function-to-convert-string-to-base-64 branch from 7b6df13 to 522f8d7 Compare May 19, 2018 07:50
Copy link
Owner

@faheel faheel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, but the logic you've used for conversion isn't right.


TEST_CASE("Conversion to Base64 magnitudes from String", "[Utility][Helper][Base64]") {
std::string num = "481482486096808911670147153572883801";
// Magnitude should be {11670147153572883801, 4814824860968089}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The magnitude is incorrect. It should be {5717256727323176281, 26101217871994095}, since

481482486096808911670147153572883801 = 5717256727323176281⋅(264)0 + 26101217871994095⋅(264)1

try {
std::string num_slice = num.substr(start_it, stop_it);
component = std::stoull(num_slice);
} catch (std::out_of_range& e) { //Using out_of_range to determine overflow
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic wouldn't work. What we want is to divide the number by the largest power of 264 that gives a non-zero quotient, push that in an array, use the remainder as the new number and repeat the process with decreasing powers until we reach 1 (0th power). Then return the reversed array.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering how can we divide a number even with 264, the dividend will anyway overflow if we are going to do these in the traditional way. So i am thinking it must all be done in strings rather than converting the numbers into integer chunks or something related.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we'll need to do string-based division first to convert to base 264. I'm working on removing as much code as possible while still having string division and remainder work. But it'll take some time as I'm busy with exams currently. In the meanwhile, if you have another suggestion, or would like to work on this then let me know.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, i will modify it to use string divisions instead.

@sahmad98 sahmad98 force-pushed the function-to-convert-string-to-base-64 branch 2 times, most recently from f5c8b64 to 783828f Compare May 21, 2018 17:01
@sahmad98 sahmad98 force-pushed the function-to-convert-string-to-base-64 branch from 783828f to 2bc7e68 Compare May 21, 2018 17:03
magnitude = convert_to_base_2_to_the_64(num_magnitude);
*/
magnitude = {0};
magnitude = convert_to_base_64(num_magnitude);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems we have a circular dependency here, because in order to get magnitudes we first need to create a BigInt from string and then get magnitudes by calling a function which returns a magnitude vector, in my case BigInt::to_base64. What are your thoughts on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants