简体   繁体   English

Base64 索引表

[英]Base64 index table

I am working on a Python program where I have a long binary string and want to convert it into the corresponding characters based on the base64 index table.我正在开发一个 Python 程序,其中有一个很长的二进制字符串,并希望根据 base64 索引表将其转换为相应的字符。

Is there any efficient way you can take '000000' and turn it into 'A' , '000001' for 'B' , etc?有什么有效的方法可以将'000000'转换为'A''000001''B'等吗? I've tried looking up at the base64 library but can't seem to find a way.我试过查找 base64 库,但似乎找不到方法。 I suppose I could just make a dictionary of the corresponding values but just wanted to see if there was a more elegant way.我想我可以制作一个相应值的字典,但只是想看看是否有更优雅的方式。

In base 64 to represent 5 zeros you'd need to apply it in the following way: AAAAA If it is a repetitive striing - meaning the same one / not a user input or dynamic of sorts then better use a simple string=0000;在基数 64 中表示 5 个零,您需要按以下方式应用它: AAAAA 如果它是重复的字符串 - 意味着相同的 / 不是用户输入或各种动态,那么最好使用简单的 string=0000; print(string) Note that it is case sensitive - in Python you can just use this or something similar: print(string) 请注意,它区分大小写 - 在 Python 中,您可以使用它或类似的东西:

from base64 import b64encode, b64decode
#hexideximal to base64 in python
h = '00000'
b64 = b64encode(bytes.fromhex(h)).decode()
print(b64)

I think should work fine this way - :) update i just reread that you are trying to decode binary to base64 it works all the same - just alter the the code slightly to something like so :我认为这样应该可以正常工作 - :) 更新我刚刚重读你正在尝试将二进制解码为 base64 它的工作原理都是一样的 - 只需将代码稍微更改为如下所示:

import base64   

 base64.b64decode(ooooo) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM