base编码是Binary-to-text encoding的一种实现方法,它可以把二进制数据(含不可打印的字符)编码成可打印字符序列。

本文会不定时收录“base全家桶”:base64、base32、base16、base58、base91、base92、base36、base62、base85、base128等。

收录BaseHash(包含base36、base52、base56、base58、base62、base94)

------------------

0x01 base64

安装:python2.7自带

alphabet:

ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/

padding:

=

使用:

import base64
c=base64.b64encode('pcat.cc')
m=base64.b64decode(c)
print c,m

0x02 base32

安装:python2.7自带

alphabet:

ABCDEFGHIJKLMNOPQRSTUVWXYZ234567

padding:

=

使用:

import base64
c=base64.b32encode('pcat.cc')
m=base64.b32decode(c)
print c,m

0x03 base16

安装:python2.7自带

alphabet:

0123456789ABCDEF

使用:

import base64
c=base64.b16encode('pcat.cc')
m=base64.b16decode(c)
print c,m

注意:

当b16decode的参数含有小写字母时,需要传入第二个参数True

base64.b16decode('706361742e6363',True)

或者使用python2.7的.decode('hex')则无须考虑大小写。

'706361742e6363'.decode('hex')

0x04 base58

github项目:https://github.com/keis/base58

安装:

pip install base58

alphabet:

123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz

使用:

import base58
c=base58.b58encode('pcat.cc')
m=base58.b58decode(c)
print c,m

0x05 base91

网址:http://base91.sourceforge.net/

github项目:https://github.com/aberaud/base91-python

安装:

pip install base91

alphabet:

ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&()*+,./:;<=>?@[]^_`{|}~"

使用:

import base91
c=base91.encode('pcat.cc')
m=base91.decode(c)
print c,m

0x06 base92

github项目:https://github.com/thenoviceoof/base92

安装:

pip install base92

alphabet:

!#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_abcdefghijklmnopqrstuvwxyz{|}

a special denotation (an empty string):

~

使用:

import base92
c=base92.encode('pcat.cc')
m=base92.decode(c)
print c,m

注意:

encode,b92encode,base92_encode是一样的,
decode,b92decode,base92_decode是一样的。

0x07 base36

github项目:https://github.com/tonyseek/python-base36

安装:

pip install base36

alphabet:

0123456789abcdefghijklmnopqrstuvwxyz

使用:

import base36
c=base36.loads('pcat')
assert type(c)==int
m=base36.dumps(c)
print c,m

注意:

dumps函数接收的参数类型为int

0x08 base62

github项目:https://github.com/suminb/base62

安装:

pip install pybase62

alphabet:

0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz

使用:

import base62
m=base62.decode('pcat')
assert type(m)==int
c=base62.encode(m)
print c,m c=base62.encodebytes('pcat.cc')
m=base62.decodebytes(c)
print c,m

注意:

encode函数接收的参数类型为int

0x09 base85

base85种类:

  1. ASCII85 encoding. This is the default. 0x00000000 is compressed to z. Spaces are not compressed.
  2. Adobe ASCII85 encoding is same as previous except data is enclosed between <~ and ~> .
  3. ZeroMQ (Z85) encoding. NOTE! Even though specification says input length must be divisible by 4, this is not currently enforced. Spaces and zeroes are not compressed.
  4. Character set from RFC1924 which is an April fools joke. Spaces and zeroes are not compressed.

(1) github项目:https://github.com/tuupola/base85

安装:

请先安装PHP的Composer,再

composer require tuupola/base85

使用:

(下面代码分别对应上面4种类型)

<?php
require __DIR__ . '/vendor/autoload.php';
use Tuupola\Base85; $m='pcat.cc'; $ascii85 = new Base85([
"characters" => Base85::ASCII85,
"compress.spaces" => false, "compress.zeroes" => true
]);
print $ascii85->encode($m) . PHP_EOL; $adobe85 = new Base85([
"characters" => Base85::ASCII85,
"compress.spaces" => false, "compress.zeroes" => true,
"prefix" => "<~", "suffix" => "~>"
]);
print $adobe85->encode($m) . PHP_EOL; $z85 = new Base85([
"characters" => Base85::Z85,
"compress.spaces" => false, "compress.zeroes" => false
]);
print $z85->encode($m) . PHP_EOL; $rfc1924 = new Base85([
"characters" => Base85::RFC1924,
"compress.spaces" => false, "compress.zeroes" => false
]);
print $rfc1924->encode($m) . PHP_EOL;

(2) python3中base64模块自带

#!/usr/bin/env python3
import base64
c=base64.a85encode(b'pcat.cc')
m=base64.a85decode(c)
print(c,m) c=base64.b85encode(b'pcat.cc')
m=base64.b85decode(c)
print(c,m)

注意:

python3中的a85encode和b85encode分别对应上面4种类型的第1和第4种。

0x0a base128

github项目:https://github.com/rpuntaie/base128

安装:

git clone https://github.com/rpuntaie/base128
cd base128
python3 setup.py install

另外需要先安装bitarray(在windows里安装麻烦)

pip install bitarray

alphabet:

0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\xb5\xb6\xb7\xbc\xbd\xbe\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff

使用:

#!/usr/bin/env python3
import base128
b128=base128.base128(chars=None, chunksize=7)
c=list(b128.encode(b'pcat.cc'))
m=b''.join(b128.decode(c))
print(c,m)

注意:
chars至少128字节,如果为None,则使用base128.base128.defaultchars
chunksize必须是7的倍数,且小于128。

0x0b BaseHash

BaseHash is a small library for creating reversible obfuscated identifier hashes to a given base and length. The project is based on the GO library, PseudoCrypt by Kevin Burns. The library is extendible to use custom alphabets and other bases.

github项目:https://github.com/calve/python-basehash

安装:

pip install basehash

alphabet:

BASE36 = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
BASE52 = '0123456789BCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz'
BASE56 = '23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz'
BASE58 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
BASE62 = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
BASE94 = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~'

(跟前面所介绍的相比,base36的alphabet的小写字母变成大写,base62相同。)

使用:

from basehash import *
print base36().decode('PCAT')
print base52().decode('pc4t')
print base56().decode('pcat')
print base58().decode('pcat')
print base62().decode('pcat')
print base94().decode('pcat.cc')

base全家桶的安装使用方法的更多相关文章

  1. 从零开始系列之vue全家桶(3)安装使用vuex

    什么是vuex? vuex:Vue提供的状态管理工具,用于同一管理我们项目中各种数据的交互和重用,存储我们需要用到数据对象. 即data中属性同时有一个或几个组件同时使用,就是data中共用的属性. ...

  2. 从零开始系列之vue全家桶(1)安装前期准备nodejs+cnpm+webpack+vue-cli+vue-router

    写在前面: 什么是全家桶? 包含了vue-router(http://router.vuejs.org),vuex(http://vuex.vuejs.org), vue-resource(https ...

  3. Adobe cc2019全家桶(免破解直接安装版)

    图片来源:Adobe官网 此次整理了Adobe cc2019的全家桶,全部为免破解,直接安装即可使用版本,对一些小白来说,值得推荐. 下载方式:找到下面你需要的Adobe软件,公众号内回复对应的关键词 ...

  4. 2020版Adobe全家桶介绍及免费下载安装

    前言 Adobe公司创建于1982年,是世界领先的数字媒体和在线营销解决方案供应商.公司总部位于美国加利福尼亚州圣何塞.Adobe 的 客户包括世界各地的企业.知识工作者.创意人士和设计者.OEM合作 ...

  5. 使用react全家桶制作博客后台管理系统 网站PWA升级 移动端常见问题处理 循序渐进学.Net Core Web Api开发系列【4】:前端访问WebApi [Abp 源码分析]四、模块配置 [Abp 源码分析]三、依赖注入

    使用react全家桶制作博客后台管理系统   前面的话 笔者在做一个完整的博客上线项目,包括前台.后台.后端接口和服务器配置.本文将详细介绍使用react全家桶制作的博客后台管理系统 概述 该项目是基 ...

  6. 最全总结 | 聊聊 Python 数据处理全家桶(Sqlite篇)

    1. 前言 上篇文章 聊到 Python 处理 Mysql 数据库最常见的两种方式,本篇文章继续说另外一种比较常用的数据库:Sqlite Sqlite 是一种 嵌入式数据库,数据库就是一个文件,体积很 ...

  7. 手把手教你全家桶之React(二)

    前言 上一篇已经讲了一些react的基本配置,本遍接着讲热更新以及react+redux的配置与使用. 热更新 我们在实际开发时,都有用到热更新,在修改代码后,不用每次都重启服务,而是自动更新.并而不 ...

  8. 已配置好的vue全家桶项目router,vuex,api,axios,vue-ls,async/await,less下载即使用

    github 地址: https://github.com/liangfengbo/vue-cli-project 点击进入 vue-cli-project 已构建配置好的vuejs全家桶项目,统一管 ...

  9. 使用vue全家桶制作博客网站

    前面的话 笔者在做一个完整的博客上线项目,包括前台.后台.后端接口和服务器配置.本文将详细介绍使用vue全家桶制作的博客网站 概述 该项目是基于vue全家桶(vue.vue-router.vuex.v ...

随机推荐

  1. django post 403

    同一个地址GET方式可以正常访问 在POST 提交数据过程中报403错误, 原来是1.3版本settings.py 文件中 'django.middleware.csrf.CsrfViewMiddle ...

  2. 如何用Deepin-wine安装运行win32的程序

    创建容器 容器就是win32程序运行的环境,可以理解为一个极小的windows,在Linux下面实际对应一个文件目录,如QQ对应的容器目录是~/.deepinwine/Deepin-QQ. 创建容器最 ...

  3. sklearn中的弹性网函数 ElasticNet

    语法:  ElasticNet(self, alpha=1.0, l1_ratio=0.5, fit_intercept=True, normalize=False, precompute=False ...

  4. Ubuntu18.04修改主机名和网卡地址

    date: 2019-06-26 09:56:04 author :headsen chen notice :个人原创 1,Ubuntu18.04 设置固定IP: 2,Ubuntu 18.04 设置主 ...

  5. Hibernate 自动更新表出错 建表或添加列,提示标识符无效

    如Oracle 数据库下报错: create table db_meta_web.user (id varchar2(255 char) not null, account varchar2(255 ...

  6. shutter 安装和设置快捷键

    1. 打开系统设置 2. 打开 Keyboard 键盘设置 3. 添加成功的状态 4. 单击右侧 Disabled,然后快速按下 Ctrl+Alt+A 如下图 5. Ctrl+Alt+A 测试OK. ...

  7. 【已解决】HttpWebRequest的GetResponse或GetRequestStream偶尔超时 + 总结各种超时死掉的可能和相应的解决办法

    [问题] 用C#模拟网页登陆,其中去请求几个页面,会发起对应的http的请求request,其中keepAlive设置为true,提交请求后,然后会有对应的response: resp = (Http ...

  8. PYTHON指定国内PIP源

    一.LINUX: vi ~/.pip/pip.conf 输入内容: [global]index-url = http://pypi.douban.com/simple/[install]trusted ...

  9. MyBatis 的案例

    首先我们需要先下载jar包 其次我们书写具体的内容 Student  Class package entity; /* * 学生类 * */ public class Student { //学生编号 ...

  10. 學校 iPad 使用學校google帳號登入Google Drive 提示"裝置政策提醒"的解決方法

    因爲學校iPad 是給學生和老師使用,大多數是不需要設置鎖屏密碼的,然後 Gsuite 默認是開啓 “行動管理服務” 的策略為基本,就是需要設備設置鎖屏密碼以保障資料安全,不那麽容易被竊取. 然後就出 ...