Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Crypt() usage

by fionbarr (Friar)
on Jul 28, 2016 at 16:04 UTC ( #1168738=perlquestion: print w/replies, xml ) Need Help??

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.
      Excellent point....thanks
Re: Crypt() usage
by stevieb (Canon) on Jul 28, 2016 at 16:07 UTC

    Appears to be:


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


    $ perl -E 'say crypt "string", "sa"' saQ9i9dEI8LLA
      Looks good, thank you
Re: Crypt() usage
by afoken (Canon) 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: (<-- link is missing in that thread). Relevant quote:

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


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

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1168738]
Front-paged by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2022-05-18 15:51 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (71 votes). Check out past polls.