Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

C Challenge

Name: omgoptimized 2012-03-13 18:58

So I wrote a C program that encodes its first command line argument using base64 and prints it to the standard output.

Can anybody make this program shorter? I bet someone can.
And yes this is probably not ANSI C, I don't even care.


#include<stdio.h>
#define _ for(j=3;(i%3)&&j>-1;x=(p.d&63<<6*j)>>6*j,putchar(
#define O (x<26)?65+x:((x<52)?71+x:((x<62)?x-4:x*4-205))),--j);p.d=0;}
int main(int c,char** v){union{char c[3];int d:24;}p;int i=-1,j,x;while(p.c[2-i%3]=v[1][++i]){if(i%3>1){_ O}_(j<3-i%3)?61:O

Name: omgoptimized 2012-03-13 19:53

bump -- I managed to get rid of a few more characters

#include<stdio.h>
#define _ for(j=3;(i%3)&&j>-1;x=(p.d&63<<6*j)>>6*j,putchar(
#define O (x<26)?65+x:(x<52)?71+x:(x<62)?x-4:x*4-205),--j);p.d=0;}
int main(int c,char** v){union{char c[3];int d:24;}p;int i=-1,j,x;while(p.c[2-i%3]=v[1][++i]){if(i%3>1){_ O}_(j<3-i%3)?61:O

Name: omgoptimized 2012-03-13 20:45

I can't help it

#include<stdio.h>
#define _ for(j=4;(i%3)&&j>0;x=(p.d&63<<6*j)>>6*j,putchar(
#define O (x<26)?65+x:(x<52)?71+x:(x<62)?x-4:x*4-205))--j;p.d=0;}
int main(int c,char** v){union{char c[3];int d:24;}p;int i=-1,j,x;while(p.c[2-i%3]=v[1][++i]){if(i%3>1){_ O}_(j<3-i%3)?61:O

Name: Anonymous 2012-03-13 20:50

THANKS FAGGOT, I SURE DO LOVE LOOKING AT THE EXACT SAME THING 3 TIMES IN A ROW FOR SOME SHITTY C PROGRAM THAT DOESN'T EVEN CONFORM TO THE STANDARD.

Name: omgoptimized 2012-03-13 20:52

>>4
Enjoy:


#include<stdio.h>
#define _ for(j=4;i%3&&j>0;x=(p.d&63<<6*j)>>6*j,putchar(
#define O x<26?65+x:x<52?71+x:x<62?x-4:x*4-205))--j;p.d=0;}
int main(int c,char** v){union{char c[3];int d:24;}p;int i=-1,j,x;while(p.c[2-i%3]=v[1][++i]){if(i%3>1){_ O}_ j<3-i%3?61:O


I can't get it any shorter now

Name: Anonymous 2012-03-13 20:56

>>5
Putting it all on one line and in macros =/= making it shorter

Name: Anonymous 2012-03-13 21:05


int main(int c,char** v){
  union{
    char c[3];
    int d:24;
  }p;
  int i=-1,j,x;
  while(p.c[2-i%3]=v[1][++i]){
    if(i%3>1){
      for(j=4;i%3&&j>0;x=(p.d&63<<6*j)>>6*j,putchar( x<26?65+x:x<52?71+x:x<62?x-4:x*4-205))
        --j;
      p.d=0;
    }
  }
  for(j=4;i%3&&j>0;x=(p.d&63<<6*j)>>6*j,putchar( j<3-i%3?61:x<26?65+x:x<52?71+x:x<62?x-4:x*4-205))
    --j;
  p.d=0;
}




pig disgusting

Name: omgoptimized 2012-03-13 21:05

It really only depends on what you set as a goal.
This time I was trying to make the source file the smallest I could (260 bytes, with windows' CR/LF). I had fun doing this, but I might try making stuff shorter with the different approach you mentioned.
Care to share the "rules"? No #defines, what counts as shorter, etc.

Name: Anonymous 2012-03-13 21:40

#include <stdlib.h>
int main(void) {
  return system("base64 -d -");
}

Name: Anonymous 2012-03-13 21:50

FROZEN VOID QUALITY

Name: Anonymous 2012-03-13 22:32

#include <dubs.h>
int main(int prog, char **dubs) {
     return check_em();
}

Name: Anonymous 2012-03-13 22:40

「ぅぅうう ぅぅううう ぅぅぅぅう ぅぅぅううぅぅうぅ」

Name: Anonymous 2012-03-13 22:51

Protip: gcc spits out the same ASM for all your less-used syntax and lack of whitespace as normal syntax.

Name: Anonymous 2012-03-14 1:28

>>12
If you leave out the ``tomot'', then how can we be sure the message wasn't truncated?

Name: Anonymous 2012-03-14 3:56

    #include <stdio.h>
    #include "base64.h"
   
    int main(int argc, char *argv[]) {
        puts(b64encode(argv[0]));
        return 0;
    }

what do I win

Name: omgoptimized 2012-03-14 5:12

>>13
I'm well aware of this

Initially I was trying to make the original code as obfuscated as possible. Then I switched my goal to making it the shortest code possible. I guess this obfuscates it well too :)

Name: Anonymous 2012-03-14 8:34

You failed to accomplish any of those goals

Name: Anonymous 2012-03-14 10:48

>>17
I don't see how it isn't the shortest - nobody proved me wrong yet.

Don't change these.
Name: Email:
Entire Thread Thread List