MCPcopy Create free account
hub / github.com/modelscope/ms-agent / str_to_md5

Function str_to_md5

ms_agent/utils/utils.py:126–145  ·  view source on GitHub ↗

Converts a given string into its corresponding MD5 hash. This function encodes the input string using UTF-8 and computes the MD5 hash, returning the result as a 32-character hexadecimal string. Args: text (str): The input string to be hashed. Returns: str: The

(text: str)

Source from the content-addressed store, hash-verified

124
125
126def str_to_md5(text: str) -> str:
127 """
128 Converts a given string into its corresponding MD5 hash.
129
130 This function encodes the input string using UTF-8 and computes the MD5 hash,
131 returning the result as a 32-character hexadecimal string.
132
133 Args:
134 text (str): The input string to be hashed.
135
136 Returns:
137 str: The MD5 hash of the input string, represented as a hexadecimal string.
138
139 Example:
140 >>> str_to_md5("hello world")
141 '5eb63bbbe01eeed093cb22bb8f5acdc3'
142 """
143 text_bytes = text.encode('utf-8')
144 md5_hash = hashlib.md5(text_bytes)
145 return md5_hash.hexdigest()
146
147
148def escape_yaml_string(text: str) -> str:

Callers

nothing calls this directly

Calls 1

encodeMethod · 0.80

Tested by

no test coverage detected