• The same string will generate different md5sums by python and md5sum to

    From hongyi.zhao@gmail.com@21:1/5 to All on Tue Oct 12 00:35:32 2021
    For short, as shown below:

    $ md5sum <<< 'TASCJO3RJMVKWDJKXLZM'
    e1b8fa8fe09c295811063bb76cefc337 -

    $ ipython
    In [1]: from hashlib import md5

    In [2]: my_str='TASCJO3RJMVKWDJKXLZM'

    In [3]: md5(my_str.encode('utf-8')).hexdigest()
    Out[3]: 'e9032994dabac08080091151380478a2'

    Any hints for this behavior?

    Regards,
    HZ

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ben Bacarisse@21:1/5 to hongy...@gmail.com on Tue Oct 12 11:25:40 2021
    "hongy...@gmail.com" <hongyi.zhao@gmail.com> writes:

    For short, as shown below:

    $ md5sum <<< 'TASCJO3RJMVKWDJKXLZM'
    e1b8fa8fe09c295811063bb76cefc337 -

    $ ipython
    In [1]: from hashlib import md5

    In [2]: my_str='TASCJO3RJMVKWDJKXLZM'

    In [3]: md5(my_str.encode('utf-8')).hexdigest()
    Out[3]: 'e9032994dabac08080091151380478a2'

    Any hints for this behavior?

    md5("TASCJO3RJMVKWDJKXLZM\n".encode('utf-8')).hexdigest() 'e1b8fa8fe09c295811063bb76cefc337'

    --
    Ben.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From hongyi.zhao@gmail.com@21:1/5 to Ben Bacarisse on Tue Oct 12 05:03:55 2021
    On Tuesday, October 12, 2021 at 6:25:43 PM UTC+8, Ben Bacarisse wrote:
    "hongy...@gmail.com" <hongy...@gmail.com> writes:

    For short, as shown below:

    $ md5sum <<< 'TASCJO3RJMVKWDJKXLZM'
    e1b8fa8fe09c295811063bb76cefc337 -

    $ ipython
    In [1]: from hashlib import md5

    In [2]: my_str='TASCJO3RJMVKWDJKXLZM'

    In [3]: md5(my_str.encode('utf-8')).hexdigest()
    Out[3]: 'e9032994dabac08080091151380478a2'

    Any hints for this behavior?
    md5("TASCJO3RJMVKWDJKXLZM\n".encode('utf-8')).hexdigest() 'e1b8fa8fe09c295811063bb76cefc337'

    Thank you for pointing this out. I confirmed it with the following command:

    $ cat -A <<< 'TASCJO3RJMVKWDJKXLZM'
    TASCJO3RJMVKWDJKXLZM$

    But how to supply string for md5sum without '\n'?

    HZ

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From hongyi.zhao@gmail.com@21:1/5 to hongy...@gmail.com on Tue Oct 12 05:21:00 2021
    On Tuesday, October 12, 2021 at 8:19:28 PM UTC+8, hongy...@gmail.com wrote:
    On Tuesday, October 12, 2021 at 8:03:58 PM UTC+8, hongy...@gmail.com wrote:
    On Tuesday, October 12, 2021 at 6:25:43 PM UTC+8, Ben Bacarisse wrote:
    "hongy...@gmail.com" <hongy...@gmail.com> writes:

    For short, as shown below:

    $ md5sum <<< 'TASCJO3RJMVKWDJKXLZM'
    e1b8fa8fe09c295811063bb76cefc337 -

    $ ipython
    In [1]: from hashlib import md5

    In [2]: my_str='TASCJO3RJMVKWDJKXLZM'

    In [3]: md5(my_str.encode('utf-8')).hexdigest()
    Out[3]: 'e9032994dabac08080091151380478a2'

    Any hints for this behavior?
    md5("TASCJO3RJMVKWDJKXLZM\n".encode('utf-8')).hexdigest() 'e1b8fa8fe09c295811063bb76cefc337'
    Thank you for pointing this out. I confirmed it with the following command:

    $ cat -A <<< 'TASCJO3RJMVKWDJKXLZM'
    TASCJO3RJMVKWDJKXLZM$

    But how to supply string for md5sum without '\n'?
    I see. Here it is:

    $ echo -n 'TASCJO3RJMVKWDJKXLZM' | md5sum
    e9032994dabac08080091151380478a2 -

    So, it seems that the `<<<' will also append `\n' at the end of the string.

    HZ

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From David W. Hodgins@21:1/5 to hongy...@gmail.com on Tue Oct 12 09:04:49 2021
    On Tue, 12 Oct 2021 08:03:55 -0400, hongy...@gmail.com <hongyi.zhao@gmail.com> wrote:

    On Tuesday, October 12, 2021 at 6:25:43 PM UTC+8, Ben Bacarisse wrote:
    "hongy...@gmail.com" <hongy...@gmail.com> writes:

    For short, as shown below:

    $ md5sum <<< 'TASCJO3RJMVKWDJKXLZM'
    e1b8fa8fe09c295811063bb76cefc337 -

    $ ipython
    In [1]: from hashlib import md5

    In [2]: my_str='TASCJO3RJMVKWDJKXLZM'

    In [3]: md5(my_str.encode('utf-8')).hexdigest()
    Out[3]: 'e9032994dabac08080091151380478a2'

    Any hints for this behavior?
    md5("TASCJO3RJMVKWDJKXLZM\n".encode('utf-8')).hexdigest()
    'e1b8fa8fe09c295811063bb76cefc337'

    Thank you for pointing this out. I confirmed it with the following command:

    $ cat -A <<< 'TASCJO3RJMVKWDJKXLZM'
    TASCJO3RJMVKWDJKXLZM$

    But how to supply string for md5sum without '\n'?

    $ echo -n 'TASCJO3RJMVKWDJKXLZM' |md5sum
    e9032994dabac08080091151380478a2 -

    Regards, Dave Hodgins

    --
    Change dwhodgins@nomail.afraid.org to davidwhodgins@teksavvy.com for
    email replies.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From hongyi.zhao@gmail.com@21:1/5 to hongy...@gmail.com on Tue Oct 12 05:19:25 2021
    On Tuesday, October 12, 2021 at 8:03:58 PM UTC+8, hongy...@gmail.com wrote:
    On Tuesday, October 12, 2021 at 6:25:43 PM UTC+8, Ben Bacarisse wrote:
    "hongy...@gmail.com" <hongy...@gmail.com> writes:

    For short, as shown below:

    $ md5sum <<< 'TASCJO3RJMVKWDJKXLZM'
    e1b8fa8fe09c295811063bb76cefc337 -

    $ ipython
    In [1]: from hashlib import md5

    In [2]: my_str='TASCJO3RJMVKWDJKXLZM'

    In [3]: md5(my_str.encode('utf-8')).hexdigest()
    Out[3]: 'e9032994dabac08080091151380478a2'

    Any hints for this behavior?
    md5("TASCJO3RJMVKWDJKXLZM\n".encode('utf-8')).hexdigest() 'e1b8fa8fe09c295811063bb76cefc337'
    Thank you for pointing this out. I confirmed it with the following command:

    $ cat -A <<< 'TASCJO3RJMVKWDJKXLZM'
    TASCJO3RJMVKWDJKXLZM$

    But how to supply string for md5sum without '\n'?

    I see. Here it is:

    $ echo -n 'TASCJO3RJMVKWDJKXLZM' | md5sum
    e9032994dabac08080091151380478a2 -

    HZ

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From William Unruh@21:1/5 to hongy...@gmail.com on Tue Oct 12 13:12:07 2021
    On 2021-10-12, hongy...@gmail.com <hongyi.zhao@gmail.com> wrote:
    On Tuesday, October 12, 2021 at 8:19:28 PM UTC+8, hongy...@gmail.com wrote:
    On Tuesday, October 12, 2021 at 8:03:58 PM UTC+8, hongy...@gmail.com wrote: >> > On Tuesday, October 12, 2021 at 6:25:43 PM UTC+8, Ben Bacarisse wrote:
    "hongy...@gmail.com" <hongy...@gmail.com> writes:

    For short, as shown below:

    $ md5sum <<< 'TASCJO3RJMVKWDJKXLZM'
    e1b8fa8fe09c295811063bb76cefc337 -

    $ ipython
    In [1]: from hashlib import md5

    In [2]: my_str='TASCJO3RJMVKWDJKXLZM'

    In [3]: md5(my_str.encode('utf-8')).hexdigest()
    Out[3]: 'e9032994dabac08080091151380478a2'

    Any hints for this behavior?
    md5("TASCJO3RJMVKWDJKXLZM\n".encode('utf-8')).hexdigest()
    'e1b8fa8fe09c295811063bb76cefc337'
    Thank you for pointing this out. I confirmed it with the following command:

    $ cat -A <<< 'TASCJO3RJMVKWDJKXLZM'
    TASCJO3RJMVKWDJKXLZM$

    But how to supply string for md5sum without '\n'?
    I see. Here it is:

    $ echo -n 'TASCJO3RJMVKWDJKXLZM' | md5sum
    e9032994dabac08080091151380478a2 -

    So, it seems that the `<<<' will also append `\n' at the end of the string.

    HZ

    From man bash

    Here Strings
    A variant of here documents, the format is:

    [n]<<<word

    The word undergoes tilde expansion, parameter and variable expansion, command substitu-
    tion, arithmetic expansion, and quote removal. Pathname expansion and word splitting are
    not performed. The result is supplied as a single string, with a newline appended, to
    the command on its standard input (or file descriptor n if n is specified).


    Note the second last line.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Christian Weisgerber@21:1/5 to hongy...@gmail.com on Tue Oct 12 12:38:49 2021
    On 2021-10-12, hongy...@gmail.com <hongyi.zhao@gmail.com> wrote:

    But how to supply string for md5sum without '\n'?

    $ printf '%s' 'TASCJO3RJMVKWDJKXLZM' | md5
    e9032994dabac08080091151380478a2

    --
    Christian "naddy" Weisgerber naddy@mips.inka.de

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ed Morton@21:1/5 to hongy...@gmail.com on Tue Oct 12 09:15:17 2021
    On 10/12/2021 7:21 AM, hongy...@gmail.com wrote:
    On Tuesday, October 12, 2021 at 8:19:28 PM UTC+8, hongy...@gmail.com wrote:
    On Tuesday, October 12, 2021 at 8:03:58 PM UTC+8, hongy...@gmail.com wrote: >>> On Tuesday, October 12, 2021 at 6:25:43 PM UTC+8, Ben Bacarisse wrote:
    "hongy...@gmail.com" <hongy...@gmail.com> writes:

    For short, as shown below:

    $ md5sum <<< 'TASCJO3RJMVKWDJKXLZM'
    e1b8fa8fe09c295811063bb76cefc337 -

    $ ipython
    In [1]: from hashlib import md5

    In [2]: my_str='TASCJO3RJMVKWDJKXLZM'

    In [3]: md5(my_str.encode('utf-8')).hexdigest()
    Out[3]: 'e9032994dabac08080091151380478a2'

    Any hints for this behavior?
    md5("TASCJO3RJMVKWDJKXLZM\n".encode('utf-8')).hexdigest()
    'e1b8fa8fe09c295811063bb76cefc337'
    Thank you for pointing this out. I confirmed it with the following command: >>>
    $ cat -A <<< 'TASCJO3RJMVKWDJKXLZM'
    TASCJO3RJMVKWDJKXLZM$

    But how to supply string for md5sum without '\n'?
    I see. Here it is:

    $ echo -n 'TASCJO3RJMVKWDJKXLZM' | md5sum
    e9032994dabac08080091151380478a2 -

    So, it seems that the `<<<' will also append `\n' at the end of the string.

    HZ


    Right, it's saving a string into a temp file and than using that as the
    input to the command so, since every line in a POSIX text file must end
    in `\n`, `<<<` has to add one. It's equivalent to manually writing:

    tmp=$(mktemp) &&
    printf '%s\n' 'TASCJO3RJMVKWDJKXLZM' > "$tmp" &&
    md5sum < "$tmp"
    rm -f -- "$tmp"

    Regards,

    Ed.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Helmut Waitzmann@21:1/5 to All on Tue Oct 12 20:22:26 2021
    Ed Morton <mortonspam@gmail.com>:

    Right, it's saving a string into a temp file and than using that as
    the input to the command so, since every line in a POSIX text file
    must end in `\n`, `<<<` has to add one. It's equivalent to manually
    writing:

    tmp=$(mktemp) &&
    printf '%s\n' 'TASCJO3RJMVKWDJKXLZM' > "$tmp" &&
    md5sum < "$tmp"
    rm -f -- "$tmp"

    On my debian linux machine it's more like


    (
    tmp="$(mktemp)" &&
    printf '%s\n' 'TASCJO3RJMVKWDJKXLZM' > "$tmp" &&
    exec 0< "$tmp" &&
    rm -f -- "$tmp" &&
    exec md5sum
    )

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From hongyi.zhao@gmail.com@21:1/5 to Helmut Waitzmann on Tue Oct 12 20:06:06 2021
    On Wednesday, October 13, 2021 at 2:23:56 AM UTC+8, Helmut Waitzmann wrote:
    Ed Morton <morto...@gmail.com>:
    Right, it's saving a string into a temp file and than using that as
    the input to the command so, since every line in a POSIX text file
    must end in `\n`, `<<<` has to add one. It's equivalent to manually >writing:

    tmp=$(mktemp) &&
    printf '%s\n' 'TASCJO3RJMVKWDJKXLZM' > "$tmp" &&
    md5sum < "$tmp"
    rm -f -- "$tmp"
    On my debian linux machine it's more like


    (
    tmp="$(mktemp)" &&
    printf '%s\n' 'TASCJO3RJMVKWDJKXLZM' > "$tmp" &&
    exec 0< "$tmp" &&
    rm -f -- "$tmp" &&
    exec md5sum
    )

    I'm on Ubuntu 20.04.2 LTS, both the above two methods work, but why do you prefer the latter?

    HZ

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From hongyi.zhao@gmail.com@21:1/5 to Christian Weisgerber on Tue Oct 12 19:53:40 2021
    On Tuesday, October 12, 2021 at 9:30:08 PM UTC+8, Christian Weisgerber wrote:
    On 2021-10-12, hongy...@gmail.com <hongy...@gmail.com> wrote:
    But how to supply string for md5sum without '\n'?
    $ printf '%s' 'TASCJO3RJMVKWDJKXLZM' | md5

    I don't have md5 command, but instead md5sum.

    e9032994dabac08080091151380478a2

    --
    Christian "naddy" Weisgerber na...@mips.inka.de

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From hongyi.zhao@gmail.com@21:1/5 to William Unruh on Tue Oct 12 20:07:50 2021
    On Tuesday, October 12, 2021 at 9:12:10 PM UTC+8, William Unruh wrote:
    On 2021-10-12, hongy...@gmail.com <hongy...@gmail.com> wrote:
    On Tuesday, October 12, 2021 at 8:19:28 PM UTC+8, hongy...@gmail.com wrote:
    On Tuesday, October 12, 2021 at 8:03:58 PM UTC+8, hongy...@gmail.com wrote:
    On Tuesday, October 12, 2021 at 6:25:43 PM UTC+8, Ben Bacarisse wrote: >> > > "hongy...@gmail.com" <hongy...@gmail.com> writes:

    For short, as shown below:

    $ md5sum <<< 'TASCJO3RJMVKWDJKXLZM'
    e1b8fa8fe09c295811063bb76cefc337 -

    $ ipython
    In [1]: from hashlib import md5

    In [2]: my_str='TASCJO3RJMVKWDJKXLZM'

    In [3]: md5(my_str.encode('utf-8')).hexdigest()
    Out[3]: 'e9032994dabac08080091151380478a2'

    Any hints for this behavior?
    md5("TASCJO3RJMVKWDJKXLZM\n".encode('utf-8')).hexdigest()
    'e1b8fa8fe09c295811063bb76cefc337'
    Thank you for pointing this out. I confirmed it with the following command:

    $ cat -A <<< 'TASCJO3RJMVKWDJKXLZM'
    TASCJO3RJMVKWDJKXLZM$

    But how to supply string for md5sum without '\n'?
    I see. Here it is:

    $ echo -n 'TASCJO3RJMVKWDJKXLZM' | md5sum
    e9032994dabac08080091151380478a2 -

    So, it seems that the `<<<' will also append `\n' at the end of the string.

    HZ
    From man bash

    Here Strings
    A variant of here documents, the format is:

    [n]<<<word

    The word undergoes tilde expansion, parameter and variable expansion, command substitu-
    tion, arithmetic expansion, and quote removal. Pathname expansion and word splitting are
    not performed. The result is supplied as a single string, with a newline appended, to
    the command on its standard input (or file descriptor n if n is specified).


    Note the second last line.

    Thank you for pointing this out.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Geoff Clare@21:1/5 to David W. Hodgins on Thu Oct 14 13:32:11 2021
    David W. Hodgins wrote:

    On Tue, 12 Oct 2021 08:03:55 -0400, hongy...@gmail.com <hongyi.zhao@gmail.com> wrote:

    But how to supply string for md5sum without '\n'?

    $ echo -n 'TASCJO3RJMVKWDJKXLZM' |md5sum
    e9032994dabac08080091151380478a2 -

    Only if you use a version of echo that does not conform to UNIX
    requirements (even though it may conform to POSIX requirements).
    POSIX allows -n to be special, but UNIX does not. A UNIX-conforming
    echo does this:

    $ echo -n foo
    -n foo
    $

    The portable way to omit the newline is to use printf.

    --
    Geoff Clare <netnews@gclare.org.uk>

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From hongyi.zhao@gmail.com@21:1/5 to Geoff Clare on Thu Oct 14 21:41:02 2021
    On Thursday, October 14, 2021 at 8:41:05 PM UTC+8, Geoff Clare wrote:
    David W. Hodgins wrote:

    On Tue, 12 Oct 2021 08:03:55 -0400, hongy...@gmail.com <hongy...@gmail.com> wrote:

    But how to supply string for md5sum without '\n'?

    $ echo -n 'TASCJO3RJMVKWDJKXLZM' |md5sum
    e9032994dabac08080091151380478a2 -
    Only if you use a version of echo that does not conform to UNIX
    requirements (even though it may conform to POSIX requirements).
    POSIX allows -n to be special, but UNIX does not. A UNIX-conforming
    echo does this:

    $ echo -n foo
    -n foo
    $

    The portable way to omit the newline is to use printf.

    Thank you for pointing this out.

    HZ

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)