agnoster / base32-js Goto Github PK
View Code? Open in Web Editor NEWBase32 encoding for JavaScript, based (loosely) on Crockford's Base32
Home Page: https://github.com/agnoster/base32-js
License: MIT License
Base32 encoding for JavaScript, based (loosely) on Crockford's Base32
Home Page: https://github.com/agnoster/base32-js
License: MIT License
Dear Author,
Thanks for your great work! But I need to use it for decoding and use C for encoding... Do you know if there is a C lib which is compatible with this base32 encoder/decoder?
Is var
missing on purpose ? https://github.com/agnoster/base32-js/blob/master/lib/base32.js#L234
If I base32 encode this string my name is hereslkdjfaklsjdfa234234@#$!!@35465*()&(*^*&^*&%&^%///劳动力
. I get dnwj0vk1dnjj0ubk41m6awk5edp6pt3actgppv3kd9j6cr9j6cu34ctm80hj889180tkad1p6mn2ga9650n5wah6brn2c996brjjybtfpundefinedmundefinedp
. Notice undefined
in string output.
Python outputs, NV4SA3TBNVSSA2LTEBUGK4TFONWGWZDKMZQWW3DTNJSGMYJSGM2DEMZUIARSIIJBIAZTKNBWGUVCQKJGFAVF4KRGLYVCMJJGLYSS6LZP4WFLHZMKVDSYVGY=
I would expect this to match the python output or throw an error.
Is there a strong reason not to use probably most authentic RFC 4648 ( http://tools.ietf.org/html/rfc4648 ) base32 characters? (i.e. alphabet = "abcdefghijklmnopqrstuvwxyz234567")? It took me 2 hours debbuging when I was implementing some protocol requiring "base32" using this library...
This works fine for some strings, but for examples like these I get invalid results:
base32.encode("юзер@екзампл.ком.example.com");
output:
9rvundefinedag206mxundefinedecundefinedw7wxjweundefinedy7gq6ay31dnr6rt9ecdqp
input:
base32.decode(9rvundefinedag206mxundefinedecundefinedw7wxjweundefinedy7gq6ay31dnr6rt9ecdqpu");
results in:
N7ªµÏ\Õ@@5;ªµÏ\×3Uk¹¼?;.;Uk¹¾<.example.com
As you can see, it does not result in the original string when it is decoded. Not sure why.
Why it is returning different result compared to other base32 libs?
like base-x
or hi-base32
Hex: 17O57684bea1f9331418b633a8f373119d765fd4
It cannot be an "O" letter, it's a zero instead ;-)
Hex: 17057684bea1f9331418b633a8f373119d765fd4
I see optimist is defined as a runtime dependency on this library, but I don't see it used. Is it needed, or perhaps it's just an artifact of an old commit?
package.json
1.0.0
yet 5 years old+I believe your decoder's finish() function is wrong, but I don't know enough of the specifics of the function to pin down exactly why. Either way, you're referencing a variable (bits) that only exists in an Encoder, so there is at least one issue there. Just figured I'd mention it.
Dear Isaac,
current implementation supports Uint8Array
for input like this base32.encode(array)
, right?
Now I'm curious why both 32-byte (output: 52 chars) and 64-byte (output: 103 chars) arrays as well as relatively long routine UTF8 strings encoded with Base32 predictably ends with either 0
or g
.
Any thoughts?
Please : why did you use the U instead of S ?
The crockford alpahbeth is : 0123456789abcdefghjkmnpqrstvwxyz
The one you use is : 0123456789abcdefghjkmnpqrtuvwxyz
Not the S is not present in your alphabet and the U is present.
This is not the Crockford Base32 correct implementation :
source : https://en.wikipedia.org/wiki/Base32 and https://www.crockford.com/base32.html and all other package in all other language (ie Python for my backend....)
I've lost 4 hours to figure out what's happened ....
We use base32 in the browser with browserify. sha1 requires crypto which adds 5k+ lines to the bundle. Also, I don't think sha1 will work in the browser anyway...
In the fork I separated sha1 (milojs@9c7fe12), but I don't think it is a good solution, it will break code that uses it. Any better ideas?
...
Hi folks,
I noticed the following behaviour
> base32.decode(base32.encode("deadbeef111"))
< "d{adbe{f111"
which appers to be introduced by the alias
behaviour. I nulled the aliases
dictionnary to retablish the desired behaviour.
> base32.decode(base32.encode("deadbeef111"))
< "deadbeef111"
Just looking to trim my deps so I thought I'd ask. That one little dep pulls in 4 other deps.
Dear Isaac,
console.log(base32.decode(base32.encode("love")));
works as expected, it returns love
, hooray.
But let's step aside the anglosaxonian world and type something in Cyrillic. For example, equivalent of word love
is любовь
in Russian, yet console.log(base32.decode(base32.encode("любовь")));
returns garbled piece of text ?OªµÏ \Õ?Uk��¹²L
.
There are various intermediate solutions to this issue. I like the following two:
console.log(decodeURIComponent(escape(base32.decode(base32.encode(unescape(encodeURIComponent("любовь")))))));
returns любовь
console.log(UTF8.decode(base32.decode(base32.encode(UTF8.encode("любовь")))));
returns любовь
var UTF8 = {
encode: function(string) {
string = string.replace(/\r\n/g, "\n");
var utftext = "";
for (var n = 0; n < string.length; n++) {
var c = string.charCodeAt(n);
if (c < 128) {
utftext += String.fromCharCode(c);
} else if ((c > 127) && (c < 2048)) {
utftext += String.fromCharCode((c >> 6) | 192);
utftext += String.fromCharCode((c & 63) | 128);
} else {
utftext += String.fromCharCode((c >> 12) | 224);
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
utftext += String.fromCharCode((c & 63) | 128);
}
}
return utftext;
},
decode: function(utftext) {
var string = "",
i = 0,
c = 0,
c2 = 0;
while (i < utftext.length) {
c = utftext.charCodeAt(i);
if (c < 128) {
string += String.fromCharCode(c);
i++;
} else if ((c > 191) && (c < 224)) {
c2 = utftext.charCodeAt(i + 1);
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
i += 2;
} else {
c2 = utftext.charCodeAt(i + 1);
c3 = utftext.charCodeAt(i + 2);
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
i += 3;
}
}
return string;
}
};
Also, there's Encoding API.
const txtencoder = new TextEncoder;
message = "любовь";
txtencoder.encode(message); // returns UTF8 Uint8Array
Could you be so kind and make it working from the box without those additional helpers so users around the globe could enjoy your library without a hassle? Developer of Base91's implementation already did it.
Hey, any chance for a Bower package? It would be cool to use the same code in the browser and on nodejs.
Thanks!
Mike
var base32 = require("base32-crockford");
base32.encode('l’'); // OUTPUT "dundefinedcg"
Could you please update (or swap out because of deprecation notice) optimist?
| Id | Module | Title | Path | Sev. | Url |
|---|---|---|---|---|
| 1067342 | minimist | Prototype Pollution in minimist | optimist>minimist | critical | GHSA-xvch-5gv4-984h |
| 1070255 | minimist | Prototype Pollution in minimist | optimist>minimist | moderate | GHSA-vh95-rmgr-6w4m |
It will be great to add declaration file as @types/base32-js is not available.
I'm getting different results between implementations. I'm missing something. Other than the fact that this implementation is using crockford's limited character set why are these two base32 encodings wildly off?
var number = 14974;
number.toString(32); // -> eju
base32.encode(number.toString()); // -> 64u3jdtm
I noticed a typo at https://github.com/agnoster/base32-js/blob/master/lib/base32.js#L149 , it looks like you want to say "crypto" instead of "cryto".
Thanks for the great library!
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.