summaryrefslogtreecommitdiff
path: root/tools/xor_compress.py
diff options
context:
space:
mode:
authorRangi <remy.oukaour+rangi42@gmail.com>2020-09-14 13:47:20 -0400
committerRangi <remy.oukaour+rangi42@gmail.com>2020-09-14 13:47:20 -0400
commit46b7c8acf4cdb06a2cbe72ecf4b7d51d74026c5c (patch)
treeca7074c4727dfd0a8eb8799fc54689ccb3f37f60 /tools/xor_compress.py
parent5736e0a953cd442a76583dd6a9407b4a426115fb (diff)
xor_compress.py and dump_decompress.py share variable names
Diffstat (limited to 'tools/xor_compress.py')
-rw-r--r--tools/xor_compress.py20
1 files changed, 10 insertions, 10 deletions
diff --git a/tools/xor_compress.py b/tools/xor_compress.py
index 30418db..5b3e6a2 100644
--- a/tools/xor_compress.py
+++ b/tools/xor_compress.py
@@ -9,35 +9,35 @@ with (open(sys.argv[1], 'rb') if len(sys.argv) > 1 else sys.stdin) as f:
n = len(data)
output = []
-v = 0
+v = 0x00
i = 0
while i < n:
- val = data[i]
+ byte = data[i]
i += 1
- if data[i] == v: #>=0x80
+ if data[i] == v:
# Alternating (>= 0x80)
# Run stops at 0x81 bytes or when the values stop alternating
size = 1
- while i < n and size < 0x81 and data[i] == (v if size % 2 else val):
+ while i < n and size < 0x81 and data[i] == (v if size % 2 else byte):
size += 1
i += 1
output.append(size + 0x7e)
- output.append(v ^ val)
+ output.append(v ^ byte)
if size % 2:
- v = val
+ v = byte
else:
# Sequential (< 0x80)
# Run stops at 0x80 bytes or when the value two ahead is equal to v
- buffer = [v ^ val]
+ buffer = [v ^ byte]
while i < n:
- v = val
+ v = byte
if len(buffer) > 0x7f or (i + 1 < n and data[i + 1] == v):
break
- val = data[i]
- buffer.append(v ^ val)
+ byte = data[i]
+ buffer.append(v ^ byte)
i += 1
output.append(len(buffer) - 1)
output.extend(buffer)