kvanttt / basencoding Goto Github PK
View Code? Open in Web Editor NEWLibrary for encoding of binary data into strings using base32, base85, base128 and other algorithms.
License: Apache License 2.0
Library for encoding of binary data into strings using base32, base85, base128 and other algorithms.
License: Apache License 2.0
See http://en.wikipedia.org/wiki/Ascii85 for information and samples.
See here for implementation: http://sourceforge.net/projects/base91/
I have a 169 bytes image. Lets encode it.
Just run it in the browser console (on https://kvanttt.github.io/BaseNcoding/):
let dataUrl = `data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAA+SURBVEhL7dIxCgAwCMVQ739pu/yh0JYgXfNWlSxWv9UhgwkDyAAygAygXEo/8k032dhkMGEAGUAGkAHQvQC3veR+Ql0lAQAAAABJRU5ErkJggg==`;
let base64 = dataUrl.slice("data:image/png;base64,".length);
let binaryString = atob(base64);
var alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
var baseN = new BaseN(alphabet, 64);
baseN.encodeString(binaryString);
wolQTkcNChoKAAAADUlIRFIAAAAgAAAAIAgCAAAAw7wYw63CowAAAAFzUkdCAMKuw44cw6kAAAAEZ0FNQQAAwrHCjwvDvGEFAAAACXBIWXMAAA7DgwAADsODAcOHb8KoZAAAAD5JREFUSEvDrcOSMQoAMAjDhVDDr39pwrvDvMKhw5DCliBdw7NWwpUsVsK/w5UhwoMJA8OIADLCgAzCoFxKP8OyTTfDmcOYZDBhABlABsKQAcOQwr0AwrfCvcOkfkJdJQEAAAAASUVORMKuQmDCgC
282
chars.
With "Base85" the length is 265
.
iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAA+SURBVEhL7dIxCgAwCMVQ739pu/yh0JYgXfNWlSxWv9UhgwkDyAAygAygXEo/8k032dhkMGEAGUAGkAHQvQC3veR+Ql0lAQAAAABJRU5ErkJggg==
228
chars. (Math.ceil(169*4/3+2)
, btoa(binaryString)
)
With "Base85" the length should be ~212
(169*5/4
).
Does it work as planned?
I find out something confusing between the system definition and the data in diagram.xlsx about the equation below.
Take a exmpale(as Base64):
a=64
k=4
b=2
n=24
// then, according to the equation, ratio should be
r=64^4 / 2^24 =1
Am i misunderstanding something?
@KvanTTT could you explain it? ๐
Anyway, really appreciate your awesome work.
There is a huuuge bug here:
For example, if you enter "ap\n" ("ap" and NEW LINE) here:
http://kvanttt.github.io/BaseNcoding/
using Base=4096 and MaxBitCount=12 it will encode into:
ู+
which decodes back into "az" instead of its original value "ap\n" ("ap" and NEW LINE).
This bug is not related to web site character encoding nor new line differences between OSs (\r, \n vs \r\n) but it is easily reproducable with unit tests.
I'm using this library as part of a project of mine, and I've found in some cases there would be a need to validate an encoded string, that is, make sure that all of the characters are valid and that the formatting is correct.
Would this be possible to add?
Hi, I am interested in your code and I'd like to be able to consume the library as a nuget package. Do you have any official nuget package feed that can provide me with the package?
Hello,
First of all, thanks for this nice Library, It has really been helpful.
I and my colleague @ron4fun found a bug in the encoding and decoding of certain values to Base32.
A test example is the Name "Ronald" without the quotes, verifying with other encoders gives "KJXW4YLMMQ======" but yours gives "KJXW4YLMMQ====" which is wrong.
I have fixed the issue in my Pascal Port but just decided to inform you about the bug.
I could provide a pull request if you want.
Regards.
All chars must be distinct
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.