in reply to One-liner to rule them all...

Rot-N ciphers are pretty trivial in Perl, as is passing a string to the shell; hardly fodder for "ruling them all". But if you could do it easily in other languages, why are you looking for a Perl solution? What does the solution you worked out in some other language lack that you need the Perl version to do for you?

It's fine to be new. It's fine to be curious as to how to accomplish something. It's great that you want to learn (I'm assuming). But why let us have all the fun when it's something you could do (and learn from) yourself?

The tools you will need are tr/// (discussed in perlop), system, and the -e command line switch, discussed in perlrun. A look at perlintro may also be helpful to you.

Since you know ahead of time what the rotation will be, you won't need to deal with dynamic construction of the transliteration. It's as straight-forward as Rot-13. After a small amount of searching you would have arrived here.


Dave

Replies are listed 'Best First'.
Re^2: One-liner to rule them all...
by fosskers (Initiate) on Jul 11, 2012 at 09:51 UTC

    What I have so far after doing some research:

    tr/a-z/x-za-w/

    Now just to feed this into system() call... or backticks?
    Also, to answer your questions:
    1. I'd like this in perl since perl is essentially guaranteed to be installed on a *nix system.
    2. Learning is great and I love doing it. Perl seems kinda cool, from what I've seen since yesterday.
    3. perlop held many answers :)

      I'm assuming that you're going to set up your one-liner such that the target string is held in @ARGV (A special variable documented in perlvar). That's one simple possibility. So $ARGV[0] will hold the first string passed on the command line. To bind your transliteration operator to $ARGV[0] you use the =~ operator like this: $ARGV[0] =~ tr/a-z/x-za-w/.

      Now $ARGV[0] holds the transliterated string, and all you need to do is pass it to system, just as you would pass any parameter to any function.

      If your target string contains whitespace you will have to wrap it in quotes that your shell respects.

      I still don't understand why this is useful. It's not really a form of security, and if the goal is to hide keystrokes, it is easy to unravel. Plus any system call will still show up in the process list.


      Dave

        Forgive my tardy reply.
        I've got it to this:
        perl -e "system(mystring =~ tr/a-z/x-za-w/r)"
        Where `mystring` is a hard-coded string.
        So I have a working solution, but is there anyway to obfuscate it further?
        To answer your question, I should have been honest from the beginning. I wanted this one-liner to do something cheeky... it's in a section of the README of the software I'm working on, as a treat for the dedicated reader.