python-migrations / PythonDataset /train /pyope-task-instances.jsonl.all
12Parker's picture
Upload 96 files
5980447 verified
{"repo": "tonyo/pyope", "pull_number": 10, "instance_id": "tonyo__pyope-10", "issue_numbers": "", "base_commit": "88c230b4f621debd91865968f42e1fca0b36e78d", "patch": "diff --git a/pyope/ope.py b/pyope/ope.py\n--- a/pyope/ope.py\n+++ b/pyope/ope.py\n@@ -1,11 +1,14 @@\n import hmac\n import math\n import hashlib\n-from Crypto.Cipher import AES\n-from Crypto.Util import Counter\n-from pyope.errors import InvalidCiphertextError, InvalidRangeLimitsError, OutOfRangeError\n+\n+from cryptography.hazmat.primitives.ciphers import Cipher, algorithms\n+from cryptography.hazmat.backends import default_backend\n+from cryptography.hazmat.primitives.ciphers.modes import CTR\n+\n import pyope.stat as stat\n import pyope.util as util\n+from pyope.errors import InvalidCiphertextError, InvalidRangeLimitsError, OutOfRangeError\n \n \n DEFAULT_IN_RANGE_START = 0\n@@ -154,18 +157,20 @@ def tape_gen(self, data):\n # FIXME\n data = str(data).encode()\n \n- # Derive a key\n+ # Derive a key from data\n hmac_obj = hmac.HMAC(self.key, digestmod=hashlib.sha256)\n hmac_obj.update(data)\n assert hmac_obj.digest_size == 32\n digest = hmac_obj.digest()\n \n- # Use AES-CTR cipher to generate a pseudo-random bit string\n- aes_cipher = AES.new(digest, AES.MODE_CTR, counter=Counter.new(nbits=128))\n+ # Use AES in the CTR mode to generate a pseudo-random bit string\n+ aes_algo = algorithms.AES(digest)\n+ aes_cipher = Cipher(aes_algo, mode=CTR(b'\\x00' * 16), backend=default_backend())\n+ encryptor = aes_cipher.encryptor()\n+\n while True:\n- encrypted_bytes = aes_cipher.encrypt(b'\\x00' * 16)\n+ encrypted_bytes = encryptor.update(b'\\x00' * 16)\n # Convert the data to a list of bits\n bits = util.str_to_bitstring(encrypted_bytes)\n for bit in bits:\n yield bit\n-\ndiff --git a/setup.py b/setup.py\n--- a/setup.py\n+++ b/setup.py\n@@ -16,6 +16,8 @@\n author_email='anton.ovchi2nikov@gmail.com',\n license='MIT',\n packages=['pyope'],\n- install_requires=['pytest>=2.6.4', 'pycrypto>=2.6.1'],\n+ install_requires=[\n+ 'cryptography>=1.1',\n+ ],\n zip_safe=False,\n )\n", "test_patch": "", "problem_statement": "", "hints_text": "", "created_at": "2017-01-01T19:56:53Z"}