TinyCode competition - trial

I’m tempted to host some silly competion thingy about writing the smallest code to perform some I/O task.

I coded some really silly task, and I’d like you guys to check out whether there is anything dangerous possible.
If so, I’d be very grateful if you’d let me know as fast as possible.
I’m renting this server, and I wouldn’t really like to get my account suspended.

I tried to isolate the running of tasks as much as possible, within the current JVM, but I might have to resort launching a new JVM to avoid any corruption of the HTTP-server-instance hosting this.

http://213.247.55.3:8484/compileandrun/

A (naive) solution for the task would be:


while(true)
{
  int a = in.read();
  int b = in.read();
  if((a|b)<0) break;
  out.write(b);
  out.write(a);
}

108 bytes, linebreaks don’t count (for readability reasons), but spaces do

Beat that! I didn’t really raise the bar very high, did I… :slight_smile:

Anyway, give it a try, and tell me if there’s something I need to know. :-*

Beat 62 bytes, and don’t forget to be naughty.

I disabled uppercase characters… to catch the casual tester

System.exit(0);

This worked though:

\u0053ystem.exit(0);

Gimme your tricks…

ewww, no uppercase characters :-[, pretty much ends it for me.

Hey… how else would I keep it secure…

and… why would you need Classes in such tasks?

I’m glad you tried it though :slight_smile:

Got to 64bytes so far…

Way to go!

ah sorry my mistake, thought the task was to break the program :slight_smile:

That too… ;D and that stops like 99.9999% of all attacks.

Haha, I’m such a muppet - that 64byte solution was actually 62bytes =)
I hadn’t removed the declaration of the now unused b integer :smiley:

Can’t see a way of beating 62 though… atleast not yet =)

Darn.

A dead end… but I love it!


for(byte[]b={0,0,1};in.read(b,b[2]++&1,1)>0;out.write(b,0,b[2]*2&2));

(69 bytes)

If you are going to break the defined contract of InputStream.read(byte[],int,int), by only checking for “>0” on the return type, then the 62 byte solution mentioned earlier can be trimmed to 61 bytes =)
(presumably your own 6[1/2] byte solution is exactly the same as mine?)

for(int a;(a=in.read())>0;out.write(in.read()),out.write(a));

0 is not breaking the contract of InputStream.read(byte[],int,int)

[quote]This method blocks until input data is available, end of file is detected, or an exception is thrown.
[/quote]
it will never ever return 0.

Unless your set the thrid argument to 0 :wink:

actually, I got 1 byte less (60 bytes):

for(int a;(a=in.read())>0;out.write(a))out.write(in.read());

ditto Abuse it’s 61 bytes if you use >=0…

I guess this is good enough to turn into a bigger project :slight_smile:

I wrote the http-server myself, so pretty much everything is possible.

Again, don’t forget to mention the security-holes. Thank you.

I totally love the simplicity.

oh yeah, nice spot ;D

I still think your 69byte solution is by far the most complicated =S

isn’t this flawed, since it only checks the validity of the first in.read?
-edit- ok, the string has pairs of bytes.