From 367f563adf50b917968359f426da0c3393cdac86 Mon Sep 17 00:00:00 2001 From: William McBrine Date: Fri, 18 Oct 2013 14:14:07 -0400 Subject: [PATCH] Faster XOR (struct pack/unpack beats chr/ord); don't generate Turing data for the padding bytes. --- metadata.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/metadata.py b/metadata.py index 4cd5282..ec7e75e 100755 --- a/metadata.py +++ b/metadata.py @@ -7,6 +7,7 @@ import struct import subprocess import sys from datetime import datetime +from itertools import izip from xml.dom import minidom from xml.parsers import expat try: @@ -670,6 +671,7 @@ def _tdcat_py(full_path, tivo_mak): count += chunk_size - 12 chunk = xml_data[2] + details = chunk['data'] if chunk['enc']: xml_key = xml_data[3]['data'] @@ -679,13 +681,13 @@ def _tdcat_py(full_path, tivo_mak): turkey = hashlib.sha1(key[:17]).digest() turiv = hashlib.sha1(key).digest() - xor_data = turing.Turing(turkey, turiv).gen(offset) + xor_data = turing.Turing(turkey, turiv).gen(count) s = chunk['start'] - details = ''.join(chr(ord(c) ^ ord(xor_data[s + count])) - for count, c in enumerate(chunk['data'])) - else: - details = chunk['data'] + fmt = '%dB' % len(details) + d2 = struct.unpack(fmt, details) + x2 = struct.unpack(fmt, xor_data[s:s + len(details)]) + details = struct.pack(fmt, *(a ^ b for a, b in izip(d2, x2))) return details -- 2.11.4.GIT