src/reportlab/lib/arciv.py
author rptlab
Tue, 30 Apr 2013 14:28:14 +0100
branchpy33
changeset 3723 99aa837b6703
parent 3721 0c93dd8ff567
child 3800 e8547b00eb59
permissions -rw-r--r--
second stage of port to Python 3.3; working hello world
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3617
ae5744e97c42 reportlab: copyright date changes
robin
parents: 3072
diff changeset
     1
#copyright ReportLab Europe Limited. 2000-2012
3072
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
     2
#see license.txt for license details
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
     3
'''
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
     4
Arciv Stream  ciphering
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
     5
'''
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
     6
__version__=''' $Id$ '''
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
     7
from types import StringType
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
     8
class ArcIV:
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
     9
	'''
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    10
	performs 'ArcIV' Stream Encryption of S using key
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    11
	Based on what is widely thought to be RSA's ArcIV algorithm.
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    12
	It produces output streams that are identical.
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    13
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    14
	NB there is no separate decoder arciv(arciv(s,key),key) == s
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    15
	'''
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    16
	def __init__(self,key):
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    17
		self._key = key
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    18
		self.reset()
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    19
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    20
	def reset(self):
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    21
		'''restore the cipher to it's start state'''
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    22
		#Initialize private key, k With the values of the key mod 256.
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    23
		#and sbox With numbers 0 - 255. Then compute sbox
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    24
		key = self._key
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3617
diff changeset
    25
		sbox = list(range(256))
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3617
diff changeset
    26
		k = list(range(256))
3072
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    27
		lk = len(key)
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    28
		for i in sbox:
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    29
			k[i] = ord(key[i % lk]) % 256
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    30
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    31
		#Re-order sbox using the private key, k.
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    32
		#Iterating each element of sbox re-calculate the counter j
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    33
		#Then interchange the elements sbox[a] & sbox[b]
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    34
		j = 0
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3617
diff changeset
    35
		for i in range(256):
3072
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    36
			j = (j+sbox[i]+k[i]) % 256
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    37
			sbox[i], sbox[j] = sbox[j], sbox[i]
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    38
		self._sbox, self._i, self._j = sbox, 0, 0
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    39
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    40
	def _encode(self, B):
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    41
		'''
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    42
		return the list of encoded bytes of B, B might be a string or a
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    43
		list of integers between 0 <= i <= 255
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    44
		'''
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    45
		sbox, i, j = self._sbox, self._i, self._j
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    46
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3617
diff changeset
    47
		C = type(B) is StringType and list(map(ord,B)) or B[:]
3072
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    48
		n = len(C)
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    49
		p = 0
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    50
		while p<n:
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    51
			#update the variables i, j.
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    52
			self._i = i = (i + 1) % 256
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    53
			self._j = j = (j + sbox[i]) % 256
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    54
			#swap sbox[i] and sbox[j]
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    55
			sbox[i], sbox[j] = sbox[j], sbox[i]
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    56
			#overwrite the plaintext with the ciphered byte
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    57
			C[p] = C[p] ^ sbox[(sbox[i] + sbox[j]) % 256]
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    58
			p = p + 1
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    59
		return C
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    60
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    61
	def encode(self,S):
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    62
		'ArcIV encode string S'
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    63
		return "".join(map(chr,self._encode(S)))
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    64
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    65
_TESTS=[{
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    66
		'key': "\x01\x23\x45\x67\x89\xab\xcd\xef",
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    67
		'input': "\x01\x23\x45\x67\x89\xab\xcd\xef",
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    68
		'output': "\x75\xb7\x87\x80\x99\xe0\xc5\x96",
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    69
		},
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    70
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    71
		{
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    72
		'key': "\x01\x23\x45\x67\x89\xab\xcd\xef",
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    73
		'input': "\x00\x00\x00\x00\x00\x00\x00\x00",
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    74
		'output': "\x74\x94\xc2\xe7\x10\x4b\x08\x79",
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    75
		},
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    76
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    77
		{
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    78
		'key': "\x00\x00\x00\x00\x00\x00\x00\x00",
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    79
		'input': "\x00\x00\x00\x00\x00\x00\x00\x00",
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    80
		'output': "\xde\x18\x89\x41\xa3\x37\x5d\x3a",
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    81
		},
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    82
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    83
		{
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    84
		'key': "\xef\x01\x23\x45",
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    85
		'input': "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    86
		'output': "\xd6\xa1\x41\xa7\xec\x3c\x38\xdf\xbd\x61",
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    87
		},
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    88
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    89
		{
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    90
		'key': "\x01\x23\x45\x67\x89\xab\xcd\xef",
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    91
		'input': "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    92
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    93
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    94
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    95
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    96
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    97
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    98
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
    99
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   100
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   101
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   102
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   103
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   104
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   105
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   106
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   107
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   108
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   109
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   110
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   111
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   112
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   113
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   114
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   115
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   116
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   117
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   118
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   119
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   120
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   121
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   122
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   123
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   124
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   125
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   126
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   127
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   128
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   129
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   130
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   131
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   132
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   133
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   134
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   135
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   136
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   137
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   138
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   139
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   140
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   141
\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   142
\x01",
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   143
	'output': "\x75\x95\xc3\xe6\x11\x4a\x09\x78\x0c\x4a\xd4\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   144
\x52\x33\x8e\x1f\xfd\x9a\x1b\xe9\x49\x8f\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   145
\x81\x3d\x76\x53\x34\x49\xb6\x77\x8d\xca\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   146
\xd8\xc7\x8a\x8d\x2b\xa9\xac\x66\x08\x5d\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   147
\x0e\x53\xd5\x9c\x26\xc2\xd1\xc4\x90\xc1\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   148
\xeb\xbe\x0c\xe6\x6d\x1b\x6b\x1b\x13\xb6\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   149
\xb9\x19\xb8\x47\xc2\x5a\x91\x44\x7a\x95\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   150
\xe7\x5e\x4e\xf1\x67\x79\xcd\xe8\xbf\x0a\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   151
\x95\x85\x0e\x32\xaf\x96\x89\x44\x4f\xd3\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   152
\x77\x10\x8f\x98\xfd\xcb\xd4\xe7\x26\x56\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   153
\x75\x00\x99\x0b\xcc\x7e\x0c\xa3\xc4\xaa\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   154
\xa3\x04\xa3\x87\xd2\x0f\x3b\x8f\xbb\xcd\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   155
\x42\xa1\xbd\x31\x1d\x7a\x43\x03\xdd\xa5\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   156
\xab\x07\x88\x96\xae\x80\xc1\x8b\x0a\xf6\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   157
\x6d\xff\x31\x96\x16\xeb\x78\x4e\x49\x5a\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   158
\xd2\xce\x90\xd7\xf7\x72\xa8\x17\x47\xb6\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   159
\x5f\x62\x09\x3b\x1e\x0d\xb9\xe5\xba\x53\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   160
\x2f\xaf\xec\x47\x50\x83\x23\xe6\x71\x32\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   161
\x7d\xf9\x44\x44\x32\xcb\x73\x67\xce\xc8\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   162
\x2f\x5d\x44\xc0\xd0\x0b\x67\xd6\x50\xa0\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   163
\x75\xcd\x4b\x70\xde\xdd\x77\xeb\x9b\x10\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   164
\x23\x1b\x6b\x5b\x74\x13\x47\x39\x6d\x62\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   165
\x89\x74\x21\xd4\x3d\xf9\xb4\x2e\x44\x6e\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   166
\x35\x8e\x9c\x11\xa9\xb2\x18\x4e\xcb\xef\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   167
\x0c\xd8\xe7\xa8\x77\xef\x96\x8f\x13\x90\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   168
\xec\x9b\x3d\x35\xa5\x58\x5c\xb0\x09\x29\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   169
\x0e\x2f\xcd\xe7\xb5\xec\x66\xd9\x08\x4b\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   170
\xe4\x40\x55\xa6\x19\xd9\xdd\x7f\xc3\x16\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   171
\x6f\x94\x87\xf7\xcb\x27\x29\x12\x42\x64\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   172
\x45\x99\x85\x14\xc1\x5d\x53\xa1\x8c\x86\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   173
\x4c\xe3\xa2\xb7\x55\x57\x93\x98\x81\x26\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   174
\x52\x0e\xac\xf2\xe3\x06\x6e\x23\x0c\x91\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   175
\xbe\xe4\xdd\x53\x04\xf5\xfd\x04\x05\xb3\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   176
\x5b\xd9\x9c\x73\x13\x5d\x3d\x9b\xc3\x35\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   177
\xee\x04\x9e\xf6\x9b\x38\x67\xbf\x2d\x7b\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   178
\xd1\xea\xa5\x95\xd8\xbf\xc0\x06\x6f\xf8\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   179
\xd3\x15\x09\xeb\x0c\x6c\xaa\x00\x6c\x80\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   180
\x7a\x62\x3e\xf8\x4c\x3d\x33\xc1\x95\xd2\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   181
\x3e\xe3\x20\xc4\x0d\xe0\x55\x81\x57\xc8\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   182
\x22\xd4\xb8\xc5\x69\xd8\x49\xae\xd5\x9d\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   183
\x4e\x0f\xd7\xf3\x79\x58\x6b\x4b\x7f\xf6\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   184
\x84\xed\x6a\x18\x9f\x74\x86\xd4\x9b\x9c\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   185
\x4b\xad\x9b\xa2\x4b\x96\xab\xf9\x24\x37\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   186
\x2c\x8a\x8f\xff\xb1\x0d\x55\x35\x49\x00\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   187
\xa7\x7a\x3d\xb5\xf2\x05\xe1\xb9\x9f\xcd\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   188
\x86\x60\x86\x3a\x15\x9a\xd4\xab\xe4\x0f\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   189
\xa4\x89\x34\x16\x3d\xdd\xe5\x42\xa6\x58\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   190
\x55\x40\xfd\x68\x3c\xbf\xd8\xc0\x0f\x12\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   191
\x12\x9a\x28\x4d\xea\xcc\x4c\xde\xfe\x58\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   192
\xbe\x71\x37\x54\x1c\x04\x71\x26\xc8\xd4\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   193
\x9e\x27\x55\xab\x18\x1a\xb7\xe9\x40\xb0\
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   194
\xc0",
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   195
		},
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   196
	]
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   197
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   198
def encode(text, key):
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   199
	"One-line shortcut for making an encoder object"
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   200
	return ArcIV(key).encode(text)
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   201
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   202
def decode(text, key):
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   203
	"One-line shortcut for decoding"
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   204
	# yes, encode and decode are symmetric - see docstring
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   205
	return ArcIV(key).encode(text)
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   206
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   207
if __name__=='__main__':
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   208
	i = 0
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   209
	for t in _TESTS:
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   210
		o = ArcIV(t['key']).encode(t['input'])
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3617
diff changeset
   211
		print('Forward test %d %s!' %(i,o!=t['output'] and 'failed' or 'succeeded'))
3072
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   212
		o = ArcIV(t['key']).encode(t['output'])
3721
0c93dd8ff567 initial changes from 2to3-3.3
rptlab
parents: 3617
diff changeset
   213
		print('Reverse test %d %s!' %(i,o!=t['input'] and 'failed' or 'succeeded'))
3072
1cae88d5ec2d make pdfencrypt.py use ArcIV
rgbecker
parents:
diff changeset
   214
		i += 1