{"id":4574,"date":"2021-01-23T00:01:47","date_gmt":"2021-01-23T08:01:47","guid":{"rendered":"https:\/\/c-for-dummies.com\/blog\/?p=4574"},"modified":"2021-01-23T09:00:16","modified_gmt":"2021-01-23T17:00:16","slug":"the-27th-international-obfuscated-c-code-contest","status":"publish","type":"post","link":"https:\/\/c-for-dummies.com\/blog\/?p=4574","title":{"rendered":"The 27th International Obfuscated C Code Contest"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2021\/01\/Screen-Shot-2021-01-16-at-09.49.31-300x102.png\" alt=\"\" width=\"300\" height=\"102\" class=\"alignnone size-medium wp-image-4583\" srcset=\"https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2021\/01\/Screen-Shot-2021-01-16-at-09.49.31-300x102.png 300w, https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2021\/01\/Screen-Shot-2021-01-16-at-09.49.31-768x262.png 768w, https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2021\/01\/Screen-Shot-2021-01-16-at-09.49.31-500x171.png 500w, https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2021\/01\/Screen-Shot-2021-01-16-at-09.49.31.png 780w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>The results of the <a href=\"http:\/\/www.ioccc.org\/\" rel=\"noopener\" target=\"_blank\">27th International Obfuscated C Code Contest<\/a> were announced earlier this month. The code is amazing. It runs. It&#8217;s horrifyingly cryptic.<br \/>\n<!--more--><br \/>\nObfuscated C is exactly the kind of coding I try to avoid. The goal is to deliberately make the code difficult to read. The obfuscation can also present itself as visually symmetrical or formatted to create an image.<\/p>\n<p>While I admire the degrees to which you can make C look complex or pretty, my goal is to teach. The code examples I use must be presented in a way that&#8217;s easy to understand. Still, obfuscating C is possible and enjoyed by dozens of programmers, hence the contest.<\/p>\n<p>Different categories of obfuscated C are possible. For example, the one-line cryptic like this:<\/p>\n<pre class=\"screen\">\r\nint main(int b,char**i){long long n=B,a=I^n,r=(a\/b&a)>>4,y=atoi(*++i),_=(((a^n\/b)*(y>>T)|y>>S)&r)|(a^r);printf(\"%.8s\\n\",(char*)&_);}<\/pre>\n<p>I&#8217;m also fond of users who freely format their code like this:<\/p>\n<pre class=\"screen\">\r\n                                                      #\\\r\n                                define C(c           <span class=\"comments\">\/**\/<\/span>)#c\r\n                               <span class=\"comments\">\/*size=3173*\/<\/span>#include&lt;stdio.h&gt;\r\n                            <span class=\"comments\">\/*crc=b7f9ecff.*\/<\/span>#include&lt;stdlib.h&gt;\r\n                           <span class=\"comments\">\/*Mile\/Adele_von_Ascham*\/<\/span>#include&lt;time.h&gt;\r\n                           typedef<span class=\"comments\">\/**\/<\/span>int(I);I<span class=\"comments\">\/*:3*\/<\/span>d,i,j,a,b,l,u[16],v\r\n                           [18],w[36],x,y,z,k;char*P=\"\\n\\40(),\",*p,*q,*t[18],m[4];\r\n                          void<span class=\"comments\">\/**\/<\/span>O(char*q){for(;*q;q++)*q&gt;32?z=111-*q?z=(z+*q)%185,(k?\r\n                          k--:(y=z%37,(x=z\/37%7)?printf(*t,t[x],y?w[y-1]:95):y&gt;14&amp;&amp;y&lt;33?x\r\n                          =y&gt;15,printf(t[15+x],x?2&lt;&lt;y%16:l,x?(1&lt;&lt;y%16)-1:1):puts(t[y%28])))\r\n                          ,0:z+82:0;}void<span class=\"comments\">\/**\/<\/span>Q(I(p),I*q){for(x=0;x&lt;p;x++){q[x]=x;}for(;--p\r\n    &gt;1;q[p]=y)y          =q[x=rand()%-~p],q[x]=q[p];}char<span class=\"comments\">\/**\/<\/span>n[999]=C(Average?!nQVQd%R&gt;Rd%\r\n  R%          %RNIPRfi#VQ}R;TtuodtsRUd%RUd%RUOSetirwf!RnruterR{RTSniamRtniQ&gt;h.oidts&lt;edulc\r\n ni                   #V&gt;rebmun&lt;=NIPD-RhtiwRelipmocResaelPRrorre#QNIPRfednfi#V__ELIF__R_\r\nRe               nifed#V~-VU0V;}V{R= R][ORrahcRdengisnuRtsnocRcitatsVesle#Vfidne#V53556\r\n .           .1RfoRegnarRehtRniRre   getniRnaRsiR]NIP[R erehwQQc.tuptuoR&gt;Rtxt.tupniR\r\n &lt;         R]NIP[R:egasuV_Redulcn i#VfednfiVfednuVenife dVfedfiVQc%Rs%#V);I<span class=\"comments\">\/**\/<\/span>main(\r\n  I(      f),char**e){if(f){for(i=    time(NULL),p=n,q=  n+998,x=18;x;p++){*p&gt;32&amp;&amp;!(\r\n         *--q=*p&gt;80&amp;&amp;*p&lt;87?P[*p-   81]:*     p)?t  [( --  x)]=q+1:q;}if(f-2||(d=atoi\r\n        (e[1]))&lt;1||65536&lt;d){;O(\"   \\\"\");             goto  O;}srand(i);Q(16,u);i=0;Q(\r\n       36,w);for(;i&lt;36; i++){w[i]   +=w           [i]&lt;26 ? 97:39; }O(C(ouoo9oBotoo%]#\r\n      ox^#oy_#ozoou#o{ a#o|b#o}c#                o~d#oo-e   #oo.  f#oo\/g#oo0h#oo1i#oo\r\n     2j#oo3k#oo4l#o   p));for(j                   =8;EOF   -(i=   getchar());l+=1){a=1+\r\n    rand()%16;for(b  =0;b&lt;a||i-                           main   (0,e);b++)x=d^d\/4^d\/8^d\/\r\n    32,d=  (d\/  2|x&lt;&lt;15)&amp;65535;                          b|=   !l&lt;&lt;17;Q(18,v);for(a=0;a&lt;18;\r\n    a++     ){if( (b&amp;(1&lt;&lt;(i=v[a]      ))))*                 m=75+i,O(m),j=i&lt;17&amp;&amp;j&lt;i?i:j;}O(C(\r\n    !)           ); }O(C(oqovoo97o    \/n!));i=           0;for(;i&lt;8;O(m))m[2]=35,*m=56+u[i],m[1\r\n    ]=          75   +i++;O(C(oA!oro   oqoo9)          );k=112-j*7;O(C(6o.!Z!Z#5o-!Y!Y#4~!X!X#3}\r\n     !W  !W     #2    |!V!V#1{!U!U#0z!            T!T#\/y!S!S#.x!R!R#-w!Q!Q#ooAv!P!P#+o#!O!O#*t!N!\r\n       N#      oo       &gt;s!M!M#oo=r!L!L#oo&lt;q!K!K#   &amp;pIo@:;= oUm#oo98m##oo9=8m#oo9oUm###oo9;=8m#o\r\n               o9   oUm##oo9=oUm#oo98m####          o09]    #o1:^#o2;_#o3&lt;o  ou#o4=a#o5&gt;b#o6?c#o\r\n             7@d#o8A e#o    9B    f#o:Cg#o;          D     h#o&lt;Ei #o=Fj#o&gt;   Gk#o?Hl#oo9os#####\r\n           ));d=0                                          ;}          O:    for(x=y=0;x&lt;8;++\r\n          x)y|=                                                               d&amp;(1&lt;&lt;u[x])?\r\n          1&lt;&lt;                                                               x:0;return\r\n           <span class=\"comments\">\/*                                                               :9    *\/<\/span>\r\n            y                                                                ;    }<\/pre>\n<p>Building these programs requires a few command line options to get things working, which I think of as cheating. For example, you can avoid using <code>#include<\/code> preprocessor directives in your code if you use the <code>&#8209;include<\/code> command line switch. Still, all this nonsense is for thrills.<\/p>\n<p>I&#8217;ve tried to write obfuscated C, but haven&#8217;t written anything that delights to me to the degree of the cryptic or pretty code I&#8217;ve seen. From my desire to teach, I have an aversion to making things difficult to figure out. Therefore, I both appreciate obfuscated C but recognize that I&#8217;m unable to do it myself.<\/p>\n<p>As I feel compelled, here&#8217;s my lame version of obfuscated C, though it&#8217;s pretty obvious what I&#8217;m doing:<\/p>\n<h3><a href=\"https:\/\/github.com\/dangookin\/C-For-Dummies-Blog\/blob\/master\/2021_01_23-Lesson.c\" rel=\"noopener\" target=\"_blank\">2021_01_23-Lesson.c<\/a><\/h3>\n<pre class=\"screen\">\r\nint main() {puts(\"Hello, World!\");return 0;}<\/pre>\n<p>All I did above is put the entire <em>main()<\/em> function on a single line. This is the entire code, by the way. To compile, you use the following command at the prompt:<\/p>\n<p><code>clang -include stdio.h 0123.c<\/code><\/p>\n<p>Again, I think specifying the <code>-include<\/code> switch is cheating, but it keeps the source code compact. My attempt at obfuscation merely takes advantage of C&#8217;s capability to ignore whitespace. Likewise, you can pad the whitespace, which is done in the second example shown earlier.<\/p>\n<p>If it&#8217;s your goal to obfuscate your C code, great! Have fun. Enter the contest (use the link above). But please don&#8217;t deliberately or otherwise obfuscate your code. C can be cryptic, but it&#8217;s an appreciated art form to make it readable.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you think C code is difficult to grasp, hang on to your hat. <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=4574\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-4574","post","type-post","status-publish","format-standard","hentry","category-main"],"_links":{"self":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4574","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4574"}],"version-history":[{"count":8,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4574\/revisions"}],"predecessor-version":[{"id":4593,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4574\/revisions\/4593"}],"wp:attachment":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4574"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4574"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4574"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}