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

archival storage

by mr_mischief (Monsignor)
on Jul 06, 2012 at 00:28 UTC ( #980191=perlmeditation: print w/replies, xml ) Need Help??

I've been programming in Perl nearly half my life. I don't see any reason I won't be into the future. It's always been a handy companion. Some of the code I've written I've kept handy for years.

I'm also a big believer in the freedom of the people, and in the right to benefit from ingenuity. Some of the major events that have happened during my lifetime that people here understand much better than the public at large are the development of digital encryption and the battles such as Ron Rivest and Phil Zimmerman had to go through unnecessarily. They've given us the world we know today and helped enable the careers many of us enjoy.

A few years back I answered a challenge for showing short crypto implementations in encryption golf (one time pad). Although ikegami bested me I've always considered that one of my favorite nodes and threads here. Well, my new implementation is shorter than my old one. It's not shorter than ikegami's but I decided that I was interested in not using command-line flags and in aesthetics.

I know ITAR has been relaxed and all and one-time pad isn't exactly a full public key system. It can be a darn good, mathematically infallible shared key portion of a hybrid scheme though. If I lose the media, I've got much bigger problems. It's part statement, part fun, part tribute to the crypto folks, and part tribute to Perl.


That's three characters less than before, and I think it looks pretty good. I especially like it in Liberation Mono typeface. I mentioned before it was a tattoo-worthy size. I think from now on I can always think of this code as part of me.

Replies are listed 'Best First'.
Re: archival storage ($/--)
by tye (Sage) on Jun 29, 2016 at 16:49 UTC

    Note that your tatoo requires that the string "-1" not appear in the first file (or for it to be used as the delimiter between the body and the 'pad' in a single file). At least in my testing...

    - tye        

      Thanks for the heads up. It also seems the string "-1" in the second file shortens what is worked on there and leaves the rest as plaintext.

      This would be fixed by using undef$/; rather than $/--;. However, this is supposed to be using the record size setting mentioned in perlvar rather than stringification. According to perlvar, for 5.22 and 5.24:

      Trying to set the record size to zero or less is deprecated and will cause $/ to have the value of "undef", which will cause reading in the (rest of the) whole file.
      ... and using $/-- does leave the variable with a numeric value of -1. In a suitably old version of perlvar (that for 5.10.1), the text reads:
      Trying to set the record size to zero or less will cause reading in the (rest of the) whole file.
      ... and in perl 5.10.1 we also get that the numeric value has been successfully set to -1.
      perl -e '$/--; printf "%d\n", $/; printf "%f\n", $/; $foo = <>; $bar = + <>; $_ = $foo ^ $bar; print $_ . "\n"' in1 in2 -1 -1.000000 '1
      where in1 is:
      and in2 is:
      while the proper output for the important line is:

      This appears to my eyes to be a bug in perl or the documentation, but in the bigger picture is what happens when one pushes into dark corners in the name of cleverness.


        works for me. The \ character is important as it isn't being a number that causes $/ to be interpreted as a record length, but it being a reference to a scalar (containing what gets interpreted as a number).

        - tye        

      String "-1" is OK, the number -1 is the problem. Easily fixed by (a bit longer)
      Error in my test. Please ignore.

      ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2023-01-31 23:09 GMT
Find Nodes?
    Voting Booth?

    No recent polls found