Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PEP-8 #92

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions pdfminer/arcfour.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@


""" Python implementation of Arcfour encryption algorithm.
See https://en.wikipedia.org/wiki/RC4
This code is in the public domain.

"""

import six # Python 2+3 compatibility
## Arcfour
##
import six


class Arcfour(object):
""" Python implementation of Arcfour encryption algorithm."""

def __init__(self, key):
s = [i for i in range(256)] #because Py3 range is not indexable
s = [i for i in range(256)] # because Py3 range is not indexable
j = 0
klen = len(key)
for i in range(256):
j = (j + s[i] + six.indexbytes(key,i % klen)) % 256
j = (j + s[i] + six.indexbytes(key, i % klen)) % 256
(s[i], s[j]) = (s[j], s[i])
self.s = s
(self.i, self.j) = (0, 0)
Expand All @@ -34,7 +32,8 @@ def process(self, data):
r += six.int2byte(c ^ k)
(self.i, self.j) = (i, j)
return r

encrypt = decrypt = process


new = Arcfour
27 changes: 10 additions & 17 deletions pdfminer/ascii85.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,26 @@


""" Python implementation of ASCII85/ASCIIHex decoder (Adobe version).

"""Python implementation of ASCII85/ASCIIHex decoder (Adobe version).
This code is in the public domain.

"""

import re
import struct

import six #Python 2+3 compatibility
import six


# ascii85decode(data)
def ascii85decode(data):
"""
In ASCII85 encoding, every four bytes are encoded with five ASCII
letters, using 85 different types of characters (as 256**4 < 85**5).
When the length of the original bytes is not a multiple of 4, a special
rule is used for round up.

The Adobe's ASCII85 implementation is slightly different from
its original in handling the last characters.

"""
n = b = 0
out = b''
for i in six.iterbytes(data):
c=six.int2byte(i)
if b'!' <= c and c <= b'u':
c = six.int2byte(i)
if b'!' <= c <= b'u':
n += 1
b = b*85+(ord(c)-33)
if n == 5:
Expand All @@ -45,6 +37,7 @@ def ascii85decode(data):
break
return out


# asciihexdecode(data)
hex_re = re.compile(b'([a-f\d]{2})', re.IGNORECASE)
trail_re = re.compile(b'^(?:[a-f\d]{2}|\s)*([a-f\d])[\s>]*$', re.IGNORECASE)
Expand All @@ -60,15 +53,15 @@ def asciihexdecode(data):
the EOD marker after reading an odd number of hexadecimal digits, it
will behave as if a 0 followed the last digit.
"""
def decode(x):
i=int(x,16)
def decode(char):
i = int(char, 16)
return six.int2byte(i)

out=b''
out = b''
for x in hex_re.findall(data):
out+=decode(x)
out += decode(x)

m = trail_re.search(data)
if m:
out+=decode(m.group(1)+b'0')
out += decode(m.group(1)+b'0')
return out
Loading