Created
December 16, 2025 07:56
-
-
Save ekiara/2a8cb3a79c3c54b06846f8678f64715b to your computer and use it in GitHub Desktop.
Generate MD5_CRYPT Hash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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