Skip to content

Commit

Permalink
get everything ready for v2.0.11
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisschellekens committed Oct 2, 2021
1 parent 5932785 commit 9580de9
Show file tree
Hide file tree
Showing 401 changed files with 1,451 additions and 682 deletions.
2 changes: 1 addition & 1 deletion borb/io/read/any_object_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
from borb.io.read.page.root_dictionary_transformer import RootDictionaryTransformer
from borb.io.read.primitive.number_transformer import NumberTransformer
from borb.io.read.primitive.string_transformer import StringTransformer
from borb.io.read.transformer import Transformer, ReadTransformerState
from borb.io.read.reference.reference_transformer import ReferenceTransformer
from borb.io.read.reference.xref_transformer import XREFTransformer
from borb.io.read.transformer import Transformer, ReadTransformerState
from borb.io.read.types import AnyPDFType
from borb.pdf.canvas.event.event_listener import EventListener

Expand Down
43 changes: 43 additions & 0 deletions borb/io/read/encryption/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""
This file is part of the borb (R) project.
Copyright (c) 2020-2040 borb Group NV
Authors: Joris Schellekens, et al.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation with the addition of the
following permission added to Section 15 as permitted in Section 7(a):
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
BORB GROUP. BORB GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
OF THIRD PARTY RIGHTS
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, see http://www.gnu.org/licenses or write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA, 02110-1301 USA.
The interactive user interfaces in modified source and object code versions
of this program must display Appropriate Legal Notices, as required under
Section 5 of the GNU Affero General Public License.
In accordance with Section 7(b) of the GNU Affero General Public License,
a covered work must retain the producer line in every PDF that is created
or manipulated using borb.
You can be released from the requirements of the license by purchasing
a commercial license. Buying such a license is mandatory as soon as you
develop commercial activities involving the borb software without
disclosing the source code of your own applications.
These activities include: offering paid services to customers as an ASP,
serving PDFs on the fly in a web application, shipping borb with a closed
source product.
For more information, please contact borb Software Corp. at this
address: [email protected]
"""
58 changes: 58 additions & 0 deletions borb/io/read/encryption/rc4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
In cryptography, RC4 (Rivest Cipher 4 also known as ARC4 or ARCFOUR meaning Alleged RC4, see below) is a stream cipher.
While it is remarkable for its simplicity and speed in software, multiple vulnerabilities have been discovered in RC4, rendering it insecure.
It is especially vulnerable when the beginning of the output keystream is not discarded, or when nonrandom or related keys are used.
Particularly problematic uses of RC4 have led to very insecure protocols such as WEP.
As of 2015, there is speculation that some state cryptologic agencies may possess the capability to break RC4 when used in the TLS protocol.
IETF has published RFC 7465 to prohibit the use of RC4 in TLS; Mozilla and Microsoft have issued similar recommendations.
A number of attempts have been made to strengthen RC4, notably Spritz, RC4A, VMPC, and RC4+.
"""


class RC4:
"""
In cryptography, RC4 (Rivest Cipher 4 also known as ARC4 or ARCFOUR meaning Alleged RC4, see below) is a stream cipher.
While it is remarkable for its simplicity and speed in software, multiple vulnerabilities have been discovered in RC4, rendering it insecure.
It is especially vulnerable when the beginning of the output keystream is not discarded, or when nonrandom or related keys are used.
Particularly problematic uses of RC4 have led to very insecure protocols such as WEP.
As of 2015, there is speculation that some state cryptologic agencies may possess the capability to break RC4 when used in the TLS protocol.
IETF has published RFC 7465 to prohibit the use of RC4 in TLS; Mozilla and Microsoft have issued similar recommendations.
A number of attempts have been made to strengthen RC4, notably Spritz, RC4A, VMPC, and RC4+.
"""

def __init__(self):
self._state = [n for n in range(256)]
self._p: int = 0
self._q: int = 0

def set_key(self, key: bytes):
self._state = [n for n in range(256)]
self._p = 0
self._q = 0
j: int = 0
for i in range(256):
if len(key) > 0:
j = (j + self._state[i] + key[i % len(key)]) % 256
else:
j = (j + self._state[i]) % 256
self._state[i], self._state[j] = self._state[j], self._state[i]

def _byte_generator(self):
self._p = (self._p + 1) % 256
self._q = (self._q + self._state[self._p]) % 256
self._state[self._p], self._state[self._q] = (
self._state[self._q],
self._state[self._p],
)
return self._state[(self._state[self._p] + self._state[self._q]) % 256]

def encrypt(self, key: bytes, input: bytes):
self.set_key(key)
return bytes([p ^ self._byte_generator() for p in input])
Loading

0 comments on commit 9580de9

Please sign in to comment.