text
stringlengths 0
828
|
|---|
response = request.post(url,data)
|
elif method=='PUT':
|
response = request.put(url,data)
|
elif method=='DELETE':
|
response = request.delete(url)
|
else:
|
return {'error' : 'No such request method %s' % method}
|
return response"
|
666,"def inverse(self, N):
|
""""""
|
Returns the modular inverse of an integer with respect to the field
|
characteristic, P.
|
Use the Extended Euclidean Algorithm:
|
ERROR: type should be string, got " https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm"
|
""""""
|
if N == 0:
|
return 0
|
lm, hm = 1, 0
|
low, high = N % self.P, self.P
|
while low > 1:
|
r = high//low
|
nm, new = hm - lm * r, high - low * r
|
lm, low, hm, high = nm, new, lm, low
|
return lm % self.P"
|
667,"def is_on_curve(self, point):
|
""""""
|
Checks whether a point is on the curve.
|
Args:
|
point (AffinePoint): Point to be checked.
|
Returns:
|
bool: True if point is on the curve, False otherwise.
|
""""""
|
X, Y = point.X, point.Y
|
return (
|
pow(Y, 2, self.P) - pow(X, 3, self.P) - self.a * X - self.b
|
) % self.P == 0"
|
668,"def generate_private_key(self):
|
""""""
|
Generates a private key based on the password.
|
SHA-256 is a member of the SHA-2 cryptographic hash functions designed by
|
the NSA. SHA stands for Secure Hash Algorithm. The password is converted
|
to bytes and hashed with SHA-256. The binary output is converted to a hex
|
representation.
|
Args:
|
data (str): The data to be hashed with SHA-256.
|
Returns:
|
bytes: The hexadecimal representation of the hashed binary data.
|
""""""
|
random_string = base64.b64encode(os.urandom(4096)).decode('utf-8')
|
binary_data = bytes(random_string, 'utf-8')
|
hash_object = hashlib.sha256(binary_data)
|
message_digest_bin = hash_object.digest()
|
message_digest_hex = binascii.hexlify(message_digest_bin)
|
return message_digest_hex"
|
669,"def generate_public_key(self):
|
""""""
|
Generates a public key from the hex-encoded private key using elliptic
|
curve cryptography. The private key is multiplied by a predetermined point
|
on the elliptic curve called the generator point, G, resulting in the
|
corresponding private key. The generator point is always the same for all
|
Bitcoin users.
|
Jacobian coordinates are used to represent the elliptic curve point G.
|
ERROR: type should be string, got " https://en.wikibooks.org/wiki/Cryptography/Prime_Curve/Jacobian_Coordinates"
|
The exponentiating by squaring (also known by double-and-add) method is
|
used for the elliptic curve multiplication that results in the public key.
|
ERROR: type should be string, got " https://en.wikipedia.org/wiki/Exponentiation_by_squaring"
|
Bitcoin public keys are 65 bytes. The first byte is 0x04, next 32
|
bytes correspond to the X coordinate, and last 32 bytes correspond
|
to the Y coordinate. They are typically encoded as 130-length hex
|
characters.
|
Args:
|
private_key (bytes): UTF-8 encoded hexadecimal
|
Returns:
|
str: The public key in hexadecimal representation.
|
""""""
|
private_key = int(self.private_key, 16)
|
if private_key >= self.N:
|
raise Exception('Invalid private key.')
|
G = JacobianPoint(self.Gx, self.Gy, 1)
|
public_key = G * private_key
|
x_hex = '{0:0{1}x}'.format(public_key.X, 64)
|
y_hex = '{0:0{1}x}'.format(public_key.Y, 64)
|
return '04' + x_hex + y_hex"
|
670,"def generate_address(self):
|
""""""
|
Creates a Bitcoin address from the public key.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.