Skip to content

Instantly share code, notes, and snippets.

@ekiara
Created December 16, 2025 07:56
Show Gist options
  • Select an option

  • Save ekiara/2a8cb3a79c3c54b06846f8678f64715b to your computer and use it in GitHub Desktop.

Select an option

Save ekiara/2a8cb3a79c3c54b06846f8678f64715b to your computer and use it in GitHub Desktop.
Generate MD5_CRYPT Hash
import crypt
def add_md5_crypt_hash(tuple_list):
"""
Takes a list of tuples with two strings and returns a list of tuples
with three elements: the original two strings plus an MD5_CRYPT hash
of the second string.
Args:
tuple_list: List of tuples, each containing two strings
Returns:
List of tuples with format (string1, string2, md5_crypt_hash)
"""
result = []
for string1, string2 in tuple_list:
# Generate MD5_CRYPT hash of the second string
md5_hash = crypt.crypt(string2, crypt.METHOD_MD5)
result.append((string1, string2, md5_hash))
return result
# Example usage
if __name__ == "__main__":
# Sample input data
input_tuples = [
("username1", "secret-string0"),
("username2", "s3cret-5tr1ng2"),
]
# Process the tuples
output_tuples = add_md5_crypt_hash(input_tuples)
# Display results
print("Input tuples:")
for t in input_tuples:
print(f" {t}")
print("\nOutput tuples with MD5_CRYPT hashes:")
for t in output_tuples:
print(f" {t}")
# Show just the hashes for clarity
print("\nGenerated hashes:")
for string1, string2, hash_value in output_tuples:
print(f" {string1}: {hash_value}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment