Giter Club home page Giter Club logo

wadelau / base62x Goto Github PK

View Code? Open in Web Editor NEW
50.0 3.0 13.0 2.41 MB

Base62x is an alternative approach to Base 64 without symbols in output. 无符号的Base64编码解码方案.

Home Page: https://ufqi.com/dev/base62x/

License: Apache License 2.0

C 10.07% PHP 31.27% Java 14.01% JavaScript 12.60% HTML 1.46% Perl 13.43% Python 13.96% Makefile 0.03% C++ 3.17%
base62 base64 urlencode urldecode base16 base32 base62x symbols php javascript c java

base62x's Introduction

Base62x: An alternative approach to Base64 for alphanumeric-only [a-zA-Z0-9] characters in output.

Base62x is an non-symbolic Base64 encoding scheme. It can be used safely in computer file systems, programming languages for data exchange, internet communication systems, etc, and it is an ideal substitute and successor of tradtional Base64 and many variants of Base64 encoding scheme.

Base62x 是一种无符号 [a-zA-Z0-9] 的Base64编码方案。

她可以在计算机文件系统、编程语言数据交换、互联网络通信系统等方面安全地使用,同时是传统算法和各种变种Base64编码方案的理想替代品、继任者。

Contents

Base62x Usage

Base62x Research Paper

-Base62x in C

-Base62x in C#

-Base62x in C++

-Base62x in Dart

-Base62x in -Java

-Base62x in -JavaScript

-Base62x in -Perl

-Base62x in -PHP

-Base62x in -Python

-Base62x

Base62x is an alternative approach to Base 64 without symbols in output.

base62x

Compact, purified and even shorter!

-Base62x .

-Base62x Online

-Base62x Usage

Base62x.encode(myString);

Base62x.decode(encodedString);

Base62x.encode(myString, inBase);

Base62x.decode(encodedString, outBase);

base62x-design

-Base62x Papers

IEEE Article Number, 6020065 ;

-R/F2SQ , page url in -URL4P .

-Base62x in RearchGate, -R/12Sb .

Reference & Citation

@article{Liu2011Base62x,
	title={Base62x: An alternative approach to Base64 for only-alphanumeric characters in output},
	author={Liu, Zhenxing and Liu, Lu and Hill, Richard and Zhan, Yongzhao},
	journal={2011 Eighth International Conference on Fuzzy Systems and Knowledge Discovery (FSKD)},
	year={2011},
	url={https://ieeexplore.ieee.org/document/6020065/}
}

base62x.c

base62x.c

shell> gcc -lm base62x.c -o base62x

shell>./base62x

Usage: ./base62x [-v] [-n <2|8|10|16|32>] <-enc|dec> string

Version: 0.90

shell> mi=0; umi=0; for i in {1..10000}; \
	do \
	r=`cat /dev/urandom|tr -dc 'a-zA-Z0-9'|fold -w 16|head -n 1`; \
	r2=`cat /dev/urandom|tr -dc 'a-zA-Z0-9'|fold -w 16|head -n 1`; \
	a="$r中文时间a$r2"; b=`./base62x -enc $a`; c=`./base62x -dec $b`; \
	if [ "$a" == "$c" ]; then d="matched";mi=`expr $mi + 1`;\
	else d="unmatched"; umi=`expr $umi + 1`; fi;\
	echo -e "a=$a b="$b" c="$c" d="$d" mi="$mi" umi="$umi"\n"; \
	done

Base62x in -PHP

base62x.class.php

base62x_test.php

In base62x_test.php

<?php

include("./base62x.class.php");

$s = "abcd1234";
$s2 = "abc中文123";
$s3 = "\"Tcler's Wiki: UTF-8 bit by bit (Revision 6)\". 2009-04-25. Retrieved 2009-05-22."
	."In orthodox UTF-8, a NUL byte (\\x00) is represented by a NUL byte. […] But […] we "
	."[…] want NUL bytes inside […] strings […] | ① ② ③ ④ ⑤ ⑥ ⑦ |  Ⅰ Ⅱ Ⅲ Ⅳ Ⅴ Ⅵ Ⅶ Ⅷ Ⅸ Ⅹ | "
	."!  # $ % & ' ( ) * + , - . /";

print "[$s] encoded:[".($s_enc=Base62x::encode($s))."]\n";
print "[$s_enc] decoded:[".($s_dec=Base62x::decode($s_enc))."]\n";

print "\n[$s2] encoded:[".($s2_enc=Base62x::encode($s2))."]\n";
print "[$s2_enc] decoded:[".($s2_dec=Base62x::decode($s2_enc))."]\n";

print "\n[$s3] encoded:[".($s3_enc=Base62x::encode($s3))."]\n";
print "[$s3_enc] decoded:[".($s3_dec=Base62x::decode($s3_enc))."]\n";

?>

Another recommended Base62x PHP Library:

https://github.com/mauriziofonte/php-base62x

Base62x in -Java

Base62x.class.jsp

base62x_test.jsp

In base62x_test.jsp

<%@page 
	import="java.util.Date,
		java.util.HashMap,
		java.util.Map,
		java.util.Iterator"
	language="java" 
	pageEncoding="UTF-8"%><%

//- system
System.setProperty("sun.jnu.encoding", "UTF-8");
System.setProperty("file.encoding", "UTF-8"); //- set " -Dfile.encoding=utf8 " in jvm start script

//- request
request.setCharacterEncoding("UTF-8");

//- response
response.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");

%><%@include file="./Base62x.class.jsp"%><%

//- Test and examples of Base62x
//- Sun Aug 14 14:09:45 CST 2016
//- [email protected]

String s = "abcd1234";
String s2 = "abc中文123";
String s3 = "\"Tcler's Wiki: UTF-8 bit by bit (Revision 6)\". 2009-04-25. Retrieved 2009-05-22."
	+ "In orthodox UTF-8, a NUL byte (\\x00)"
	+ "is represented by a NUL byte. […] But […] we […] want NUL bytes inside […] strings […] "
	+ "| ① ② ③ ④ ⑤ ⑥ ⑦ "
	+ "| Ⅰ Ⅱ Ⅲ Ⅳ Ⅴ Ⅵ Ⅶ Ⅷ Ⅸ Ⅹ | ! # $ % & ' ( ) * + , - . /";

String s_enc, s_dec, s2_enc, s2_dec, s3_enc, s3_dec;

out.println("<br/>["+s+"] encoded:["+(s_enc=Base62x.encode(s))+"]");
out.println("<br/>["+s_enc+"] decoded:["+(s_dec=Base62x.decode(s_enc))+"]");

out.println("<br/>["+s2+"] encoded:["+(s2_enc=Base62x.encode(s2))+"]");
out.println("<br/>["+s2_enc+"] decoded:["+(s2_dec=Base62x.decode(s2_enc))+"]");

out.println("<br/>["+s3+"] encoded:["+(s3_enc=Base62x.encode(s3))+"]");
out.println("<br/>["+s3_enc+"] decoded:["+(s3_dec=Base62x.decode(s3_enc))+"]");

%>

It's an alternative option for -Base64 in -Java , JDK Doc .

Base62x in -JavaScript

Base62x.class.js

base62x_test.js.html

In base62x_test.js.html

var randi = Math.ceil(Math.random()*10000);
var s = randi+'abcd'+(randi*randi)+'1234@'+(randi%2==0?'中國-文化-源遠流長'
	+randi+':::':randi)+(new Date())+'@'+Math.ceil(Math.random()*100000);
var encs = Base62x.encode(s);
var decs = Base62x.decode(encs);

var inum = randi+'a'+1+randi+'fea'; var ibase = 16; var obase = 16;
var num_enc = Base62x.encode(inum, ibase);
var num_dec = Base62x.decode(num_enc, obase);

Play with npm,

npm install base62x

by https://github.com/beaulac/node-base62x

Base62x in -Perl

Base62x.pm

Usage: OOP Style

use Base62x;

my $base62x = Base62x->new();
my $str = “Hello World!\n”;
my $encoded = $base62x->encode($str);
$str = $base62x->decode($encoded);

# numbers conversion
my $i = 100;
    # treas $i as base 10 and transform it into Base62x
my $numInBase62x = $base62x->encode($i, 10);
    # try to decode a Base62x num into base 10
$i = $base62x->decode($numInBase62x, 10);

Usage: Functional Style

use Base62x qw (base62x_encode base62x_decode);

my $str = “Hello World!\n”;
my $encoded = base62x_encode($str);
$str = base62x_decode($encoded);

Base62x in -Python

Base62x.py

Usage: OOP style

# import Base62x.py
from Base62x import Base62x

# initialize
base62x = Base62x();

rawstr =abcd1234xefg89;01”;
encstr = base62x.encode(rawstr);
decstr = base62x.decode(encstr);

Base62x_test.py

Test cases for Base62x in Python.

One more Base62x in Python:

https://www.freesuch.com/read/admin/works/程序员笔记/base62x的实现.rtf

Base62x in -cplusplus / C++

base62x_test.cpp

Test scripts.

Base62x.class.hpp

Main class for the conversion.

Base62x in -csharp / C#

@todo

Base62x in -Dart

dart-base62x

https://pub.dev/packages/base62x

https://gitee.com/yf-frontend/dart-base62x/tree/main

base62x's People

Contributors

solomonxie avatar wadelau avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

base62x's Issues

License

There is no license in this repo, so effectively all code is proprietary and we can't use it for anything...

Links of "papers" are not available

Just found in the README that these links are not available anymore:

[ -R/p2SK ](http://ufqi.com/naturedns/search?q=-r/C2TZ) , page url in [ -URL4P ](http://ufqi.com/naturedns/search?q=-url4p) .

[-Base62x in RearchGate, -R/12Sb ](http://ufqi.com/naturedns/search?q=-R/12Sb ) .

You might want to reference these to stable links instead of searching result.

Extra long numbers conversion failed due to error in math function in PHP

<?php
$num = 362967911866744841;
print "$num / 60 = ".($dvd=sprintf('%.20F', $num/60))."\n";
print "$dvd * 60 = ".($num2=sprintf('%.20F', $dvd=$dvd*60))."\n";
print "num2 - num = ".($num3 = sprintf('%.20F', ($num2-$num)))."\n";
?>

Output:
362967911866744841 / 60 = 6049465197779081.00000000000000000000
6049465197779081.00000000000000000000 * 60 = 362967911866744832.00000000000000000000
num2 - num = 0.00000000000000000000

The error is that 362967911866744841 / 60 should be 6049465197779080.6833333333333333.
And also, 6049465197779081.00000000000000000000 * 60 is not equal to 362967911866744841 .

Due to this error, 362967911866744841 in Base 10 would be a1122334ef in Base 60, and K9XMIBhi09 in Base62x, but it will failed to reverse back from Base62x to Base 60 (a1122334ff).

Be careful in precision when dealing with extra long numbers!

Need help: add Base62x to Base64 in Wikipedia.org

Hi guys,
I need help by editing a few of sentences on Base62x in Wikipedia.org.
It would be an appendage to the page of Base64 in Wikipedia.org or a newly-created item on it.

I am trying to do so to help more developers know the better approach we have built to the traditional Base64.
The attempt had been made myself but failed due to that I am one of the authors of Base62x.

Could you please help on this addition of Base62x to Wikipedia?

Thanks in advance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.