From fc87287f136ff04502c27cf64bd9d00d7eee5c9c Mon Sep 17 00:00:00 2001 From: lmwgv Date: Mon, 12 Feb 2018 11:06:45 +0100 Subject: [PATCH] Improve performance of RC4_encrypt in utils.py Avoid string concatenation until after the loop. --- PyPDF2/utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/PyPDF2/utils.py b/PyPDF2/utils.py index 6b536a0..2120c70 100644 --- a/PyPDF2/utils.py +++ b/PyPDF2/utils.py @@ -172,14 +172,14 @@ def RC4_encrypt(key, plaintext): j = (j + S[i] + ord_(key[i % len(key)])) % 256 S[i], S[j] = S[j], S[i] i, j = 0, 0 - retval = b_("") + retval = [] for x in range(len(plaintext)): i = (i + 1) % 256 j = (j + S[i]) % 256 S[i], S[j] = S[j], S[i] t = S[(S[i] + S[j]) % 256] - retval += b_(chr(ord_(plaintext[x]) ^ t)) - return retval + retval.append(b_(chr(ord_(plaintext[x]) ^ t))) + return b_("").join(retval) def matrixMultiply(a, b):