Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(433)

Unified Diff: third_party/tlslite/tlslite/utils/python_rc4.py

Issue 210323002: Update tlslite to 0.4.6. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Executable bit and --similarity=80 Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/tlslite/tlslite/utils/python_aes.py ('k') | third_party/tlslite/tlslite/utils/python_rsakey.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/tlslite/tlslite/utils/python_rc4.py
diff --git a/third_party/tlslite/tlslite/utils/python_rc4.py b/third_party/tlslite/tlslite/utils/python_rc4.py
index c513ce78c8ca82bff73b1a40af86f52f4b1d38c6..15d9fd49113e7e5fdf1269385f0c0b8f5d183fa8 100644
--- a/third_party/tlslite/tlslite/utils/python_rc4.py
+++ b/third_party/tlslite/tlslite/utils/python_rc4.py
@@ -1,15 +1,17 @@
+# Author: Trevor Perrin
+# See the LICENSE file for legal information regarding use of this file.
+
"""Pure-Python RC4 implementation."""
-from rc4 import RC4
-from cryptomath import *
+from .rc4 import RC4
+from .cryptomath import *
def new(key):
return Python_RC4(key)
class Python_RC4(RC4):
- def __init__(self, key):
- RC4.__init__(self, key, "python")
- keyBytes = stringToBytes(key)
+ def __init__(self, keyBytes):
+ RC4.__init__(self, keyBytes, "python")
S = [i for i in range(256)]
j = 0
for i in range(256):
@@ -20,20 +22,20 @@ class Python_RC4(RC4):
self.i = 0
self.j = 0
- def encrypt(self, plaintext):
- plaintextBytes = stringToBytes(plaintext)
+ def encrypt(self, plaintextBytes):
+ ciphertextBytes = plaintextBytes[:]
S = self.S
i = self.i
j = self.j
- for x in range(len(plaintextBytes)):
+ for x in range(len(ciphertextBytes)):
i = (i + 1) % 256
j = (j + S[i]) % 256
S[i], S[j] = S[j], S[i]
t = (S[i] + S[j]) % 256
- plaintextBytes[x] ^= S[t]
+ ciphertextBytes[x] ^= S[t]
self.i = i
self.j = j
- return bytesToString(plaintextBytes)
+ return ciphertextBytes
def decrypt(self, ciphertext):
return self.encrypt(ciphertext)
« no previous file with comments | « third_party/tlslite/tlslite/utils/python_aes.py ('k') | third_party/tlslite/tlslite/utils/python_rsakey.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698