Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Genetic Code

by MeowChow (Vicar)
on Apr 09, 2001 at 21:28 UTC ( #71087=obfuscated: print w/replies, xml ) Need Help??

Sorry for the ahhh... verticality. In my defense, I encourage you to find the print statement ;-)
s OO CG T--A A---T A----T C----G T----A A---T G--C CG CG C--G G---C G----C C----G A----T C---G G--C AT CG A--T A---T G----C A----T G----C C---G A--T GC CG G--C A---T G----C G----C G----C A---T T--A AT CG T--A C---G A----T A----T G----C A---T A--T CG TA T--A G---C G----C C----G A----T C---G G--C CG TA T--A C---G T----A C----G A----T C---G G--C GC TA G--C C---G G----C G----C G----C A---T T--A CG AT G--C A---T A----T C----G C----G A---T A--T CG CG G--C G---C G----C A----T T----A C---G G--C CG TA A--T A---T G----C A----T A----T C---G A--T GC TA G--C C---G T----A G----C G----C C---G T--A AT CG G--C G---C T----A C----G G----C C---G C--G CG AT T--A C---G G----C G----C A----T T---A G--C CG TA G--C A---T G----C A----T G----C O,@_{ A=>C => G=> T=>} =0..3 ,s=. * (\w).* (\w).* \n=$_ { $- ++ /9 %2?$ 2:$ 1 }=gex* s=(.)( .)(.)(. )=chr 64*$ 1+ 16 *$2+ 4 *$ 3 +$ 4 =gex * eval
               s aamecha.s a..a\u$&owag.print

Replies are listed 'Best First'.
Re: Genetic Code
by MeowChow (Vicar) on Apr 10, 2001 at 21:54 UTC
    Heres a vivisection of this japh, for those that have asked. It works by decoding Perl (or any ASCII text) from one of the two interwoven DNA strands, with every four nucleotides representing one ASCII character (unlike real DNA which uses three nucleotides per codon, ASCII requires four, since 4^4 == 256). Because DNA is "mirrored" on each strand (T's to A's and G's to C's), we only use one of the two strands. First, we'll rewrite the code in a more readable format:
    # "$ _" is really "$_", and change the qq to a double-quote $_ = "CG T--A A---T A----T C----G T----A A---T and so on "; @_{A => C => G => T => } = 0..3; s|.*(\w).*(\w).*\n|$_{$-++ / 9 % 2 ? $2:$ 1}|gex; s|(.)(.)(.)(.)|chr (64*$1 + 16*$2 + 4*$3 + $4)|gex; eval
    Next, we'll make sense of the following line of code:
    @_{A => C => G => T => } = 0..3; # is really... @_{'A', 'C', 'G', 'T'} = 0..3;
    This is a hash slice notation that sets the A,C,G, and T keys of the %_ hash to their numeric value counterparts 0,1,2, and 3 respectively. The use of the digraph => operator allows for making strings of barewords.

    The next line of code transforms the chromosome into a series of Base4 digits, by substituting the appropriate digit for each line:

    s| .* # greedily match (\w) # match first letter, and store into $1 .* # greedily match (\w) # match last letter, and store into $2 .*\n # eat up remainder of line | # this expression maps the relevant character to its Base4 digit f +rom # the %_ hash. The $- is used as a line counter (it defaults to 0) +. When # the DNA strands flip positions, this continues decoding on the c +orrect # strand (see physi's comment for a visual representation of this) $_{$-++ / 9 % 2 ? $2:$ 1} |gex;
    After this substitution, $_ looks something like 010210320210103203.... All that's left to do is to transform each sequence of four Base4 digits into their ASCII representation:
    s| # store next four characters into $1,$2,$3, and $4 (.)(.)(.)(.) | # replace with a Base4-to-ASCII conversion of those characters chr (64*$1 + 16*$2 + 4*$3 + $4) |gex;
    After this, $_ contains our decoded code: print"Just Another Perl Hacker\n". The string is at last eval'd, and japhage occurs.

    And, in case anyone's interested, here's the corresponding Perl-to-DNA encoder:

    use strict; my $BASE = 4; my %NUC_PAIRS = ( A => T => C => G => G => C => T => A => ); my @DIGIT_TO_NUC = qw( A C G T ); my $FMT_DNA = <<END; 01 0--1 0---1 0----1 0----1 0---1 0--1 01 10 1--0 1---0 1----0 1----0 1---0 1--0 10 END my @FMT_DNA = split "\n",$FMT_DNA; my $str = 'print"Just Another Perl Hacker\n"'; my @str_digits; for (split//, $str) { my $ord = ord($_); my @digits = (0) x 4; print "$ord:\t"; my $i = 0; while ($ord) { $digits[4 - ++$i] = $ord % $BASE; $ord = int ($ord / $BASE); } print "@digits\n"; push @str_digits, [@digits]; } my $i = 0; for (@str_digits) { for (@$_) { my $fmt = $FMT_DNA[$i++ % @FMT_DNA]; my $nuc0 = $DIGIT_TO_NUC[$_]; my $nuc1 = $NUC_PAIRS{$nuc0}; $fmt =~ s/0/$nuc0/; $fmt =~ s/1/$nuc1/; print "$fmt\n"; } }
                   s aamecha.s a..a\u$&owag.print
      Sorry my ignorance... But I REALLY did not understand this part of the code:

       my $fmt = $FMT_DNA[$i++ % @FMT_DNA];

      I searched in books on "%" and nothing there helped me to understand its functioning here...

      Please... Give me your wisdom Saint Monk...

      Braz Monk
        %: Modolus operator. If $a % $b, returns the remainder when $a is divided by $b. Thus, 45 % 6 is 3, as is 51 % 6.

        The code in question does this:

        my $fmt = $FMT_DNA[$i++ % @FMT_DNA];
        1. Get the remainder when $i is divided by the number of elements in @FMT_DNA and put it in a temp variable.
        2. Increment $i by 1.
        3. Get the element in @FMT_DNA with an index of the temp variable and put it in $fmt.

        What this is doing is treating @FMT_DNA as a circular list - a list that will wrap around to the beginning when it runs out of elements. So, if it was 3 elements, it would do element 0, element 1, element 2, element 0, element 1, etc.

        We are the carpenters and bricklayers of the Information Age.

        The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

        Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

      how do u decode a computer code called Base4 used to substitute numbers for letters of the alphabet?
Re: Genetic Code
by Boldra (Deacon) on Apr 10, 2001 at 18:05 UTC
    I'm not going to attempt a full dissection, but I beleive the print statement is contained in the first letters of the first double-twist. That is:

    Beautiful code, MeowChow

    I've shifted my code up by one letter
Re: Genetic Code
by Mission (Hermit) on Apr 10, 2001 at 17:23 UTC
    That is a lovely work of art and code. Simply incredible! Do you have pointers for attmepting a code 'walk through'? I've worked with Perl for about three weeks now, so I'm definately an Initiate. The 'light' in the monestary is sometimes overwhelming.

    - Mission
    "Heck I don't know how to do it either, but do you think that's going to stop me!"
Re: Genetic Code
by physi (Friar) on Apr 10, 2001 at 19:28 UTC
    Really beautiful!
    Just a question to your %2 part
    Is this only for obfusication, or is there a deeper math sense hidden in it 8-).
    I guess the print is in :


    And now I see that there IS a deeper sense :-) Congrat.
    Maybe this is the first step to write a perl program which make changes to itselfe and see what's gonna happen. So there is maybe a chance, that this perl program becomes a perl Operating System one day ...
    ok, stop dreaming but keep on hoping :)

    ----------------------------------- --the good, the bad and the physi-- -----------------------------------
Re: Genetic Code
by providencia (Pilgrim) on Apr 12, 2001 at 00:10 UTC
    I love this one it's so soft on the eyes(IMHO).
    Reminds me of the scrolling ascii art that haunted a
    BBS I ran a few years ago.

    A prettiest obfuscated code contest anyone?

Re: Genetic Code
by r.joseph (Hermit) on Apr 13, 2001 at 22:20 UTC
    I have been lurking around the obfuscation section for as long as I have been a member of PM because I have always been fascinated with the skill and ingenuity required to create truly great obfuscated code. I must say that up until I stumbled across this post, the only other obfusctaed script I had been really impressed with was, of course, the ubiquitous camel code. I have always been fascinated with the storage of information in DNA strands, and although this script may not be as complicated as the camel code, its asthetic appeal and overall brilliance struck me as amazing. Defintely ++ MeowChow, I would more than once if I could. Keep up the awesome work - one day, I only hope that I could create something so shweet! :)

    r. j o s e p h
    "Violence is a last resort of the incompetent" - Salvor Hardin, Foundation by Issac Asimov
Re: Genetic Code
by Kickstart (Pilgrim) on Apr 10, 2001 at 01:14 UTC
    Ok, so what's it do? I ran it, no output was made. Once again, perl masturbation? :-)


      Funny, it works on every system I've ran it on (Linux/Win32-Perl 5.005/5.6). Are you sure you copy-pasted the code correctly? Try using the download code option; I got rid of the code tags surrounding the word "print" in my message, so this should work well now.
                     s aamecha.s a..a\u$&owag.print
        Strange, ok that worked. Can't see any differences between what I first copied and the d/l code. I should prolly run diff, but I'm lazy.


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2016-09-25 13:22 GMT
Find Nodes?
    Voting Booth?
    Extraterrestrials haven't visited the Earth yet because:

    Results (470 votes). Check out past polls.