import hashlib
import sys

# Encrypts a string using SHA-256 and returns the hexadecimal representation.
# Usage: python encrypt.py [password]
# example: python encrypt.py 'mysecretpassword'

def encrypt_sha256(input_str: str) -> str:
    digest = hashlib.sha256(input_str.encode()).digest()

    # BigInteger(1, messageDigest).toString(16) drops leading zero bytes
    no = int.from_bytes(digest, byteorder="big")
    hashtext = format(no, "x")  # hex without leading zeros

    # Same padding as Java: while (hashtext.length() < 32)
    while len(hashtext) < 32:
        hashtext = "0" + hashtext

    return hashtext


if __name__ == "__main__":
    password = sys.argv[1] if len(sys.argv) > 1 else input("Password: ")
    print(encrypt_sha256(password))

