Skip to content

Commit

Permalink
Validate Hexadecimal
Browse files Browse the repository at this point in the history
Signed-off-by: Fahd El Haraka <elharakafahd@icloud.com>
  • Loading branch information
ELHARAKA authored Aug 2, 2024
1 parent 63f32a2 commit 968a17e
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions to_wif.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,20 @@
Module for converting batch bitcoin private keys to WIF (Compressed & Uncompressed).
"""

import binascii
from src.conversion_utils import convert_hex_to_wif
from src.common import process_file

def is_valid_hex_key(hex_key):
"""
Validate if the given string is a valid hexadecimal.
"""
try:
int(hex_key, 16)
return True
except ValueError:
return False

def convert_compressed(hex_private_key):
"""
Convert a hexadecimal private key to Wallet Import Format (WIF) for compressed addresses.
Expand All @@ -28,14 +39,16 @@ def process_both_conversions(hex_private_key):
Args:
hex_private_key (str): The hexadecimal private key to be converted.
"""
convert_compressed(hex_private_key)
convert_uncompressed(hex_private_key)
if is_valid_hex_key(hex_private_key):
convert_compressed(hex_private_key)
convert_uncompressed(hex_private_key)
else:
print(f"Invalid hexadecimal key: {hex_private_key}")

# Call common.py to process the file with both conversion functions
process_file("hex_input.txt", process_both_conversions)

print("Conversion successful. Check your 'compressed_output.txt' and "
"'uncompressed_output.txt' files for the converted keys.")
print("Conversion process completed. Check 'compressed_output.txt' and 'uncompressed_output.txt' files for the converted keys.")
print("__________________________________________________")
print("Developed by: Fahd El Haraka")
print("If this saved you time or helped, donations please for BTC Address:")
Expand Down

0 comments on commit 968a17e

Please sign in to comment.