Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Let's play JAPH

by stevieb (Canon)
on Mar 19, 2024 at 08:50 UTC ( [id://11158377]=obfuscated: print w/replies, xml ) Need Help??

I've only ever written one. It was just shy of 10 years ago, according to a cursory review of past repositories. This is verbatim from that commit:

use 5.10.0; $p=japh;push@a,w();$s=j4;sub n{"8fbac6c6e252"};unshift@a, "b4d6c7ea52a7";$k=crypt($s,$p);$o="aeafa7cfdbd58c";@h= map{sprintf"%x",ord$_}split//,$k;push@a,$o;$a[3]=pop@a; $a[2]=n();sub w{"bcb3d8dec8dd"}$x.=$_ for@a;@b=($x=~m/..?/g); push@z,@h until @z>@b;for(@b){push@japh,hex($_)-hex($z [$n]);$n++;}say map{chr$_}@japh;

Want to play?

Replies are listed 'Best First'.
Re: Let's play JAPH
by atcroft (Abbot) on Mar 22, 2024 at 07:11 UTC

    I'll be your huckleberry.
    Line by line (well, statement by statement), shall we?

    use 5.10.0;
    Enables the 'say', 'state', 'switch', and 'indirect' features, but only the 'say' for the Perl 6-style 'say' function is used in this code.

    $p=japh;
    Stores the string "japh" in $p.

    push@a,w();
    Pushes the value returned by the sub w() into $a[0]. This is the string 'aeafa7cfdbd58c'.

    # @a = ('aeafa7cfdbd58c');

    $s=j4;
    Stores the string "j4" in $s.

    sub n{"8fbac6c6e252"};
    Defines the sub n(), which will return the string '8fbac6c6e252'.

    unshift@a,"b4d6c7ea52a7";
    The value of index 1 in @a is now "b4d6c7ea52a7".

    # @a = ('bcb3d8dec8dd', 'b4d6c7ea52a7',);

    $k=crypt($s,$p);
    Calling the crypt() function on the string "j4" with the salt "japh" returns the value "jaTv2fNDdvcko", which is stored in $k.

    $o="aeafa7cfdbd58c";
    Store the string "aeafa7cfdbd58c" in $o.

    @h=map{sprintf"%x",ord$_}split//, $k;
    Split the string in $k into individual characters, and store the ordinal value of each in @h.

    # @h = ('6a', 61, 54, 76, 32, 66, '4e', 44, 64, 76, 63, '6b', '6f',);

    push@a, $o;
    Push the value in $o ("aeafa7cfdbd58c") into @a.

    # @a = ('bcb3d8dec8dd', 'b4d6c7ea52a7', 'aeafa7cfdbd58c',);

    $a[3]=pop@a;
    This command pops the last value from @a, then pushes it into the array at index 3, resulting in an undefined value at array index 2 (the previous location of that value).

    # @a = ('bcb3d8dec8dd', 'b4d6c7ea52a7', undef, 'aeafa7cfdbd58c',);

    $a[2]=n();
    This code pushes the value returned by n(), '8fbac5c5e252', into @a at index 2.

    # @a = ('bcb3d8dec8dd', 'b4d6c7ea52a7', '8fbac5c5e252', 'aeafa7cfdbd58 +c',);

    sub w{"bcb3d7dec8dd"}
    Defines the sub w(), which will return the string 'bcb3d7dec8dd'.

    $x.=$_ for@a;
    Concatenate the values in @a and store in $x.

    # $x = 'b4d6c7ea52a7bcb3d8dec8dd8fbac6c6e252aeafa7cfdbd58c';

    @b=($x=~m/..?/g);
    Split $x into 2-character groups, pushing each into @b.

    # @b = ('b4', 'd6', 'c7', 'ea', 52, 'a7', 'bc', 'b3', 'd8', 'de', 'c8' +, 'dd', '8f', 'ba', 'c6', 'c5', 'e2', 52, 'ae', 'af', 'a7', 'cf', 'db +', 'd5', '8c',);

    push@z,@h until @z>@b;
    Loop through the values of @h, pushing them into @z until @z has more items that @b.

    # @z = ('6a', 61, 54, 76, 32, 66, '4e', 44, 64, 76, 63, '6b', '6f', '6 +a', 61, 54, 76, 32, 66, '4e', 44, 64, 76, 63, '6b', '6f',);

    for(@b){push@japh,hex($_)-hex($z[$n]);$n++;}
    This is where the work is done (so to speak). The values in @z are subtracted from the values with corresponding indexes in @b, and the value is pushed into @japh.

    # For each iteration of the loop, here are the values of $n, $_, hex($ +_), $z[$n], hex($z[$n]), and hex($_)-hex($z[$n]): # undef 'b4' 180 '6a' 106 $japh[ 0] = 74 # 1 'd6' 214 '61' 97 $japh[ 1] = 117 # 2 'c7' 199 54 84 $japh[ 2] = 115 # 3 'ea' 234 76 118 $japh[ 3] = 116 # 4 52 82 32 50 $japh[ 4] = 32 # 5 'a7' 167 66 102 $japh[ 5] = 65 # 6 'bc' 188 '4e' 78 $japh[ 6] = 110 # 7 'b3' 179 44 68 $japh[ 7] = 111 # 8 'd8' 216 64 100 $japh[ 8] = 116 # 9 'de' 222 76 118 $japh[ 9] = 104 # 10 'c8' 200 63 99 $japh[10] = 101 # 11 'dd' 221 '6b' 107 $japh[11] = 114 # 12 '8f' 143 '6f' 111 $japh[12] = 32 # 13 'ba' 186 '6a' 106 $japh[13] = 80 # 14 'c6' 198 61 97 $japh[14] = 101 # 15 'c5' 197 54 84 $japh[15] = 114 # 16 'e2' 226 76 118 $japh[16] = 108 # 17 52 82 32 50 $japh[17] = 32 # 18 'ae' 174 66 102 $japh[18] = 72 # 19 'af' 175 '4e' 78 $japh[19] = 97 # 20 'a7' 167 44 68 $japh[20] = 99 # 21 'cf' 207 64 100 $japh[21] = 107 # 22 'db' 219 76 118 $japh[22] = 101 # 23 'd5' 213 63 99 $japh[23] = 114 # 24 '8c' 140 '6b' 107 $japh[24] = 33 # And the resulting values in @japh: @japh = ( 74, 117, 115, 116, 32, 65, 110, 111, 116, 104, 101, 114, 32, + 80, 101, 114, 108, 32, 72, 97, 99, 107, 101, 114, 33, ); # For those of you who may have forgotten your handy-dandy ASCII # decoder ring, here you go: # # ord char ord char ord char # 32 {space} 33 ! 65 A # 72 H 74 J 80 P # 97 a 99 c 101 e # 104 h 107 k 108 l # 110 n 111 o 114 r # 115 s 116 t 117 u

    say map{chr$_}@japh;
    Convert the ordinal values back to ASCII characters and display.

    # Just Another Perl Hacker!

    Nice code, and a fun exercise tracing through to see how it worked. Well done.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: obfuscated [id://11158377]
Approved by choroba
Front-paged by Discipulus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2025-07-18 10:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.