TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: Any ideas what code this is?

4 pointsby ahmettalmost 11 years ago
<p><pre><code> $_=&#x27;^#(&#x2F;||&#x2F;@!@[{@:^[-[&#x27;^&quot;;@@@\\&gt;])@.&quot;. &quot;{)&#x2F;];)^{&quot;;$,+=(++$,);$_.=&quot;&gt;&amp;$,&quot;;`$_`; </code></pre> Saw it in a colleague&#x27;s email signature. Seemed like Perl to me but I don&#x27;t know Perl at all, certainly not at this level. So any ideas?

5 comments

jcralmost 11 years ago
Original Code<p><pre><code> $_=&#x27;^#(&#x2F;||&#x2F;@!@[{@:^[-[&#x27;^&quot;;@@@\\&gt;])@.&quot;. &quot;{)&#x2F;];)^{&quot;;$,+=(++$,);$_.=&quot;&gt;&amp;$,&quot;;`$_`; </code></pre> $ man perlop<p>= Assignment Operator.<p>. Concatenation Operator.<p>.= Concatenate and Assign.<p>^ Binary XOR. The binary &quot;^&quot; and &quot;|&quot; operators have lower precedence than relational operators like concatenate.<p>&#x27; Text between single quotes is an uninterpreted string.<p>&quot; Text between double quotes is an interpreted string.<p>; Statement terminator, just like C, java, javascript, ...<p>$ man perlvar<p>$_ The default input and pattern-searching space. A lot of perl code operates on this variable by default.<p>$, The output field separator for the print operator. If defined, this value is printed between each of print&#x27;s arguments. The default is &quot;undef&quot;.<p>The first statement is:<p>$_=&#x27;^#(&#x2F;||&#x2F;@!@[{@:^[-[&#x27;^&quot;;@@@\\&gt;])@.&quot;.&quot;{)&#x2F;];)^{&quot;;<p>String1: &#x27;^#(&#x2F;||&#x2F;@!@[{@:^[-[&#x27;<p>String2: &quot;;@@@\\&gt;])@.&quot;<p>String3: &quot;{)&#x2F;];)^{&quot;<p>So we get:<p>Result = String1 XOR String2 CONCAT String3<p>Since XOR has a lower precedence than Concatenate, we Concatenate first and then do the XOR.<p><pre><code> # First String: $_=&#x27;^#(&#x2F;||&#x2F;@!@[{@:^[-[&#x27;; printf &quot;HEX1: %*v2.2X\n&quot;, &#x27; &#x27;, $_; print &quot;STR1: &quot; . $_ . &quot;\n&quot;; $str1 = $_; # OUTPUT: # HEX1: 5E 23 28 2F 7C 7C 2F 40 21 40 5B 7B 40 3A 5E 5B 2D 5B # STR1: ^#(&#x2F;||&#x2F;@!@[{@:^[-[ # Second String: $_=&quot;;@@@\\&gt;])@.&quot;; printf &quot;HEX2: %*v2.2X\n&quot;, &#x27; &#x27;, $_; print &quot;STR2: &quot; . $_ . &quot;\n&quot;; $str2 = $_; # OUTPUT: # HEX2: 3B 40 40 40 5C 3E 5D 29 40 2E # STR2: ;@@@\&gt;])@. # Third String: $_=&quot;{)&#x2F;];)^{&quot;; printf &quot;HEX3: %*v2.2X\n&quot;, &#x27; &#x27;, $_; print &quot;STR3: &quot; . $_ . &quot;\n&quot;; $str3 = $_; # OUTPUT: # HEX3: 7B 29 2F 5D 3B 29 5E 7B # STR3: {)&#x2F;];)^{ # Since the &quot;^&quot; binary XOR operator has lower precedence # than the &quot;.&quot; concatenation operator, XOR str2 and str3 to # get the Fourth String: $_ = $str2 . $str3; printf &quot;HEX4: %*v2.2X\n&quot;, &#x27; &#x27;, $_; print &quot;STR4: &quot; . $_ . &quot;\n&quot;; $str4 = $_; # OUTPUT: # HEX4: 3B 40 40 40 5C 3E 5D 29 40 2E 7B 29 2F 5D 3B 29 5E 7B # STR4: ;@@@\&gt;])@.{)&#x2F;];)^{ # Now we can do a binary XOR on Sring #1 and String #4 to # get Fifth String: $_ = $str1 ^ $str4; printf &quot;HEX5: %*v2.2X\n&quot;, &#x27; &#x27;, $_; print &quot;STR5: &quot; . $_ . &quot;\n&quot;; $str5 = $_; # OUTPUT: # HEX5: 65 63 68 6F 20 42 72 69 61 6E 20 52 6F 67 65 72 73 20 # STR5: echo Brian Rogers # This is wickedly bad juju. The &quot;(++$,)&quot; portion increments an # undefined variable and would normally be an error, but with errors and # warnings shut off, it increments an undefined variable to 1, then adds # it to itself with &quot;+=&quot; to get 2. $,+=(++$,); # Here we concatenate shell redirection to stderr, which is file # descriptor 2, with the usual &quot;&gt;&amp;2&quot; since &quot;$,&quot; now equals 2. $_.=&quot;&gt;&amp;$,&quot;; print &quot;\n&quot;; printf &quot;HEX-: %*v2.2X\n&quot;, &#x27; &#x27;, $_; print &quot;STR-: &quot; . $_ . &quot;\n&quot;; # OUTPUT: # HEX-: 65 63 68 6F 20 42 72 69 61 6E 20 52 6F 67 65 72 73 20 3E 26 32 # STR-: echo Brian Rogers &gt;&amp;2 # Finally, the statement is evaluated in the shell: `$_`; </code></pre> Note: You should ask your friend Brian Rodgers if he always writes his name to Standard ERROR! ;)
mc_hammeralmost 11 years ago
<p><pre><code> $_ = &#x27;somestring&#x27;; `$_`; &#x2F;&#x2F; backticks are shell or exec(), $_ is the previous string. </code></pre> type echo &quot;&#x27;^#(&#x2F;||&#x2F;@!@[{@:^[-[&#x27;^&quot;;@@@\\&gt;])@.&quot;.&quot;{)&#x2F;];)^{&quot;;$,+=(++$,);$_.=&quot;&gt;&amp;$,&quot; to see what it does<p>;$,+=(++$,); looks like a for loop<p>looks like php to me - backticks work in perl, bash and php
edoceoalmost 11 years ago
The $ vars lead me to either Shell, Perl or PHP.<p>$_ is a special var in Bash and Perl.<p>The &#x27;.&#x27; char is for string concat in Perl and PHP<p>So, I think this is perl.<p>The first statement evaluates to: &quot;echo Brian Rogers &gt;&amp;2&quot; The second statement `$_` runs that command.<p>The end result is that this line of code prints:<p>Brian Rogers
andoralmost 11 years ago
It&#x27;s Perl. The last `$_`; evals what&#x27;s in $_, so change it to just print the variable:<p><pre><code> $_=&#x27;^#(&#x2F;||&#x2F;@!@[{@:^[-[&#x27;^&quot;;@@@\\&gt;])@.&quot;. &quot;{)&#x2F;];)^{&quot;;$,+=(++$,);$_.=&quot;&gt;&amp;$,&quot;; print &quot;$_&quot;; </code></pre> The output is:<p><pre><code> echo Brian Rogers &gt;&amp;2</code></pre>
psophisalmost 11 years ago
Look like a regular expression.