I thought I'd take a regex approach.
-v (japh)#!/usr/bin/perl do{print(chr($c+=$1>=1000&&1000-$1||$1*1))while/\G(\d{4})/g}for<DATA>; __DATA__ 010600111002000110840065 001300010005101210030013 108200801011001310061076 007210070002000810060013 110200000000000000001002
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: japh with re
by TheEnigma (Pilgrim) on Aug 19, 2004 at 01:15 UTC | |
Not just for what it does and how it does it, but because it's probably the first obfuscated code I've been able to figure out on my own. However, some things were just assumptions or guesses. So, in an attempt to help me really wrap my mind around this, build up my hubris, and learn something; I would appreciate it if (a|some) more knowledgable monk(s?) could (explain|verify) the following magic: 1) I think I figured this one out. At first I was confused about the 4 digit sequences. I was thinking the ones that started with a zero were octal, and was coming up with an unintelligible character sequence. But then I recalled something about the default match delimiters acting like double quotes. I read elsewhere on this site that a "number" like 0100 is octal, but "0100" is decimal. So apparently the captured data in the match effectively is double quoted, in this case insuring the numbers are decimal? 2) I seem to recall reading, but can't find it anywhere right now; that in an expression like it's value is the last thing evaluated. That expression can be re-written as so if $1>=1000, it has to evaluate 1000-$1, and can stop there since it's satisfied the ||, and the value of the expression is 1000-$1. If $1<1000 it won't bother with 1000-$1, and then evaluate $1*1, so the value of the expression is $1. At least, from my reading of the description of associativity, that's the order in which I presume it evaluates the terms. So, I take it, one of the ramifications of associativity is determining the ultimate value of a complex expression? 3) I've never seen a do{} with the while inside the braces, is this the same effect as having it immediately after them? 4) I've never seen a block before a for. Is this a similar idiom to reversing an if and letting you do this? 5) I copied the code into my text editor and put spaces in between each 4 digit sequence of the data while I was trying to figure it out. After I figured it out, I saved it and ran it, but it didn't work. I had to remove the spaces. The \G saves your place in the data, but it doesn't act like an anchor does it? I mean, if there's now a space before the next set of 4 digits, shouldn't it just skip the space to get to the digits? It didn't seem to. Sorry to go on so long, but I've found this to be a site of great knowledge, and am hoping to learn much here. TheEnigma | [reply] [d/l] [select] |
by Velaki (Chaplain) on Aug 19, 2004 at 22:01 UTC | |
These explanations refer to the numbered items in the "above" post. Hope they help. :-) | [reply] [d/l] [select] |