def encode_text(text, bit7):
if bit7:
res = list()
while text:
d = list()
r = list()
for i in range(len(text[:8])):
b = '{0:07b}'.format(ord(text[i]))
if not i:
r.append(b)
else:
r.append(b[:-i])
d.append(b[-i:])
if '' in r:
r.remove('')
for i in range(len(r)):
try:
res.append(d[i] + r[i])
except:
res.append('{0:08b}'.format(int(r[i],2)))
text = text[8:]
return res