januswel / base32 Goto Github PK
View Code? Open in Web Editor NEWBase32 encoder/decoder for hex string
Base32 encoder/decoder for hex string
Inserted this library in a new TypeScript/VueJS project, at first for base32 decoding, I spent 3 hours on understanding why my server rejected the data decoded from base32. Turns out this library is dropping some zeros.
The first issue I faced :
MZ2H7MN3ACFGINNTVS73V2Q6QSZGGD2GUMBBD34G67IGG4LL2FRQ====
decodes to :
0x66747fb1bb8a6435b3acbfbaea1e84b2630f46a30211ef86f7d063716bd163
There's a 00 char missing between bb and 8a
Now I investigated further :
import { encode as encode, decode as decode} from '@januswel/base32';
const start0 = '1234567890abcdef';
const encoded0 = encode(start0);
const decoded0 = decode(encoded0);
console.log(start0 == decoded0);
console.log(start0);
console.log(decoded0);
const start = '66747fb1bb008a6435b3acbfbaea1e84b2630f46a30211ef86f7d063716bd163';
const encoded = encode(start);
const decoded = decode(encoded);
console.log(start == decoded);
console.log(start);
console.log(decoded);
const start2 = '66747fb1bb8a6435b3acbfbaea1e84b2630f46a30211ef86f7d063716bd163';
const encoded2 = encode(start2);
const decoded2 = decode(encoded2);
console.log(start2 == decoded2);
console.log(start2);
console.log(decoded2);
Output
true
1234567890abcdef
1234567890abcdef
false
66747fb1bb008a6435b3acbfbaea1e84b2630f46a30211ef86f7d063716bd163
66747fb1bb8a6435b3acbfbaea1e84b2630f46a30211ef86f7d063716bd163
false
66747fb1bb8a6435b3acbfbaea1e84b2630f46a30211ef86f7d063716bd163
66747fb1bb8a6435b3acbfbaea1e84b2630f46a3211ef86f7d063716bd163
First example is OK as in the light test vectors in this repo.
The second example it drops 0x00, and the third one it drops half a byte (a single "hex" 0) and the output is not even "hex bytes consistent".
โ
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.