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

Base62 support #1

@anitgandhi

Description

@anitgandhi

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions