Hashing (hiding) strings in Python

前端 未结 4 1729
南方客
南方客 2020-12-15 08:14

What I need is to hash a string. It doesn\'t have to be secure because it\'s just going to be a hidden phrase in the text file (it just doesn\'t have to be recognizable for

4条回答
  •  无人及你
    2020-12-15 08:39

    You can simply use the base64 module to achieve your goal:

    >>> import base64
    >>> a = 'helloworld'
    >>> encoded_str = base64.encodestring(a)
    >>> encoded_str
    'aGVsbG93b3JsZA=='
    >>> base64.decodestring(encoded_str)
    'helloworld'
    >>>
    

    of course you can also use the the hashlib module, it's more secure , because the hashed string cannot(or very very hard) be decoded latter, but for your question base64 is enough -- "It doesn't really have to be secure"

提交回复
热议问题