Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

I am such a geek

by K_M_McMahon (Hermit)
on Jan 21, 2005 at 14:55 UTC ( [id://423988]=obfuscated: print w/replies, xml ) Need Help??

I kept looking at this stuff on here and thought that it was really cool. Last night I "went to bed" early (laptop in hand) and 2.5 hours later I had this code ready. This is my first attempt, be gentle.
#!/usr/bin/perl -w use strict;open my ($f ) ,$0;local $/;my $a = <$f> ; $a=~s/\s+//g ;$a=~/_{2}(.+$)/;$a= $1;while($a=~m/(.{13})$/){unshift(@;,$1) ;$a=~s/.{13}$//;}foreach (@; ){for (my $i=0;$i<128 ;$i++){print chr ($i) if (crypt (chr($i),$_) eq $_);}} __END__ oyINpLQGuRwwCe.P5IVph0xPw T8R3/s500K0YUw3dVujjlsowlo EfUEms7OOkp3M5fH78hGOgxsJ U406Ru7Bl6B/HI9LcpZLPXsw jk6eGkhSThneVa2YTL/TWOm H0HSsMn146/lpvNCANYDjV cvRTejnJ4wtbAHzsAuira mYhutHKecx/zwh61iLpt h3SRAXP.lotAU1cwerQ H.pgVvqzLOuTmagpGL x/vApQsuo2Xxmv/.i ZdyXFEbczWhScflJ Ee2CPpMzZZLfH3p wZSs5Devx6zjZc Rmn5olZiat262 RPseOlOid/QO ISSPLXdIANM JTcJp2A.bt 6MSA7QlfH IMdy97lW 16pRLKa H5pdLD qUtK6 R2aO cQV ut o
update: changed __DATA__ to __END__ since that is what I really meant.

Replies are listed 'Best First'.
Re: I am such a geek
by Tanktalus (Canon) on Jan 21, 2005 at 16:01 UTC

    Bonus points for "use strict;" :-)

Re: I am such a geek
by wolfger (Deacon) on Jan 21, 2005 at 15:36 UTC

    The layout of the code; it looks like it should be a picture of something, but I can't make out what it is. Otherwise, nice job. Welcome to geekdom. ;-)


    --
    Linux, sci-fi, and Nat Torkington, all at Penguicon 3.0
    perl -e 'print(map(chr,(0x4a,0x41,0x50,0x48,0xa)))'
      Slightly modified to give it more consistent look!
      #!/usr/bin/perl -w use strict;open my($f),$0;local$/;my$a= <$f> ; $a=~s/\s+//g ;$a=~/_{2}(.+$)/ ; $a = $1 ;while( $a=~m /(.{13})$/) {unshift( @;, $1 );$a=~s/.{13}$//;} foreach (@;){for (my $i=0;$i<128; $i++){print chr($i) if (crypt( chr($i),$_) eq $_);}}__END__ oyINpLQGuRwwCe.P5IVph0xPw T8R3/s500K0YUw3dVujjlsowlo EfUEms7OOkp3M5fH78hGOgxsJ U406Ru7Bl6B/HI9LcpZLPXsw jk6eGkhSThneVa2YTL/TWOm H0HSsMn146/lpvNCANYDjV cvRTejnJ4wtbAHzsAuira mYhutHKecx/zwh61iLpt h3SRAXP.lotAU1cwerQ H.pgVvqzLOuTmagpGL x/vApQsuo2Xxmv/.i ZdyXFEbczWhScflJ Ee2CPpMzZZLfH3p wZSs5Devx6zjZc Rmn5olZiat262 RPseOlOid/QO ISSPLXdIANM JTcJp2A.bt 6MSA7QlfH IMdy97lW 16pRLKa H5pdLD qUtK6 R2aO cQV ut o
      -Kevin
      It could be half a carrot?
      I couldn't think of what I wanted it to look like, so I just kind of made it cascade from big to small. Thanx for the compliment! -Kevin
Re: I am such a geek
by jdalbec (Deacon) on Jan 22, 2005 at 18:25 UTC
    This is very slow on Mac OS X 10.3.
    real 14m36.335s user 13m33.220s sys 0m4.200s
    From the Mac OS X 10.3 crypt() man page:
    The first argument to crypt() is a null-terminated string, typically a user's typed password. The second is in one of two forms: if it begins with an underscore ("_") then an extended format is used in interpreting both the key and the setting, as outlined below.

    Extended crypt: The key is divided into groups of 8 characters (the last group is null- padded) and the low-order 7 bits of each each character (56 bits per group) are used to form the DES key as follows: the first group of 56 bits becomes the initial DES key. For each additional group, the XOR of the encryption of the current DES key with itself and the group bits becomes the next DES key.

    The setting is a 9-character array consisting of an underscore followed by 4 bytes of iteration count and 4 bytes of salt. These are encoded as printable characters, 6 bits per character, least significant character first. The values 0 to 63 are encoded as "./0-9A-Za-z". This allows 24 bits for both count and salt.

    Traditional crypt: The first 8 bytes of the key are null-padded, and the low-order 7 bits of each character is used to form the 56-bit DES key.

    The setting is a 2-character array of the ASCII-encoded salt. Thus only 12 bits of salt are used. count is set to 25.
    I believe the iteration count works out to 6639540 in the first crypt() call.

    Update: My point is that since the first crypted string starts with "_" it's triggering this extended crypt() algorithm that takes (in this case) about 260,000 times as long as the traditional crypt() algorithm.

    A workaround is to insert any additional character (other than "_", of course) at the beginning of the first line after the __END__.

    You do realize that the underscore in /_{2}(.+$)/ matches the underscores before END and not the underscores after it, right?

      Well, the core at the end is running through over 3,000 calculations, so it may take a little time depending on your CPU power. It runs pretty quick on my 1.7Ghz.
Re: I am such a geek
by Dru (Hermit) on May 16, 2006 at 04:44 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: obfuscated [id://423988]
Approved by wolfger
Front-paged by wolfger
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-19 19:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found