Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 2 3 [4] 5 6
  Print  
  TinyCode competition - trial  (Read 20358 times)
0 Members and 2 Guests are viewing this topic.
Offline noblemaster

JGO Ninja
***

Posts: 730
Medals: 6


Age of Conquest makes your day!


« Reply #90 on: 2007-10-29 22:59:47 »

mhh, what about floating point numbers? 1.0, 0.34...

Offline oNyx

JGO Kernel
*****

Posts: 2943
Medals: 5


pixels! :x


« Reply #91 on: 2007-10-29 23:02:09 »

Using a sandbox should have done the trick as well, no?

弾幕 ☆ @mahonnaiseblog
Offline markush

Jr. Member
**

Posts: 52


Plöp!


« Reply #92 on: 2007-10-30 04:23:03 »

Barcode 64 bytes:

1  
2  
3  
4  
5  
for(int c=1,i=48;c>0;i++)
  if((c=in.read())<99){
    out.write(i);
    i=47;
  }


Sometimes you need to take some time off, to see the simple optimizations Smiley
Games published by our own members! Go get 'em!
Offline erikd

JGO Kernel
*****

Posts: 2561
Medals: 7


Maximumisness


« Reply #93 on: 2007-10-30 05:26:02 »

This is fun  Cheesy
But it's too easy to cheat, ie. optimizing just for the test case while breaking the algorithm.

Online Riven
« League of Dukes »

JGO Kernel
*****

Posts: 5871
Medals: 255


Hand over your head.


« Reply #94 on: 2007-10-30 05:32:46 »

Tonight I'll expend the number of testcases from 1 to N (where N >= 1)

Hi, appreciate more people! Σ ♥ = ¾

Learn how to award medals... and work your way up the social rankings
Offline Abuse

JGO Kernel
*****

Posts: 1866
Medals: 5


falling into the abyss of reality


« Reply #95 on: 2007-10-30 06:34:34 »

I believe there is now a new way of crashing the server - I'll see if I can verify this @ lunchtime.

If so, I'll let you know via pm Riven  Cheesy
Offline Abuse

JGO Kernel
*****

Posts: 1866
Medals: 5


falling into the abyss of reality


« Reply #96 on: 2007-10-30 09:39:40 »

I believe there is now a new way of crashing the server - I'll see if I can verify this @ lunchtime.

If so, I'll let you know via pm Riven  Cheesy

No joy yet... but I'm very close.

More worryingly, if successful it will give the capability to execute arbitrary code, essentially giving almost complete control over the machine on-which the server is running  - limited only by the user level security offered by the OS.
Online Riven
« League of Dukes »

JGO Kernel
*****

Posts: 5871
Medals: 255


Hand over your head.


« Reply #97 on: 2007-10-30 11:01:30 »

I'm very interested.

I bet it is solvable by removing the support for uppercase characters again..?

Hi, appreciate more people! Σ ♥ = ¾

Learn how to award medals... and work your way up the social rankings
Offline Abuse

JGO Kernel
*****

Posts: 1866
Medals: 5


falling into the abyss of reality


« Reply #98 on: 2007-10-30 11:48:43 »

Here is what I have so far :-

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
      final Class c = new ClassLoader() {
         public Class read() {
           
            byte [] classData =
               new byte[] {-54,-2,-70,-66,0,0,0,46,0,41,7,0,2,1,0,4,66,108,97,104,7,0,4,1,0,16,106,97,118,97,47,108,97,110,103,47,79,98,106,101,99,116,1,0,6,99,104,101,101,115,101,1,0,1,68,1,0,8,60,99,108,105,110,105,116,62,1,0,3,40,41,86,1,0,4,67,111,100,101,9,0,11,0,13,7,0,12,1,0,16,106,97,118,97,47,108,97,110,103,47,83,121,115,116,101,109,12,0,14,0,15,1,0,3,111,117,116,1,0,21,76,106,97,118,97,47,105,111,47,80,114,105,110,116,83,116,114,101,97,109,59,8,0,17,1,0,11,105,110,105,116,105,97,108,105,115,101,100,10,0,19,0,21,7,0,20,1,0,19,106,97,118,97,47,105,111,47,80,114,105,110,116,83,116,114,101,97,109,12,0,22,0,23,1,0,7,112,114,105,110,116,108,110,1,0,21,40,76,106,97,118,97,47,108,97,110,103,47,83,116,114,105,110,103,59,41,86,10,0,25,0,27,7,0,26,1,0,14,106,97,118,97,47,108,97,110,103,47,77,97,116,104,12,0,28,0,29,1,0,6,114,97,110,100,111,109,1,0,3,40,41,68,9,0,1,0,31,12,0,5,0,6,1,0,15,76,105,110,101,78,117,109,98,101,114,84,97,98,108,101,1,0,18,76,111,99,97,108,86,97,114,105,97,98,108,101,84,97,98,108,101,1,0,6,60,105,110,105,116,62,10,0,3,0,36,12,0,34,0,8,1,0,4,116,104,105,115,1,0,6,76,66,108,97,104,59,1,0,10,83,111,117,114,99,101,70,105,108,101,1,0,9,66,108,97,104,46,106,97,118,97,0,33,0,1,0,3,0,0,0,1,0,25,0,5,0,6,0,0,0,2,0,8,0,7,0,8,0,1,0,9,0,0,0,55,0,2,0,0,0,0,0,15,-78,0,10,18,16,-74,0,18,-72,0,24,-77,0,30,-79,0,0,0,2,0,32,0,0,0,14,0,3,0,0,0,4,0,8,0,6,0,14,0,2,0,33,0,0,0,2,0,0,0,1,0,34,0,8,0,1,0,9,0,0,0,47,0,1,0,1,0,0,0,5,42,-73,0,35,-79,0,0,0,2,0,32,0,0,0,6,0,1,0,0,0,2,0,33,0,0,0,12,0,1,0,0,0,5,0,37,0,38,0,0,0,1,0,39,0,0,0,2,0,40};              
         
            Class c = defineClass("Blah", classData, 0, classData.length);
           
            resolveClass(c);
            return c;
         }
      }.read();

      // TODO: Find some api operation that causes the static initialiser of Class c to be invoked.
     // Complication:  The api operation must be defined in a public non-final class in the java.lang package.
     // I have yet to find a way of achieving this :-(


I'm hoping java.lang.SecurityManager holds the key..... as there is little else of use in the java.lang package.
Online Riven
« League of Dukes »

JGO Kernel
*****

Posts: 5871
Medals: 255


Hand over your head.


« Reply #99 on: 2007-10-30 12:42:35 »

Thanks for your hack-skills, i bet there is a huge security hole here.

As you posted this here, I'll take down my server and fix it later tonight.

Hi, appreciate more people! Σ ♥ = ¾

Learn how to award medals... and work your way up the social rankings
Games published by our own members! Go get 'em!
Online Riven
« League of Dukes »

JGO Kernel
*****

Posts: 5871
Medals: 255


Hand over your head.


« Reply #100 on: 2007-10-30 12:52:20 »

I think that if you'd add forName("Blah"), the static initializer would have been executed...?

Hi, appreciate more people! Σ ♥ = ¾

Learn how to award medals... and work your way up the social rankings
Offline Abuse

JGO Kernel
*****

Posts: 1866
Medals: 5


falling into the abyss of reality


« Reply #101 on: 2007-10-30 13:41:40 »

I think that if you'd add forName("Blah"), the static initializer would have been executed...?

forName is a method in Class, not ClassLoader.
And as Class is declared final, I cannot access the method as a sub-class (to avoid usage of the dot operator)
Offline Abuse

JGO Kernel
*****

Posts: 1866
Medals: 5


falling into the abyss of reality


« Reply #102 on: 2007-10-30 14:55:42 »

Nope, looks like you were safe afterall, I can't find a way of executing the class initialiser of a class constructed through Reflection without using the dot operator.

The only security hole exposed through ClassLoader is that you can get an InputStream to any file on the classpath.
So in theory we could of grabbed the class files of the application, piped them to the OutputStream you provide us in the method parameter, resulting in the class file contents being piped back to us as the contents of the web page.
I suppose decompiling the resultant files might have allowed us to find an exploit in your app....
Online Riven
« League of Dukes »

JGO Kernel
*****

Posts: 5871
Medals: 255


Hand over your head.


« Reply #103 on: 2007-10-31 09:36:30 »

I still think there is a loophole to be found with overriding toString() (as that doesn't require the explicit method-invocation) with a body containing System.exit(0); in bytecode.

If you can grab an instance of the produced class, or can run the static initializer, it's pretty much overtaken.

Hi, appreciate more people! Σ ♥ = ¾

Learn how to award medals... and work your way up the social rankings
Offline Abuse

JGO Kernel
*****

Posts: 1866
Medals: 5


falling into the abyss of reality


« Reply #104 on: 2007-10-31 11:12:56 »

You should leave it up!
Consider it the the 'out of the (sand)box' coding exercise Grin
Online Riven
« League of Dukes »

JGO Kernel
*****

Posts: 5871
Medals: 255


Hand over your head.


« Reply #105 on: 2007-10-31 11:43:47 »

If it was my own server... yes, but I'm renting this one, and I just paid 250 euro, and I don't want to get my account suspended.

Further, a company is dependant (critically) on a MySQL database on it.



And... I don't have much time to fix it, with my examns this week.

Hi, appreciate more people! Σ ♥ = ¾

Learn how to award medals... and work your way up the social rankings
Online Riven
« League of Dukes »

JGO Kernel
*****

Posts: 5871
Medals: 255


Hand over your head.


« Reply #106 on: 2007-10-31 18:08:29 »

I fixed the security holes... until somebody finds some class that has a static method named read or write, that has some funny sideeffect.


And another one...

http://213.247.55.3:8484/compileandrun/?assignment=encoder
This one could get extremely small.

(48 bytes)
(46 bytes)
(45 bytes)

Hi, appreciate more people! Σ ♥ = ¾

Learn how to award medals... and work your way up the social rankings
Offline Abuse

JGO Kernel
*****

Posts: 1866
Medals: 5


falling into the abyss of reality


« Reply #107 on: 2007-10-31 18:49:23 »

48,47,46  Cry
Online Riven
« League of Dukes »

JGO Kernel
*****

Posts: 5871
Medals: 255


Hand over your head.


« Reply #108 on: 2007-10-31 18:55:59 »

I watched you in SSH, and you're so damn near the answer...


Hi, appreciate more people! Σ ♥ = ¾

Learn how to award medals... and work your way up the social rankings
Online Riven
« League of Dukes »

JGO Kernel
*****

Posts: 5871
Medals: 255


Hand over your head.


« Reply #109 on: 2007-10-31 18:58:40 »

you need to remember the behaviour of modulo with negative values

Hi, appreciate more people! Σ ♥ = ¾

Learn how to award medals... and work your way up the social rankings
Offline Abuse

JGO Kernel
*****

Posts: 1866
Medals: 5


falling into the abyss of reality


« Reply #110 on: 2007-10-31 19:22:42 »

45!, Got there in the end  Grin
Online Riven
« League of Dukes »

JGO Kernel
*****

Posts: 5871
Medals: 255


Hand over your head.


« Reply #111 on: 2007-10-31 19:28:04 »

Great, you (??) caused a few (harmless) ArithmeticExceptions and NullPointerExceptions on the way  to it Smiley

I passed the getMessage() to the client now.

I only saw those that threw errors, and if your last is like that, you got a completely different solution than I came up with..

1  
for(int b=48;(b^=in.read()%2)>0;out.write(b));

Hi, appreciate more people! Σ ♥ = ¾

Learn how to award medals... and work your way up the social rankings
Offline Abuse

JGO Kernel
*****

Posts: 1866
Medals: 5


falling into the abyss of reality


« Reply #112 on: 2007-10-31 19:31:13 »

yup, that's what I got to in the end.

While I wouldn't stake my life on it, it looks pretty much like the optimal solution...

p.s.

I don't think I was the cause of the exceptions - I do all my testing in Eclipse, only use the submission page to check the size.
Online Riven
« League of Dukes »

JGO Kernel
*****

Posts: 5871
Medals: 255


Hand over your head.


« Reply #113 on: 2007-10-31 19:34:44 »

I see somebody doing extremely clever stuff at the server now, and he keeps getting stuck at 46 bytes.... it's a bit unfair, really

Hi, appreciate more people! Σ ♥ = ¾

Learn how to award medals... and work your way up the social rankings
Offline Abuse

JGO Kernel
*****

Posts: 1866
Medals: 5


falling into the abyss of reality


« Reply #114 on: 2007-10-31 19:39:54 »

Are you using the same class for defining the assignments?

I have an idea for one :-P
Online Riven
« League of Dukes »

JGO Kernel
*****

Posts: 5871
Medals: 255


Hand over your head.


« Reply #115 on: 2007-10-31 19:41:01 »

Yup, I posted the code, and nothing changed yet.


Gimme gimme!

Hi, appreciate more people! Σ ♥ = ¾

Learn how to award medals... and work your way up the social rankings
Online Riven
« League of Dukes »

JGO Kernel
*****

Posts: 5871
Medals: 255


Hand over your head.


« Reply #116 on: 2007-10-31 19:45:11 »

To be honest, I exp[ected more people to join in... this competition is being played by roughly 5 people Smiley


But well, once the assignments get thougher, and the website has user-accounts, things might become better.

Hi, appreciate more people! Σ ♥ = ¾

Learn how to award medals... and work your way up the social rankings
Offline Martin Strand

Jr. Member
**

Posts: 60



« Reply #117 on: 2007-10-31 19:50:16 »

aargh, I give up!  Cheesy I got two similar 46 byte solutions:
1  
2  
3  
4  
5  
for (
int i = 0;
(i ^= in.read()) >= 0;
out.write(48|i)
);


1  
2  
3  
4  
5  
for (
int i = 48;
(i ^= in.read() & 3) < 50;
out.write(i)
);


Martin
Online Riven
« League of Dukes »

JGO Kernel
*****

Posts: 5871
Medals: 255


Hand over your head.


« Reply #118 on: 2007-10-31 19:53:34 »

I witnessed your suffering.

You got two great solutions!

Hi, appreciate more people! Σ ♥ = ¾

Learn how to award medals... and work your way up the social rankings
Offline Abuse

JGO Kernel
*****

Posts: 1866
Medals: 5


falling into the abyss of reality


« Reply #119 on: 2007-10-31 20:34:54 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;


public class ReverseStream extends TinyCodeAssignment {

   public byte[] createQuestion() {
      return str2arr("stun slap swang god . burg slipup stool ergo trams");
   }

   public String getDefaultSource() {
      StringBuilder sb = new StringBuilder();
     
      sb.append("byte [] buffer = new byte[4];\n");
      sb.append("int len = 0;\n");
      sb.append("int b;\n");
      sb.append("while((b=in.read())>=0) {\n");
      sb.append("   buffer[len++] = (byte)b;\n");        
      sb.append("   if(len==buffer.length) {\n");
      sb.append("      byte [] newBuffer = new byte[len*2];\n");
      sb.append("      for(int i = 0;i < len;i++) {\n");
      sb.append("         newBuffer[i] = buffer[i];\n");
      sb.append("      }\n");
      sb.append("      buffer = newBuffer;\n");
      sb.append("   }\n");
      sb.append("}\n\n");
      sb.append("for(int i = len-1;i>=0; i--) {\n");
      sb.append("   out.write(buffer[i]);\n");
      sb.append("}");
     
      return sb.toString();
   }

   public String getDescription() {
      return "Reverse the order of the stream";
   }

   public String getExample() {
      return "ABCD -> DCBA";
   }

   public String getName() {
      return "reverse";
   }

   public String getTitle() {
      return "Reverse";
   }

   public void processCorrectly(InputStream in, OutputStream out)
         throws IOException {
      byte [] buffer = new byte[4];
      int len = 0;
      int b;
      while((b=in.read())>=0) {
         buffer[len++] = (byte)b;        
         if(len==buffer.length) {
            byte [] newBuffer = new byte[len*2];
            for(int i = 0;i < len;i++) {
               newBuffer[i] = buffer[i];
            }
            buffer = newBuffer;
         }
      }
     
      for(int i = len-1;i>=0; i--) {
         out.write(buffer[i]);
      }  
   }
}
Pages: 1 2 3 [4] 5 6
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.131 seconds with 19 queries.