Keith and Dawg 5

By: Jason Yang

NOTE: Do Keith and Dawg 4 first.

Another mysterious communique from Jazz Money. This time, it was in the form of a carrier pigeon. Keith caught the pigeon, and unwrapped the message.

"Mr. Keith. Your new assignment is to figure out the password to one of Degen's security measures. Attached to the leg of this pigeon you will find a flash drive with the relevant files. This is the only secure way of transporting such a high value object. Furthermore, we have stored all documents necessary in an encrypted compressed file, where the password is the J Dawg's PIN you previously found, to ensure that should this pigeon get intercepted, the information will not fall into the wrong hands. We have gone to great lengths to ensure the secrecy of this information, so you must complete the assignment as quickly as possible. Jazz Money out."

After several hours of intense study, here's what Keith has figured out:

  • lock.jar is the main locking program.
  • lock.jar is run with "java -jar lock.jar"
  • On a terminal with ANSI escape sequences, use "java -jar lock.jar ansi"

Find the correct password.

To be continued...


Boot.java

package opencl;


import java.io.BufferedReader;
import java.io.Console;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.util.List;
import java.util.Scanner;

import javax.swing.JOptionPane;

import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLException;
import org.lwjgl.PointerBuffer;
import org.lwjgl.opencl.CL;
import org.lwjgl.opencl.CL10;
import org.lwjgl.opencl.CLCommandQueue;
import org.lwjgl.opencl.CLContext;
import org.lwjgl.opencl.CLDevice;
import org.lwjgl.opencl.CLKernel;
import org.lwjgl.opencl.CLMem;
import org.lwjgl.opencl.CLPlatform;
import org.lwjgl.opencl.CLProgram;
import org.lwjgl.opencl.Util;

/**
 * @author Jason Yang
 *
 */

public class Boot {
    // OpenCL variables
    public CLContext context;
    public CLPlatform platform;
    public List<CLDevice> devices;
    public CLDevice device;
    public CLCommandQueue queue;

    int[] array;

    String check = "NgLn TQvscdUp@k\\e^n(Jb";

    public static String ANSI_RESET = "";
    public static String ANSI_BLACK = "";
    public static String ANSI_RED = "";
    public static String ANSI_GREEN = "";
    public static String ANSI_YELLOW = "";
    public static String ANSI_BLUE = "";
    public static String ANSI_PURPLE = "";
    public static String ANSI_CYAN = "";
    public static String ANSI_WHITE = "";

    static long t;

    public static void main(String[] args){
        try {
            if (args.length > 0){
                if (args[0].toLowerCase().equals("ansi")){
                    ANSI_RESET = "\u001B[0m";
                    ANSI_BLACK = "\u001B[30;1m";
                    ANSI_RED = "\u001B[31;1m";
                    ANSI_GREEN = "\u001B[32;1m";
                    ANSI_YELLOW = "\u001B[33;1m";
                    ANSI_BLUE = "\u001B[34;1m";
                    ANSI_PURPLE = "\u001B[35;1m";
                    ANSI_CYAN = "\u001B[36;1m";
                    ANSI_WHITE = "\u001B[37;1m";
                }
            }
            new Boot().run();
        } catch (LWJGLException e) {
            e.printStackTrace();
        }
    }

    public void run() throws LWJGLException {
        initializeCL();

        loadPass();

        String source = loadText("/opencl/kernel.cl");

        System.out.println(ANSI_YELLOW + "[INFO] " + ANSI_RESET + "Building kernel...");
        CLProgram program = CL10.clCreateProgramWithSource(context, source, null);
        int error = CL10.clBuildProgram(program, devices.get(0), "", null);
        if (error == 0)
            System.out.print(ANSI_RESET);
        else
            System.out.print(ANSI_RED);
        System.out.println(program.getBuildInfoString(device, CL10.CL_PROGRAM_BUILD_LOG) + ANSI_RESET);

        Util.checkCLError(error);
        CLKernel kernel = CL10.clCreateKernel(program, "ctf", null);
        System.out.println(ANSI_GREEN + "done.");

        final int size = check.length();
        IntBuffer errorBuff = BufferUtils.createIntBuffer(1);

        System.out.println(ANSI_CYAN + "[MESSAGE] " + ANSI_RESET + "Input the password:" + ANSI_RED);
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String aString = "";
        try {
            aString = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }

        System.out.print(ANSI_YELLOW + "[INFO] " + ANSI_RESET + "Creating arrays...");
        float[] aData = new float[size];
        for (int i = 0; i < size; i++){
            char c;
            if (i >= aString.length()){
                c = ' ';
            } else {
                c = aString.charAt(i);
            }

            int n = (int) c;
            aData[i] = n;
        }

        float[] bData = new float[size];
        for (int i = 0; i < size; i++){
            bData[i] = array[i];
        }
        System.out.println(ANSI_GREEN + "done.");

        System.out.print(ANSI_YELLOW + "[INFO] " + ANSI_RESET + "Creating buffers in memory...");
        FloatBuffer aBuff = BufferUtils.createFloatBuffer(size);
        aBuff.put(aData);
        aBuff.rewind();

        CLMem aMemory = CL10.clCreateBuffer(context, CL10.CL_MEM_WRITE_ONLY | CL10.CL_MEM_COPY_HOST_PTR, aBuff, errorBuff);
        Util.checkCLError(errorBuff.get(0));

        FloatBuffer bBuff = BufferUtils.createFloatBuffer(bData.length);
        bBuff.put(bData);
        bBuff.rewind();

        CLMem bMemory = CL10.clCreateBuffer(context, CL10.CL_MEM_WRITE_ONLY | CL10.CL_MEM_COPY_HOST_PTR, bBuff, errorBuff);
        Util.checkCLError(errorBuff.get(0));

        CLMem resultMemory = CL10.clCreateBuffer(context, CL10.CL_MEM_READ_ONLY, size*4, errorBuff);
        System.out.println(ANSI_GREEN + "done.");

        System.out.print(ANSI_YELLOW + "[INFO] " + ANSI_RESET + "Checking for errors...");
        Util.checkCLError(errorBuff.get(0));
        System.out.println(ANSI_GREEN + "done.");

        System.out.print(ANSI_YELLOW + "[INFO] " + ANSI_RESET + "Setting kernel parameters...");
        kernel.setArg(0, aMemory);
        kernel.setArg(1, bMemory);
        kernel.setArg(2, resultMemory);
        kernel.setArg(3, size);
        System.out.println(ANSI_GREEN + "done.");

        System.out.print(ANSI_YELLOW + "[INFO] " + ANSI_RESET + "Creating work size buffer...");
        final int dimensions = 1; 
        PointerBuffer globalWorkSize = BufferUtils.createPointerBuffer(dimensions);
        globalWorkSize.put(0, size);
        System.out.println(ANSI_GREEN + "done.");

        startTime();

        System.out.print(ANSI_YELLOW + "[INFO] " + ANSI_RESET + "Running kernels...");
        CL10.clEnqueueNDRangeKernel(queue, kernel, dimensions, null, globalWorkSize, null, null, null);
        CL10.clFinish(queue);
        System.out.println(ANSI_GREEN + "done.");

        stopTime();

        System.out.print(ANSI_YELLOW + "[INFO] " + ANSI_RESET + "Reading result buffer...");
        FloatBuffer resultBuff = BufferUtils.createFloatBuffer(size);
        CL10.clEnqueueReadBuffer(queue, resultMemory, CL10.CL_TRUE, 0, resultBuff, null, null);
        System.out.println(ANSI_GREEN + "done.");

        String s = "";
        for(int i = 0; i < resultBuff.capacity(); i++) {
            s += (char) resultBuff.get(i);
        }
        System.out.println(ANSI_YELLOW + "[INFO] " + ANSI_RESET + "Time taken: " + t / 1000000000f + " s");
        if (s.equals(check))
            System.out.println(ANSI_YELLOW + "[INFO] " + ANSI_GREEN + "Success! You found the flag (it's the password).");
        else
            System.out.println(ANSI_YELLOW + "[INFO] " + ANSI_RED + "Hah nice try!");

        // Cleanup!
        CL10.clReleaseKernel(kernel);
        CL10.clReleaseProgram(program);

        // More cleanup!
        CL10.clReleaseMemObject(aMemory);
        CL10.clReleaseMemObject(bMemory);
        CL10.clReleaseMemObject(resultMemory);
        destroyCL();
    }

    public void startTime(){
        t = System.nanoTime();
    }

    public void stopTime(){
        t = System.nanoTime() - t;
    }

    public void initializeCL() throws LWJGLException { 
        IntBuffer errorBuf = BufferUtils.createIntBuffer(1);
        System.out.print(ANSI_YELLOW + "[INFO] " + ANSI_RESET + "Creating OpenCL instance...");
        CL.create();
        System.out.println(ANSI_GREEN + "done.");

        List<CLPlatform> platforms = CLPlatform.getPlatforms();
        for (int i = 0; i < platforms.size(); i++){
            CLPlatform p = platforms.get(i);
            System.out.println(ANSI_BLACK + "\n================================\n");
            System.out.println(ANSI_YELLOW + "[INFO] " + ANSI_RESET + "Platform " + i);
            System.out.println(ANSI_YELLOW + "[INFO] " + ANSI_RESET + p.getInfoString(CL10.CL_PLATFORM_NAME));
            System.out.println(ANSI_YELLOW + "[INFO] " + ANSI_RESET + p.getInfoString(CL10.CL_PLATFORM_VENDOR));
            System.out.println(ANSI_YELLOW + "[INFO] " + ANSI_RESET + p.getInfoString(CL10.CL_PLATFORM_VERSION));
            System.out.println(ANSI_YELLOW + "[INFO] " + ANSI_RESET + p.getInfoString(CL10.CL_PLATFORM_PROFILE));
            System.out.println(ANSI_YELLOW + "[INFO] " + ANSI_RESET + p.getInfoString(CL10.CL_PLATFORM_EXTENSIONS));
            System.out.println("\n");

            List<CLDevice> devices = p.getDevices(CL10.CL_DEVICE_TYPE_GPU);
            for (int j = 0; j < devices.size(); j++){
                CLDevice d = devices.get(j);
                System.out.println(ANSI_YELLOW + "[INFO] " + ANSI_RESET + "Device " + j);
                System.out.println(ANSI_YELLOW + "[INFO] " + ANSI_RESET + d.getInfoString(CL10.CL_DEVICE_NAME));
                System.out.println(ANSI_YELLOW + "[INFO] " + ANSI_RESET + d.getInfoString(CL10.CL_DEVICE_VERSION));
                System.out.println(ANSI_YELLOW + "[INFO] " + ANSI_RESET + d.getInfoString(CL10.CL_DEVICE_VENDOR));
                System.out.println("\n");
            }
        }

        int plat = 0;
        try {
            System.out.println(ANSI_CYAN + "[MESSAGE] " + ANSI_RESET + "Input platform id:" + ANSI_CYAN);
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            plat = Integer.parseInt(br.readLine());
        } catch (NumberFormatException e){
            System.out.println(ANSI_RED + "[ERROR] " + ANSI_RESET + "Not a number...exiting");
            System.exit(0);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        platform = CLPlatform.getPlatforms().get(plat);
        System.out.println(ANSI_YELLOW + "[INFO] " + ANSI_RESET + platform.getInfoString(CL10.CL_PLATFORM_NAME));

        int dev = 0;
        try {
            System.out.println(ANSI_CYAN + "[MESSAGE] " + ANSI_RESET + "Input device id:" + ANSI_CYAN);
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            dev = Integer.parseInt(br.readLine());
        } catch (NumberFormatException e){
            System.out.println(ANSI_RED + "[ERROR] " + ANSI_RESET + "Not a number...exiting");
            System.exit(0);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        devices = platform.getDevices(CL10.CL_DEVICE_TYPE_GPU);
        device = devices.get(dev);
        System.out.println(ANSI_YELLOW + "[INFO] " + ANSI_RESET + device.getInfoString(CL10.CL_DEVICE_NAME));

        System.out.print(ANSI_YELLOW + "[INFO] " + ANSI_RESET + "Creating OpenCL context...");
        context = CLContext.create(platform, devices, errorBuf);
        System.out.println(ANSI_GREEN + "done.");

        System.out.print(ANSI_YELLOW + "[INFO] " + ANSI_RESET + "Creating command queue...");
        queue = CL10.clCreateCommandQueue(context, device, CL10.CL_QUEUE_PROFILING_ENABLE, errorBuf);
        Util.checkCLError(errorBuf.get(0)); 
        System.out.println(ANSI_GREEN + "done.");
    }


    public void destroyCL() {
        System.out.print(ANSI_YELLOW + "[INFO] " + ANSI_RESET + "Releasing resources...");
        // Finish destroying anything we created
        CL10.clReleaseCommandQueue(queue);
        CL10.clReleaseContext(context);
        // And release OpenCL, after this method call we cannot use OpenCL unless we re-initialize it
        CL.destroy();
        System.out.println(ANSI_GREEN + "done." + ANSI_RESET);
    }


    public String loadText(String name) {
        System.out.print(ANSI_YELLOW + "[INFO] " + ANSI_RESET + "Loading " + name + "...");
        InputStream is = null;
        BufferedReader br = null;
        String source = null;
        try {
            // Get the file containing the OpenCL kernel source code
            is = Boot.class.getResourceAsStream(name);
            // Create a buffered file reader for the source file
            br = new BufferedReader(new InputStreamReader(is));
            // Read the file's source code line by line and store it in a string builder
            String line = null;
            StringBuilder result = new StringBuilder();
            while((line = br.readLine()) != null) {
                result.append(line);
                result.append("\n");
            }
            // Convert the string builder into a string containing the source code to return
            source = result.toString();
        } catch(NullPointerException npe) {
            npe.printStackTrace();
        } catch(IOException ioe) {
            ioe.printStackTrace();
        } finally {
            try {
                br.close();
                is.close();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }

        System.out.println(ANSI_GREEN + "done.");
        return source;
    }

    public void loadPass(){
        String s = loadText("/opencl/pass.key");
        array = new int[s.length()];
        for (int i = 0; i < s.length(); i++){
            try {
                array[i] = Integer.parseInt(Character.toString(s.charAt(i)));
            } catch (NumberFormatException e){}
        }
    }

}

kernel.cl

kernel void ctf(global float* a, global float*b, global float* result, int const size) {
    const int itemId = get_global_id(0);
    if (itemId < size){
        float4 p = (float4)(4, 0, a[itemId], 3);
        float4 q = (float4)(8, b[itemId], -6, 7);
        float8 m = p.xwxyzyzy;
        float8 n = q.zyzwxyzw;
        float s = dot(m.even, n.lo);
        float t = dot(m.odd, n.hi);
        result[itemId] = s + t;
    }
}

pass.key

161803398874989484820458683436563811772030917980576286213544862270526046281890244970720720418939113748475408807538689175212663386222353693179318006076672635443338908659593958290563832266131992829026788067520876689250171169620703222104321626954862629631361443814975870122034080588795445474924618569536486444924104432077134494704956584678850987433944221254487706647809158846074998871240076521705751797883416625624940758906970400028121042762177111777805315317141011704666599146697987317613560067087480710131795236894275219484353056783002287856997829778347845878228911097625003026961561700250464338243776486102838312683303724292675263116533924731671112115881863851331620384005222165791286675294654906811317159934323597349498509040947621322298101726107059611645629909816290555208524790352406020172799747175342777592778625619432082750513121815628551222480939471234145170223735805772786160086883829523045926478780178899219902707769038953219681986151437803149974110692608867429622675756052317277752035361393621076738937645560606059216589466759551900400555908950229530942312482355212212415444006470340565734797663972394949946584578873039623090375033993856210242369025138680414577995698122445747178034173126453220416397232134044449487302315417676893752103068737880344170093954409627955898678723209512426893557309704509595684401755519881921802064052905518934947592600734852282101088194644544222318891319294689622002301443770269923007803085261180754519288770502109684249362713592518760777884665836150238913493333122310533923213624319263728910670503399282265263556209029798642472759772565508615487543574826471814145127000602389016207773224499435308899

results matching ""

    No results matching ""