<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.yobi.be/index.php?action=history&amp;feed=atom&amp;title=Hack.lu_2015_Writeups</id>
	<title>Hack.lu 2015 Writeups - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.yobi.be/index.php?action=history&amp;feed=atom&amp;title=Hack.lu_2015_Writeups"/>
	<link rel="alternate" type="text/html" href="https://wiki.yobi.be/index.php?title=Hack.lu_2015_Writeups&amp;action=history"/>
	<updated>2026-05-22T18:57:06Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.8</generator>
	<entry>
		<id>https://wiki.yobi.be/index.php?title=Hack.lu_2015_Writeups&amp;diff=10367&amp;oldid=prev</id>
		<title>PhilippeTeuwen: Created page with &quot;==2015== ===2015 Perl golf=== Goal: Write a Perl program that takes a parameter as input and outputs a filtered version with alternating upper/lower case letters of the (engli...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.yobi.be/index.php?title=Hack.lu_2015_Writeups&amp;diff=10367&amp;oldid=prev"/>
		<updated>2017-10-20T18:59:02Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;==2015== ===2015 Perl golf=== Goal: Write a Perl program that takes a parameter as input and outputs a filtered version with alternating upper/lower case letters of the (engli...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==2015==&lt;br /&gt;
===2015 Perl golf===&lt;br /&gt;
Goal: Write a Perl program that takes a parameter as input and outputs a filtered version with alternating upper/lower case letters of the (english) alphabet. Non-letter characters have to be printed but otherwise ignored.&lt;br /&gt;
&amp;lt;br&amp;gt;Example:&lt;br /&gt;
 Input	Hello World! Hallo Welt!&lt;br /&gt;
 Output	HeLlO wOrLd! HaLlO wElT!&lt;br /&gt;
Rules:&lt;br /&gt;
* You have 1 second.&lt;br /&gt;
* You have 45 (ASCII) chars.&lt;br /&gt;
* Do not flood the server.&lt;br /&gt;
&lt;br /&gt;
The first thing is to find how the server will use your script.&lt;br /&gt;
&amp;lt;br&amp;gt;Input isn&amp;#039;t read from stdin but is expected as the first argument, so you can try locally with&lt;br /&gt;
 perl -e &amp;#039;print @ARGV[0]&amp;#039; &amp;#039;Hello World! Hallo Welt!&amp;#039;&lt;br /&gt;
 Hello World! Hallo Welt!&lt;br /&gt;
Then come with a strategy to convert letters as asked and squeeze it.&lt;br /&gt;
&amp;lt;br&amp;gt;Here is our solution: (37 chars)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$_=pop;s/\pL.*?(\pL|$)/\u\L$&amp;amp;/g;print&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
But here is actually how Fluxfingers designed this challenge: they tried internally, kept the best one-liner they could come with, which was 38 chars long, and extended the limit to 45 to give some room to the participants.&lt;br /&gt;
&amp;lt;br&amp;gt;The best solution Fluxfingers had in mind: (38 chars)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$_=pop;s/\pL/uc$&amp;amp;^$&amp;quot;^($x^=$&amp;quot;)/ge/print &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
So we were one char shorter \o/&lt;br /&gt;
&lt;br /&gt;
A little word of explanation of our solution:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$_=pop;s/\pL.*?(\pL|$)/\u\L$&amp;amp;/g;print&lt;br /&gt;
$_=                                    assign to the Perl &amp;quot;current var&amp;quot;, so we don&amp;#039;t have to mention it later&lt;br /&gt;
   pop;                                we need @ARGV[0], pop is shorter&lt;br /&gt;
       s/             /      /g;       search and replace, g=repeat&lt;br /&gt;
         \pL.*  \pL                    We want one letter followed optionally by some stuff followed by one letter&lt;br /&gt;
                                          \w captures too much (also [0-9_]) so we rely on that Unicode magic \pL&lt;br /&gt;
                                          So first captured letter needs to be in uppercase and second captured letter needs to be lowercase&lt;br /&gt;
            .*?                        Problem with .* is that it captures too much, including letters.&lt;br /&gt;
                                          One could write [^a-zA-Z]* but that&amp;#039;s not golfing anymore&lt;br /&gt;
                                          Adding the &amp;quot;?&amp;quot; reduces the &amp;quot;greediness&amp;quot; of the expression to capture as few chars as possible&lt;br /&gt;
               (\pL|$)                 An issue wit \pL only is that it fails if there is an odd number of letters in the string&lt;br /&gt;
                                          So here we say one letter, or end of string, to capture that corner case.&lt;br /&gt;
                       \u\L$&amp;amp;          $&amp;amp; is what was captured by the regex, \u means first char uppercase, \L means lowercase for the remaining letters&lt;br /&gt;
                                print  Should I explain?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After the CTF, we got it even shorter, now 36 chars!:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$_=uc pop;s/\pL.*?\pL/\u\L$&amp;amp;/g;print&lt;br /&gt;
   uc                                  Set whole input as uppercase&lt;br /&gt;
                  \pL                  No more dirty (\pL|$) trick here&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The trick is to avoid the corner case of odd number of letters by setting the whole input uppercase first&lt;br /&gt;
&lt;br /&gt;
Alternative solution of 36 chars, optimizing what was discussed [https://github.com/teamavidya/ctf/commit/52f5789e743af94c147d4e5e0fd3796bc162872b#commitcomment-13953040 here]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$_=lc pop;s/\pL/$&amp;amp;^($u^=$&amp;quot;)/ge;print&lt;br /&gt;
$_=                                    assign to the Perl &amp;quot;current var&amp;quot;, so we don&amp;#039;t have to mention it later&lt;br /&gt;
   lc                                  Set whole input as lowercase&lt;br /&gt;
      pop;                             we need @ARGV[0], pop is shorter&lt;br /&gt;
          s/   /           /ge         search and replace, g=repeat, e=evaluate again the result&lt;br /&gt;
            \pL                        We want one letter: \w captures too much (also [0-9_]) so we rely on that Unicode magic \pL&lt;br /&gt;
               &lt;br /&gt;
                $&amp;amp;                     $&amp;amp; is what was captured by the regex&lt;br /&gt;
                  ^     $&amp;quot;             xor it with $&amp;quot; which evaluates to &amp;quot; &amp;quot;. The effect is that a letter XORed by 0x20 toggles its case.&lt;br /&gt;
                  ^($u^=$&amp;quot;)            Actually that&amp;#039;s to be done only half of the time so we xor with a variable that is constantly xored with &amp;quot; &amp;quot;&lt;br /&gt;
                                         so $u value is successively 0x20, 0x00, 0x20, 0x00 etc&lt;br /&gt;
                                print  Should I explain?&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;UPDATE&amp;#039;&amp;#039;&amp;#039;: [https://github.com/teamavidya/ctf/commit/52f5789e743af94c147d4e5e0fd3796bc162872b#commitcomment-13964794 someone] managed to get down to 34 chars!:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
print pop=~s/\pL/lc$&amp;amp;^($u^=$&amp;quot;)/ger&lt;br /&gt;
                                 r      perform non-destructive substitution and return the new value&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Actually we can go even further for some of those solutions if we tolerate that the script doesn&amp;#039;t always work.&lt;br /&gt;
&amp;lt;br&amp;gt;One can simply reload multiple times the script till the server provides a compatible input to get the flag.&lt;br /&gt;
&amp;lt;br&amp;gt;E.g. 29 chars and 28 chars:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$_=pop;s/\w.*?\w/\u$&amp;amp;/g;print&lt;br /&gt;
print pop=~s/\w.*?\w/\u$&amp;amp;/gr&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
worked after a few reloads on the sentence &amp;quot;body. want Law the help of and, being. a, graduates&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===2015 PHP Golf===&lt;br /&gt;
Same as for Perl Golf, but now we&amp;#039;ve 62 chars max.&lt;br /&gt;
&amp;lt;br&amp;gt;The lazy solution: (57 chars)&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?=`echo &amp;#039;$argv[1]&amp;#039;|perl -pe &amp;#039;s/\pL.*?(\pL|$)/\u\L$&amp;amp;/g&amp;#039;`;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Apparently Fluxfingers solution was:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;lt;?=preg_filter(&amp;quot;/\pL/e&amp;quot;,&amp;#039;($0|&amp;quot; &amp;quot;)^chr($m^=32)&amp;#039;,$argv[1]);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>PhilippeTeuwen</name></author>
	</entry>
</feed>