<commit_before>from binascii import hexlify
from bmconfigparser import BMConfigParser
import pyelliptic
from pyelliptic import arithmetic as a, OpenSSL
def makeCryptor(privkey):
    private_key = a.changebase(privkey, 16, 256, minlen=32)
    public_key = pointMult(private_key)
    privkey_bin = <KEY>' + private_key
    pubkey_bin = <KEY>' + public_key[1:-32] + <KEY>' + public_key[-32:]
    cryptor = pyelliptic.ECC(curve='secp256k1',privkey=privkey_bin,pubkey=pubkey_bin)
    return cryptor
def hexToPubkey(pubkey):
    pubkey_raw = a.changebase(pubkey[2:],16,256,minlen=64)
    pubkey_bin = '\<KEY> '+pubkey_raw[:32]+'\x00 '+pubkey_raw[32:]
    return pubkey_bin
def makePubCryptor(pubkey):
    pubkey_bin = hexToPubkey(pubkey)
    return pyelliptic.ECC(curve='secp256k1',pubkey=pubkey_bin)
# Converts hex private key into hex public key
def privToPub(privkey):
    private_key = a.changebase(privkey, 16, 256, minlen=32)
    public_key = pointMult(private_key)
    return hexlify(public_key)
# Encrypts message with hex public key
def encrypt(msg,hexPubkey):
    return pyelliptic.ECC(curve='secp256k1').encrypt(msg,hexToPubkey(hexPubkey))
# Decrypts message with hex private key
def decrypt(msg,hexPrivkey):
    return makeCryptor(hexPrivkey).decrypt(msg)
# Decrypts message with an existing pyelliptic.ECC.ECC object
def decryptFast(msg,cryptor):
    return cryptor.decrypt(msg)
# Signs with hex private key
def sign(msg,hexPrivkey):
    # pyelliptic is upgrading from SHA1 to SHA256 for signing. We must 
    # upgrade PyBitmessage gracefully. 
    # https://github.com/yann2192/pyelliptic/pull/33
    # More discussion: https://github.com/yann2192/pyelliptic/issues/32
    digestAlg = BMConfigParser().safeGet('bitmessagesettings', 'digestalg', 'sha1')
    if digestAlg == "sha1":
        # SHA1, this will eventually be deprecated
        print "sha1"
        return makeCryptor(hexPrivkey).sign(msg, digest_alg=OpenSSL.digest_ecdsa_sha1)
    elif digestAlg == "sha256":
        # SHA256. Eventually this will become the default
        print "sha256"
        return makeCryptor(hexPrivkey).sign(msg, digest_alg=OpenSSL.EVP_sha256)
    else:
        raise ValueError("Unknown digest algorithm %s" % (digestAlgo))
# Verifies with hex public key
def verify(msg,sig,hexPubkey):
    # As mentioned above, we must upgrade gracefully to use SHA256. So
    # let us check the signature using both SHA1 and SHA256 and if one
    # of them passes then we will be satisfied. Eventually this can <commit_msg>Remove unnecessary "print" from previous commit<commit_after>from binascii import hexlify
from bmconfigparser import BMConfigParser
import pyelliptic
from pyelliptic import arithmetic as a, OpenSSL
def makeCryptor(privkey):
    private_key = a.changebase(privkey, 16, 256, minlen=32)
    public_key = pointMult(private_key)
    privkey_bin = <KEY>' + private_key
    pubkey_bin = <KEY> + public_key[1:-32] + '\x00\x20' + public_key[-32:]
    cryptor = pyelliptic.ECC(curve='secp256k1',privkey=privkey_bin,pubkey=pubkey_bin)
    return cryptor
def hexToPubkey(pubkey):
    pubkey_raw = a.changebase(pubkey[2:],16,256,minlen=64)
    pubkey_bin = '\x02\xca\x00 '+pubkey_raw[:32]+'\x00 '+pubkey_raw[32:]
    return pubkey_bin
def makePubCryptor(pubkey):
    pubkey_bin = hexToPubkey(pubkey)
    return pyelliptic.ECC(curve='secp256k1',pubkey=pubkey_bin)
# Converts hex private key into hex public key
def privToPub(privkey):
    private_key = a.changebase(privkey, 16, 256, minlen=32)
    public_key = pointMult(private_key)
    return hexlify(public_key)
# Encrypts message with hex public key
def encrypt(msg,hexPubkey):
    return pyelliptic.ECC(curve='secp256k1').encrypt(msg,hexToPubkey(hexPubkey))
# Decrypts message with hex private key
def decrypt(msg,hexPrivkey):
    return makeCryptor(hexPrivkey).decrypt(msg)
# Decrypts message with an existing pyelliptic.ECC.ECC object
def decryptFast(msg,cryptor):
    return cryptor.decrypt(msg)
# Signs with hex private key
def sign(msg,hexPrivkey):
    # pyelliptic is upgrading from SHA1 to SHA256 for signing. We must 
    # upgrade PyBitmessage gracefully. 
    # https://github.com/yann2192/pyelliptic/pull/33
    # More discussion: https://github.com/yann2192/pyelliptic/issues/32
    digestAlg = BMConfigParser().safeGet('bitmessagesettings', 'digestalg', 'sha1')
    if digestAlg == "sha1":
        # SHA1, this will eventually be deprecated
        return makeCryptor(hexPrivkey).sign(msg, digest_alg=OpenSSL.digest_ecdsa_sha1)
    elif digestAlg == "sha256":
        # SHA256. Eventually this will become the default
        return makeCryptor(hexPrivkey).sign(msg, digest_alg=OpenSSL.EVP_sha256)
    else:
        raise ValueError("Unknown digest algorithm %s" % (digestAlgo))
# Verifies with hex public key
def verify(msg,sig,hexPubkey):
    # As mentioned above, we must upgrade gracefully to use SHA256. So
    # let us check the signature using both SHA1 and SHA256 and if one
    # of them passes then we will be satisfied. Eventually this can 
{'fraction_non_alphanumeric': 0.09894274885298225, 'fraction_numerical': 0.034709754637941355, 'mean_word_length': 4.595982142857143, 'pattern_counts': {'":': 4, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5033001', 'n_tokens_mistral': 1794, 'n_tokens_neox': 1665, 'n_words': 423}