Skip to content
This repository has been archived by the owner on Feb 2, 2022. It is now read-only.

Base62 support #1

Closed
anitgandhi opened this issue Jun 29, 2017 · 1 comment
Closed

Base62 support #1

anitgandhi opened this issue Jun 29, 2017 · 1 comment
Assignees
Milestone

Comments

@anitgandhi
Copy link
Contributor

Description of Enhancement

Currently, this package only has support for inputs of base/radix 36, due to math/big MaxBase const being 36, as of June 29, 2017.

So, this package should have base62 support. This may involve the math/big package itself being updated, or a modified version of it must be used. See below.

In fact, because the math/big actually treats upper case and lower case alpha characters as the same, this actually causes a bug in this package. For example:

Encrypt Input: abc123def
Encrypt Output: flknlk32n

Encrypt Input: ABC123DEF
Encrypt Output: flknlk32n (same as before)

Decrypt input: flknlk32n
Decrypt output: abc123def

This is a collision of sorts.

Notes

Supporting base 62 properly in math/big directly is very easy. Here's a diff on math/big/natconv.go that shows it. Ideally, this change will be accepted by Golang maintainers.

< // This file was has minor configurations compared to
< // the standard library's math/big package in order
< // to support base 62 conversions rather than base 36
<
21c17
< const digits = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
---
> const digits = "0123456789abcdefghijklmnopqrstuvwxyz"
27c23
< const MaxBase = len(digits)
---
> const MaxBase = 'z' - 'a' + 10 + 1
179c175
< 			d1 = Word(ch - 'A' + 10 + 26)
---
> 			d1 = Word(ch - 'A' + 10)
181c177
< 			d1 = Word(MaxBase + 1)
---
> 			d1 = MaxBase + 1

While maintaining a customized version of math/big as a subpackage of fpe is not difficult, it's arguably not the best path forward.

@anitgandhi
Copy link
Contributor Author

The Go team has added base62 support to the math/big library via golang/go@51cfe68

It should be available in Go 1.10.

As such, if you want base62 support with this library, please wait until Go 1.10 is released 😄

tl;dr on how to use base62 support is to set your radix to something between 36 and 62, with the understanding that the alphabet it follows is now 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ

vdparikhrh referenced this issue in vdparikhrh/fpe Dec 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant