长话短说,我正在编写一个程序来解码隐藏在音频文件中的消息,我遇到了一个问题,我需要在数组或字符串中存储“提取的”ASCII字母才能打印完整的信息。我目前的代码只给了我“消息”中的最后一个字母。
def decode(sound):
for sample in getSamples (sound):
ampValue = getSampleValue (sample)
asciiNum = ampValue % 128
if asciiNum == 0:
break
asciiLet = chr (asciiNum)
showInformation (asciiLet)
如何让我的代码显示隐藏在屏蔽音频中的所有字母?此外,我必须在不导入任何模块的情况下执行此操作。
答案 0 :(得分:0)
youre getting the last letter because it always replaced the variable 'asciiLet' every loop. try to create an inital value then add it.
def decode(sound):
asciiLet = '' #<--- inital
for sample in getSamples (sound):
ampValue = getSampleValue (sample)
asciiNum = ampValue % 128
if asciiNum == 0:
break
asciiLet += chr (asciiNum) #<--- add it
showInformation (asciiLet)