Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Can someone explain this one to me?

by Cody Pendant (Prior)
on Jun 16, 2001 at 06:01 UTC ( #88992=obfuscated: print w/replies, xml ) Need Help??

I saw this in some guy's sig, but when I asked him to explain he had to admit it wasn't his work and he didn't understand it either...

perl -le '$_="6110>374086;2064208213:90<307;55";tr[0->][ LEOR!AUBGNSTY];print'

It prints out "ALL YOUR BASE ARE BELONG TO US!" for anyone who can't be bother to run it.

Replies are listed 'Best First'.
Re: Can someone explain this one to me?
by btrott (Parson) on Jun 16, 2001 at 06:19 UTC
    This uses transliteration to map a certain set of characters to another set. The source set is comprised of the ASCII characters from '0' to '>'. If you look at the source string, you'll notice that it's comprised entirely of characters within the source set.

    The tr takes the source set and maps it onto the destination set, which is ' LEOR!AUBGNSTY'; for each character in the source set, it gets mapped to the corresponding character in the dest set. For example:

    '0' => ' ' '1' => 'L' '2' => 'E' ... '>' => 'Y'
    It's just like a substitution cipher (I think that's the right name). You can do it manually: go through the source string, the string in $_, which is
    6110>374086;2064208213:90<307;55
    and replace each character by the corresponding character in the destination set. '6' is turned into 'A', '1' is turned into 'L', '1' is turned into 'L', etc. And right there you have 'ALL'.

    Make sense? The key point here is to know what tr does, so you should read the docs for that if you're still not sure how this works.

Re: Can someone explain this one to me?
by CheeseLord (Deacon) on Jun 16, 2001 at 06:27 UTC

    Well, sure, I can try.

    The first part of the program, $_="6110>374086;2064208213:90<307;55"; simply puts a string with (seemingly) gibberish in $_. Then, the second statement, tr[0->][ LEOR!AUBGNSTY]; maps every character from 0 to > to the corresponding character in the second part of the transliteration statement ( LEOR!AUBGNSTY). Basically, the changes go like this:

    Oldnew
    '0'' '
    '1''L'
    '2''E'
    '3''O'
    '4''R'
    '5''!'
    '6''A'
    '7''U'
    '8''B'
    '9''G'
    ':''N'
    ';''S'
    '<''T'
    '>''Y'

    That range occurs because of the - in the first section of the tr statement. Anyway, after that it gets printed. (print).

    The -l on the command line forces the output to add a newline at the end of every output statement, if I'm reading perlrun right.

    Hope that helps. I'm sure if I'm wrong we'll both find out pretty soon. :)

    His Royal Cheeziness

Re: Can someone explain this one to me?
by wog (Curate) on Jun 16, 2001 at 06:36 UTC
    Although the other answers appear to explain the way this works they ignore one other trick going on here. The ASCII characters between 0 and > inclusive are 0 1 2 3 4 5 6 7 8 9 : ; < = and >. You'll notice that the > character was used in the example code, and not the = charactor, though if you do a one-to-one mapping it looks like = should have been used, and > would be left over. The reason the could given still works is another bit of magic -- when tr's replacement list is shorter then its source list it duplicates the last item of the replacement list to match, thus the Y at the end correspondes to both = and >. Except with some /something options: see perlop for more information, of course.

      Thanks a lot for that everyone, that's certainly taught me something about tr// that I didn't know. The only way I knew how to obfuscate it was to do a y// instead...

        For the best obfu using tr I have ever seen see Line Noise

        cheers

        tachyon

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: obfuscated [id://88992]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2020-07-04 10:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?