惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Spread Privacy
Spread Privacy
S
Schneier on Security
G
GRAHAM CLULEY
AWS News Blog
AWS News Blog
Cisco Talos Blog
Cisco Talos Blog
The Hacker News
The Hacker News
T
The Exploit Database - CXSecurity.com
P
Proofpoint News Feed
L
LINUX DO - 热门话题
C
CXSECURITY Database RSS Feed - CXSecurity.com
Security Latest
Security Latest
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Google DeepMind News
Google DeepMind News
H
Hacker News: Front Page
PCI Perspectives
PCI Perspectives
T
Tenable Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
N
Netflix TechBlog - Medium
Application and Cybersecurity Blog
Application and Cybersecurity Blog
腾讯CDC
A
Arctic Wolf
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Project Zero
Project Zero
NISL@THU
NISL@THU
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
V
Vulnerabilities – Threatpost
Cyberwarzone
Cyberwarzone
I
Intezer
Apple Machine Learning Research
Apple Machine Learning Research
T
Threat Research - Cisco Blogs
爱范儿
爱范儿
Webroot Blog
Webroot Blog
Forbes - Security
Forbes - Security
The Cloudflare Blog
T
Tailwind CSS Blog
C
CERT Recently Published Vulnerability Notes
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
大猫的无限游戏
大猫的无限游戏
Microsoft Azure Blog
Microsoft Azure Blog
Know Your Adversary
Know Your Adversary
云风的 BLOG
云风的 BLOG
B
Blog
The Register - Security
The Register - Security
T
Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
V2EX - 技术
V2EX - 技术
P
Privacy & Cybersecurity Law Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org

博客园 - qufo

Golang 线程池 Docker 实现的 redis 主从 Golang 之 Qrcode 二维码 Golang 之 key-value LevelDB 无废话 Thrift 之 Hello World( PHP 版). [转] putty 使用密钥登陆 OpenSSH 一个视图引发的血案 破一个行业ERP的感想 Practical Ext JS Projects with Gears中关于Gears描述。 七七前一天,搞定 PHP5 + Oracle 8.1.7 去掉PowerDesigner 15 在 Visual Studio 2008里的不兼容。 回家 庆祝自己通过驾驶员考试 2008.08.08.一个有记住意义的时刻。 adverbux.com 明天路考 blank.security 距离2008年8月8日还有8天。 随时10个可用线程--自己涂鸦的“线程池”
Golang 之 Base62 编码
qufo · 2016-08-02 · via 博客园 - qufo

Base62 编码用62个可见字符来编码信息,也就是所谓的62进制,可用于缩短地址之类的。实现起来也很简单。当然,这个实现跟别人家的有可能不一样,反正自己能编能解就行。 

package main

import (
    "math"
    "strings"
)

const CODE62  = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
const CODE_LENTH = 62
var EDOC = map[string]int{"0":0,"1":1,"2":2,"3":3,"4":4,"5":5,"6":6,"7":7,"8":8,"9":9,"a":10,"b":11,"c":12,"d":13,"e":14,"f":15,"g":16,"h":17,"i":18,"j":19,"k":20,"l":21,"m":22,"n":23,"o":24,"p":25,"q":26,"r":27,"s":28,"t":29,"u":30,"v":31,"w":32,"x":33,"y":34,"z":35,"A":36,"B":37,"C":38,"D":39,"E":40,"F":41,"G":42,"H":43,"I":44,"J":45,"K":46,"L":47,"M":48,"N":49,"O":50,"P":51,"Q":52,"R":53,"S":54,"T":55,"U":56,"V":57,"W":58,"X":59,"Y":60,"Z":61, }

/**
 * 编码 整数 为 base62 字符串
 */
func Encode(number int) string {
    if number == 0 {
        return "0"
    }
    result := make([]byte , 0)
    for number > 0 {
        round  := number / CODE_LENTH
        remain := number % CODE_LENTH
        result = append(result,CODE62[remain])
        number  = round
    }
    return string(result)
}


/**
 * 解码字符串为整数
 */
func Decode(str string) int {
    str = strings.TrimSpace(str)
    var result int = 0
    for index,char := range []byte(str){
        result +=  EDOC[string(char)] * int(math.Pow(CODE_LENTH,float64(index)))
    }
    return result
}