http://qs1969.pair.com?node_id=1168738

fionbarr has asked for the wisdom of the Perl Monks concerning the following question:

Is the 'crypt' function identical on Windows and *nix platforms?

Replies are listed 'Best First'.
Re: Crypt() usage
by Athanasius (Archbishop) on Jul 28, 2016 at 16:28 UTC

    Hello fionbarr,

    Yes, but apparently you can’t rely on the crypt function being available under Windows. From perlport#crypt:

    May not be available if library or source was not provided when building perl. (Win32)

    This may be important to bear in mind if your script is intended to run on platforms over which you have no direct control.

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

      That warning is well over 20 years old. I doubt if there is any perl version for Windows where crypt isn't properly implemented.

      .. and, related to that, I wonder if the different line-endings (in Linux and Windows) might result in a different crypt result. I only have Windows here at work, so I cannot test this hypothesis right now.

      Alex / talexb / Toronto

      Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

        Line endings should only be an issue in I/O. By default perl strings use a single newline character as a record separator. PerlIO translates between this and whatever your OS requires. When processing files from another OS, specify the required translation on the open statement.
        Bill
      Excellent point....thanks
Re: Crypt() usage
by stevieb (Canon) on Jul 28, 2016 at 16:07 UTC

    Appears to be:

    Windows:

    c:\> perl -E "say crypt 'string', 'sa'" saQ9i9dEI8LLA

    Ubuntu:

    $ perl -E 'say crypt "string", "sa"' saQ9i9dEI8LLA
      Looks good, thank you
Re: Crypt() usage
by afoken (Chancellor) on Jul 30, 2016 at 09:03 UTC
    Is the 'crypt' function identical on Windows and *nix platforms?

    No. See the thread starting at Re^2: replacing password in a file. Short: Many implementations use DES, but the libc is free to choose any other algorithm: http://pubs.opengroup.org/onlinepubs/9699919799/functions/crypt.html (<-- link is missing in that thread). Relevant quote:

    The crypt() function is a string encoding function. The algorithm is implementation-defined.

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)