【发布时间】:2015-05-23 05:29:24
【问题描述】:
我开始在 Python 中研究 Vernam 密码,显然我不知道在 Python 中使用二进制文件,例如,如果我在控制台中 print 00011 它返回 9。
"""Sistema de Cifrado Vernam"""
#alfabeto
alfabeto = {"a":00011,"b":11001,"c":01110,"d":01001,"e":00001,"f":01101,"g":11010,"h":10100,"i":00110,"j":01011,"k":01111,"l":10010,"m":11100,
"n":01100,"o":11000,"q":10111,"r":01010,"s":00101,"t":10000,"u":00111,"v":11110,"w":10011,"x":11101,"y":10101,"z":10001,
"<":01000,"=":00010,"fdown":11111,"fup":11011," ":00100, "":00000}
"""Mensaje en texto plano"""
#Susituir por input
mensaje = "stack"
m = []
for e in mensaje:
m.append(alfabeto[e])
print m
输出
[65, 10000, 9, 584, 585]
我想打印 ASCII 版本的实际二进制数。
【问题讨论】:
-
在python2中,以0开头的int被理解为base 8(八进制)。因此
011变为十进制(以 10 为底)9
标签: python python-2.7 binary