md5 wrongness?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ron Johnson

    md5 wrongness?


    Why do Python's md5 and GNU md5sum produce differing results?

    $ md5sum --version
    md5sum (GNU coreutils) 5.97

    $ echo snagglefrob | md5sum
    f842244d79af85b 457811091319d85 ff -
    $ echo 'snagglefrob' | md5sum
    f842244d79af85b 457811091319d85 ff -
    $ echo "snagglefro b" | md5sum
    f842244d79af85b 457811091319d85 ff -


    $ python
    Python 2.4.4 (#2, Aug 16 2007, 02:03:40)
    [GCC 4.1.3 20070812 (prerelease) (Debian 4.1.2-15)] on linux2
    Type "help", "copyright" , "credits" or "license" for more information.
    >>import md5
    >>s = md5.new()
    >>s.update('sna gglefrob')
    >>s.hexdigest ()
    '9eb2459fcdd9f9 b8a9fef7348bcac 933'

    --
    Ron Johnson, Jr.
    Jefferson LA USA

    %SYSTEM-F-FISH, my hovercraft is full of eels
  • Erik Max Francis

    #2
    Re: md5 wrongness?

    Ron Johnson wrote:
    $ echo "snagglefro b" | md5sum
    f842244d79af85b 457811091319d85 ff -
    >
    $ python
    Python 2.4.4 (#2, Aug 16 2007, 02:03:40)
    [GCC 4.1.3 20070812 (prerelease) (Debian 4.1.2-15)] on linux2
    Type "help", "copyright" , "credits" or "license" for more information.
    >>>import md5
    >>>s = md5.new()
    >>>s.update('sn agglefrob')
    >>>s.hexdigest( )
    '9eb2459fcdd9f9 b8a9fef7348bcac 933'
    echo inserts a newline, your Python snippet doesn't.

    % echo -n "snagglefro b" | md5sum
    9eb2459fcdd9f9b 8a9fef7348bcac9 33 -

    --
    Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/
    San Jose, CA, USA && 37 18 N 121 57 W && AIM, Y!M erikmaxfrancis
    Granted that I must die, how shall I live?
    -- Michael Novak

    Comment

    • John Machin

      #3
      Re: md5 wrongness?

      On Nov 24, 1:34 pm, Ron Johnson <ron.l.john...@ cox.netwrote:
      Why do Python's md5 and GNU md5sum produce differing results?
      They don't differ. Try feeding them the same input:
      >>import md5
      >>md5.new('snag glefrob').hexdi gest()
      '9eb2459fcdd9f9 b8a9fef7348bcac 933'
      >>md5.new('snag glefrob\n').hex digest()
      'f842244d79af85 b457811091319d8 5ff'
      >>>
      >
      $ md5sum --version
      md5sum (GNU coreutils) 5.97
      >
      $ echo snagglefrob | md5sum
      f842244d79af85b 457811091319d85 ff -
      $ echo 'snagglefrob' | md5sum
      f842244d79af85b 457811091319d85 ff -
      $ echo "snagglefro b" | md5sum
      f842244d79af85b 457811091319d85 ff -
      >
      $ python
      Python 2.4.4 (#2, Aug 16 2007, 02:03:40)
      [GCC 4.1.3 20070812 (prerelease) (Debian 4.1.2-15)] on linux2
      Type "help", "copyright" , "credits" or "license" for more information.>>i mport md5
      >s = md5.new()
      >s.update('snag glefrob')
      >s.hexdigest( )
      >
      '9eb2459fcdd9f9 b8a9fef7348bcac 933'
      >
      --
      Ron Johnson, Jr.
      Jefferson LA USA
      >
      %SYSTEM-F-FISH, my hovercraft is full of eels

      Comment

      • Ayaz Ahmed Khan

        #4
        Re: md5 wrongness?

        John Machin wrote:
        On Nov 24, 1:34 pm, Ron Johnson <ron.l.john...@ cox.netwrote:
        >Why do Python's md5 and GNU md5sum produce differing results?
        >
        They don't differ. Try feeding them the same input:
        >
        >>>import md5
        >>>md5.new('sna gglefrob').hexd igest()
        '9eb2459fcdd9f9 b8a9fef7348bcac 933'
        >>>md5.new('sna gglefrob\n').he xdigest()
        'f842244d79af85 b457811091319d8 5ff'
        >>>>
        Or, alternatively:

        $ echo -n snagglefrob | md5sum
        9eb2459fcdd9f9b 8a9fef7348bcac9 33 -

        --
        Ayaz Ahmed Khan

        Comment

        • Ron Johnson

          #5
          Re: md5 wrongness?

          On 11/24/07 02:27, Ayaz Ahmed Khan wrote:
          John Machin wrote:
          >On Nov 24, 1:34 pm, Ron Johnson <ron.l.john...@ cox.netwrote:
          >>Why do Python's md5 and GNU md5sum produce differing results?
          >They don't differ. Try feeding them the same input:
          >>
          >>>>import md5
          >>>>md5.new('sn agglefrob').hex digest()
          >'9eb2459fcdd9f 9b8a9fef7348bca c933'
          >>>>md5.new('sn agglefrob\n').h exdigest()
          >'f842244d79af8 5b457811091319d 85ff'
          >
          Or, alternatively:
          >
          $ echo -n snagglefrob | md5sum
          9eb2459fcdd9f9b 8a9fef7348bcac9 33 -
          Thanks to all. I knew there had to be operator error, but I
          couldn't figure out where...

          --
          Ron Johnson, Jr.
          Jefferson LA USA

          %SYSTEM-F-FISH, my hovercraft is full of eels

          Comment

          Working...