-
-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5932785
commit 9580de9
Showing
401 changed files
with
1,451 additions
and
682 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) |
Oops, something went wrong.