I want to write a small script in python which does byte stuffing/unstuffing, since I have no idea how to do any of it Im just going for stuffing first.
So, the goal is simple, there is a function with three inputs, something like this: ByteStuffing(flagbyte, escapebyte, frame)
and output with flag bytes in the beginning and end, and stuffed frame in between.
so lets say my flag byte is Z, escape byte is A and frame LEONARDO
ByteStuffing(Z,A,LEONARDO) = ZLEONAARDOZ
p.s. escape byte also escapes flag characters in frame, not just escape bytes itself.
unstuffing is just reverse function.
now, i am really not familiar with programming, just getting started so I am really not very creative when it comes to coding, that's why I want to start with this small 'projects', can anybody give me ideas how to get started with this problem?
p.s Python version 2.7.12
EDIT: from Keerthana Prabhakaran's answer i ended up with this.
def applyByteStuffing(flagbyte, escapebyte, payload):
flagbyte = ("Z")
escapebyte = ("A")
x = payload.replace (escapebyte, escapebyte*2)
y = x.replace (flagbyte, escapebyte+flagbyte)
print (flagbyte + y + flagbyte)
return;
if i try to test it like this:
def test():
assert applyByteStuffing("Z", "A", "TAZZA") == "ZTAAAZAZAAZ"
if __name__ == '__main__':
test()
I am getting assertion error. has anyone idea where my assertion error is happening?
just trying out trying out this:
applyByteStuffing("Z" , "A" , "TAZZA")
gives me the correct output: ZTAAAZAZAAZ