Questions and Answers

How do I collect points?

  • +5
    Chosen as best answer
  • +1
    Posted answer
  • +1
    Posted question
  • +1
    Thumb up
  • -1
    Thumb down
9

by MRNCT in Challenge Help about November 18, 2017 open - report

Programming 1,3

*EDIT: In python it works fine, so I guess I'm definetely missing something in java, but I don't know what! anyone ?





Hey guys, I think I'm missing something important here.
Programming 1 should be easy. I'm using java to complete those challenges.
I'm getting access to the website, but if I modify the headers and the cookies and send them - nothing really much happens.

same thing with Programming3:
I can easily get the image's RGB in 255;255;255 but if I send it nothing happens.

 

********************SPOILER*********************

The code for programming 1 is pretty easy, but this is the code I'm using for programming 3:

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;

import javax.imageio.ImageIO;
import javax.imageio.stream.ImageInputStream;

public class scrape {

    public static void main(String[] args) {
        try {

            // System.out.println(rawData);
            String type = "application/x-www-form-urlencoded";
            
            URL u = new URL("http://challenges.enigmagroup.org/programming/3/image.php");
            HttpURLConnection conn = (HttpURLConnection) u.openConnection();
            conn.setDoOutput(true);
            conn.setRequestMethod("POST");
            // conn.setRequestProperty("Content-Type", type);
            
            conn.setRequestProperty("Content-Length", 35 + "");
            conn.setRequestProperty("Cookie",MY_COOKIE"); //avoid "You must be logged in for tracking purposes."
            OutputStream os = conn.getOutputStream();
            os.write(encodedData.getBytes());

            ImageInputStream stream = ImageIO.createImageInputStream(conn.getInputStream());
            
            BufferedImage image = ImageIO.read(stream);
            
            int rgb = image.getRGB(0, 0) & 0xffffff;
            int red = (rgb & 0xff0000) >> 16;
            int green = (rgb & 0x00ff00) >> 8;
            int blue = (rgb & 0x0000ff);

            System.out.println(red + "," + green + "," + blue);
            
            String color = red + ";" + green + ";" + blue;
            
            System.out.println(image);
            
            String rawData = "color=" + color + "&submit=1";
            String encodedData = URLEncoder.encode(rawData, "UTF-8");
            os.write(encodedData.getBytes());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

No answers yet. Be the first!
You must login to post an answer.