-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Closed
Labels
FrozenDueToAgeNeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.Feedback is required from experts, contributors, and/or the community before a change can be made.ProposalProposal-Accepted
Milestone
Description
Introduction
In the process of developing fpe, I used math/big for it's useful big number equivalents of itoa and atoi with base/radix support. However, as of right now, math/big only supports a maximum base/radix of 36: https://github.com/golang/go/blob/master/src/math/big/natconv.go#L18-L24
I believe this can be expanded to allow at least base62 strings and possibly arbitrary alphabets and radices.
Proposal
I'm proposing two separate but related changes such that math/big can add support for:
- base62 strings. As of right now, interpreting a
big.Intas base62 and base36 strings usingText()andSetString()results in the same string. In the context of FPE, that's effectively a collision in my opinion. See Base62 support capitalone/fpe#1 for details including a small 4-line diff that introduces base62 support - Arbitrary alphabet and base support (Some context: Arbitrary alphabet and radix support capitalone/fpe#2) . This would allow users to define their own alphabets and use their own choice of base to use a subset of said alphabet. This would expand the current alphabet which is base36 (0-9, a-z) and MaxBase=36 even more.
I believe this may entail:- In
natconv.go, changedigitsandMaxBaseconsts to vars. - Addition of
SetDigitsand/orSetMaxBasefunction tomath/big
- In
Admittedly I don't know how many use cases there are for the 2nd point other than what I'm doing on fpe, however the flexibility of having arbitrary alphabets and bases could be useful in other cases.
Notes
CC: @griesemer
fmpwizard, qqiao and jakeburchamcznic
Metadata
Metadata
Assignees
Labels
FrozenDueToAgeNeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.Feedback is required from experts, contributors, and/or the community before a change can be made.ProposalProposal-Accepted