MCPcopy Index your code
hub / github.com/secdev/scapy / corrupt_bytes

Function corrupt_bytes

scapy/utils.py:1227–1239  ·  view source on GitHub ↗

Corrupt a given percentage (at least one byte) or number of bytes from a string

(data, p=0.01, n=None)

Source from the content-addressed store, hash-verified

1225
1226@conf.commands.register
1227def corrupt_bytes(data, p=0.01, n=None):
1228 # type: (str, float, Optional[int]) -> bytes
1229 """
1230 Corrupt a given percentage (at least one byte) or number of bytes
1231 from a string
1232 """
1233 s = array.array("B", bytes_encode(data))
1234 s_len = len(s)
1235 if n is None:
1236 n = max(1, int(s_len * p))
1237 for i in random.sample(range(s_len), n):
1238 s[i] = (s[i] + random.randint(1, 255)) % 256
1239 return s.tobytes()
1240
1241
1242@conf.commands.register

Callers 1

_fixMethod · 0.90

Calls 1

bytes_encodeFunction · 0.90

Tested by

no test coverage detected