Previous Thread
Next Thread
Print Thread
Rate Thread
#68813 03/27/2001 2:02 PM
Joined: Feb 1999
Posts: 1,379
cal
Offline
Programmer
Programmer
Offline
Joined: Feb 1999
Posts: 1,379
Code
code:
Explain how this code works and impress me.

Just a thought smile

(contest not open to mark or charles :p)

Sponsored Links
#68814 03/27/2001 2:20 PM
Joined: Mar 2000
Posts: 21,079
Likes: 3
I type Like navaho
I type Like navaho
Joined: Mar 2000
Posts: 21,079
Likes: 3
it is handy for stretching the browser screen for anybody running at less than 2000x1600...

Did I win? laugh


- Allen wavey
- What Drives You?
#68815 03/27/2001 2:43 PM
Joined: Feb 1999
Posts: 1,379
cal
Offline
Programmer
Programmer
Offline
Joined: Feb 1999
Posts: 1,379
close allen laugh

Just a thought smile

#68816 03/27/2001 5:22 PM
Joined: Mar 2000
Posts: 615
Member
Member
Offline
Joined: Mar 2000
Posts: 615
Disable smilies in that post wink

#68817 03/27/2001 6:58 PM
Joined: Feb 2000
Posts: 4,625
Member
Member
Offline
Joined: Feb 2000
Posts: 4,625
Code
code:
[/QUOTE]

Sponsored Links
#68818 03/27/2001 7:10 PM
Joined: Mar 2000
Posts: 3,594
Moderator / Template Diva
Moderator / Template Diva
Offline
Joined: Mar 2000
Posts: 3,594
Does it draw lines?

---Skorpion


Don't put that signature in your mouth! You don't know where it's been!
#68819 03/27/2001 7:26 PM
Joined: Mar 2000
Posts: 615
Member
Member
Offline
Joined: Mar 2000
Posts: 615
No, it prints 'just another perl hacker'.
now, understanding how it works... wink

#68820 03/27/2001 7:31 PM
Joined: Feb 2000
Posts: 4,625
Member
Member
Offline
Joined: Feb 2000
Posts: 4,625
WOW. I'd have to be here all day to actually type how everything in it works. tipsy

#68821 03/27/2001 7:45 PM
Joined: Feb 2000
Posts: 61
Member
Member
Offline
Joined: Feb 2000
Posts: 61
Yeah, there's lots of stuff going on in line #2. laugh

I don't understand why a couple things in there work the way they do. The rest is obfuscated, but is not that hard to decipher.

Really, you want an analysis of that? See, I have a flu. Only important thing on the to-do list today is "drink lots of fluids".

Is there a prize?


"Waffles are nothing more than a vehicle for butter and syrup" - Dr. Clayton Forrester
#68822 03/28/2001 12:50 AM
Joined: Sep 2000
Posts: 755
P.I.T.A. / Programmer
P.I.T.A. / Programmer
Offline
Joined: Sep 2000
Posts: 755
Quote
quote:
tipsy


"Annnnnnnndd now, opening for Iron Maiden...... WYLD STALLYNS!!!" --Bill S. Preston, Esquire and Ted "Theodore " Logan
Sponsored Links
#68823 03/28/2001 2:15 AM
Joined: Feb 2000
Posts: 61
Member
Member
Offline
Joined: Feb 2000
Posts: 61
No one yet? OK, here's it is:

Separate the lines of code:

Code
code:

****************
Line 1 creates an array containing 24 elements.

@a = (0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23);

****************
Line 2 uses the special variable $: which happens to contain " n-", reverses it and sets $b equal the first character. This is the same as:

$b = '-';

****************
Line 3 is equivalent to:

$a = '$b=3';

****************
Line 4 is puzzling. I think I know how it works, but not sure why. First thing is to group it according to operator precedence:

$c = ord ($; + $[ - 2 + (ord $b)) ;

(ord $b) equals 45
$[ is another special variable, default value is zero
$; is another special variable, equal to the string "43" - (that's a single ASCII character octal 043)

Substituting:

$c = ord ( "43" + 0 - 2 + 45 );

For some reason I do not understand, the "43" character is evaluated as zero. I think. So we get:

$c = ord ( 0 + 0 - 2 + 45 );
$c = ord ( 43 );

Ord wants a string, so the number 43 is converted to the string "43", then ord returns the numeric ASCII value of '4', which is 52.

$c = ord '43';
$c = 52 ;

****************
Line 5 is easy. See line 2, and substitute.

$b = ord '-';
$b = 45;

****************
Line 6 is also easy. Take the string in $a, split it into a list of single characters, and take the numeric ASCII value of the first element (which happens to be the character '$').

$a = ord ('$');
$a = 36

****************
Line 7 is even easier. Add one to the special variable $[, which is zero.

$d = 1;

****************
Line 8 has another special variable. Good thing I have a perl book by O'Reilly:

$b = 31 - ord $; ;
$b = 31 - 28;
$b = 3;

****************
Line 9. Tricky use of the q//

$e = ( ord "@" ) - ord ";" ;
$e = 64 - 59
$e = 5

****************
Line 10. Here's the other line that puzzles me. First, add some spaces so it makes sense:

$f = 1 + ( length (@a) * 3 );

I know this evaluates to 7. Not sure why length(@a) is equal to 2. Maybe perl uses a 16 bit number as an array reference and the length function counts these bytes. Dunno.

$f = 7;

****************
Line 11. Now that I know $f, this line is easy:

$g = $f + ($d * 2);
$g = 9;

****************
Line 12. Takes the number of elements in @a divides by two and adds 1:

$h = 1 + ( 24 / 2 )
$h = 13

****************
So far, all the program has done is the following:
@a=(0..23);
$a=36;
$b=3;
$c=52;
$d=1;
$e=5;
$f=7;
$g=9;
$h=13;

****************
Line 13: A 24 element array is defined. This is the encrypted message.

****************
Line 14:

14a. @b = map {
14b. s!([a-h])!$$1!gi;
14c. 1 while (
14d. s!(-?$[a-h])(-?$[a-h])!$1+$2!gi
14e. );
14f. $_ = eval;
14g. } @c;

This takes the encrypted message in @c, which is an array of 24 strings containing the letters a-f in various combinations, and some punctuation. Turns it into an array of numbers.

14b inserts a "$" in front of every letter ( deg becomes $d$e$g )
14d adds the '+' character ( $d$e$g becomes $d+$e+$g )
14f evaluates the expression. ($d+$e+$g becomes 1+5+9 which equals 15 )

****************
15. The message is almost decoded. So finish decoding it and print. Heres the line with whitespace added for readability.

print map{ chr( $_ + 80 + shift @b ) } @a;

Not hard to figure that one out. For each element in @a, $_ is loaded with that element, then the following expression is evaluated:

chr( $_ + 80 + shift @b )

The result of the map function is an array, and is passed to the print command.

This line has the same end result:

for ( $n = 0; $n < 24; $n++) {
print chr( $a[$n] + 80 + $b[$n] );
}

****************
Thanks Cal, that was fun to figure out. Learned alot about using ord and map.

If you've read this far, you'll like The Fifth Annual Obfuscated Perl Contest Winners . Unfortunately, the original site is no more, but the pages are still cached on Google.

[ March 28, 2001: Message edited by: el84 ]


"Waffles are nothing more than a vehicle for butter and syrup" - Dr. Clayton Forrester
#68824 03/28/2001 3:00 AM
Joined: Feb 1999
Posts: 1,379
cal
Offline
Programmer
Programmer
Offline
Joined: Feb 1999
Posts: 1,379
Very Good!

The way it works basically, i to combine the numbers from two arrays (@a and @b) to get the ascii values of the characters. Since @a is just the numbers 0 to 23, all the real work is done by @b.

Now, the variables $a to $h are loaded with various values (mostly small primes). The @c array is then loaded with expressions which evaluate to the numbers needed to make @b. If ($a+$b)-$c is needed to make the value (and we can make any value since we chose good primes) then it's written to @c as "(ab)-c".A quick regex later and we can add $'s before each letter and +'s where nessacery. Now eval'ing these into @b give us our second list.

Line 3 ($a=q;$b=3; wink is meant to throw you. At first glane it looks like $a='q'; $b=3; which would override the previous value of $b. It actually just tricky use of the single quotish operator using a semi comma to delimit.

Right. Now for something slightly different:

Code
code:

Just a thought smile


Link Copied to Clipboard
Donate Today!
Donate via PayPal

Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.

Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.
Recommended Hosts
We have personally worked with and recommend the following Web Hosts:
Stable Host
bluehost
InterServer
Visit us on Facebook
Member Spotlight
isaac
isaac
California
Posts: 1,157
Joined: July 2001
Forum Statistics
Forums63
Topics37,573
Posts293,925
Members13,849
Most Online5,166
Sep 15th, 2019
Today's Statistics
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
Top Posters
AllenAyres 21,079
JoshPet 10,369
LK 7,394
Lord Dexter 6,708
Gizmo 5,833
Greg Hard 4,625
Top Posters(30 Days)
Top Likes Received
isaac 82
Gizmo 20
Brett 7
WebGuy 2
Morgan 2
Top Likes Received (30 Days)
None yet
The UBB.Developers Network (UBB.Dev/Threads.Dev) is ©2000-2024 VNC Web Services

 
Powered by UBB.threads™ PHP Forum Software 8.0.0
(Preview build 20221218)