我正在开设一个课程密码学项目。它需要获取一个MP4文件,并将其读入1KB的块中。我有一些代码可以做到这一点,或多或少。发表于下方。但是如何在不手动添加填充的情况下执行此操作?我怎样才能直接将其读入存储在MP4中的位?
import binascii
file = open("tagthis.mp4", "rb")
allbytes = []
while 1:
somebytes = file.read(1024)
if not somebytes:
break
chunk = ""
for byte in somebytes:
byte = bin(ord(byte))
byte = byte[2:len(byte)]
padding = "0" * (8 - len(byte))
chunk += padding + byte
allbytes.append(chunk)