2021西湖论剑misc——Yusa的小秘密

下载附件得到小姐姐的图片

Stegsolve看一下,G0和R0通道发现疑似flag的字符串
2021西湖论剑misc——Yusa的小秘密_第1张图片
2021西湖论剑misc——Yusa的小秘密_第2张图片
将图片颜色空间变为YCbCr,再反转颜色,即可在R0发现完整flag

DASCTF{2947b683036d49e5681f83f7bc3fbb34}

2021西湖论剑misc——Yusa的小秘密_第3张图片
大佬用python轻而易举就能搞出来,我不会。。。
搞了个java版,奉上代码

import java.io.File;
import java.io.FileInputStream;

import javax.imageio.ImageIO;

/**
 * @Author: Jack Jparrow
 * @Date: 2021-11-22 17:52:21
 * @LastEditTime: 2021-11-22 20:47:18
 * @LastEditors: Jack Jparrow
 * @Description: 颜色空间转换为ycbcr,反转颜色,2021西湖论剑misc Yusa的小秘密
 */

public class rev_col {

    public static void main(String[] args) {
        String init_pic_pat_in = "D:\\Desktop\\1.png";// 原图
        String pic_pat_out_ycbcr = "D:\\Desktop\\ycb.png";// 转换颜色空间的图
        String pic_pat_out_res = "D:\\Desktop\\res.png";// 此为最终结果

        rgbToYcbcr(init_pic_pat_in, pic_pat_out_ycbcr);
        revcol(pic_pat_out_ycbcr, pic_pat_out_res);
    }

    /**
     * rgb转ycbcr
     * 
     * @param pic_pat_in
     * @param pic_pat_out_ycbcr
     */
    static void rgbToYcbcr(String pic_pat_in, String pic_pat_out_ycbcr) {
        try {
            FileInputStream in = new FileInputStream(pic_pat_in);
            java.awt.image.BufferedImage image = ImageIO.read(in);

            int wid = image.getWidth();
            int hei = image.getHeight();

            java.awt.image.BufferedImage bim = new java.awt.image.BufferedImage(wid, hei, java.awt.image.BufferedImage.TYPE_INT_RGB);

            int ycbcr[] = new int[3];
            for (int i = 0; i < hei; i++) {
                for (int j = 0; j < wid; j++) {
                    int rgb = image.getRGB(j, i);
                    int r = (rgb & 0xff0000) >> 16;
                    int g = (rgb & 0x00ff00) >> 8;
                    int b = rgb & 0x0000ff;

                    ycbcr[0] = (int) (0.299 * r + 0.587 * g + 0.114 * b);
                    ycbcr[1] = (int) (-0.1687 * r - 0.3313 * g + 0.5 * b + 128);
                    if (ycbcr[1] > 255) {
                        ycbcr[1] = 255;
                    }
                    ycbcr[2] = (int) (0.299 * r + 0.587 * g + 0.114 * b);
                    if (ycbcr[2] > 255) {
                        ycbcr[2] = 255;
                    }

                    int col_ycb = colToRgb(ycbcr[0], ycbcr[1], ycbcr[2]);// 以rgb形式写入图片
                    bim.setRGB(j, i, col_ycb);
                }
            }

            ImageIO.write(bim, "png", new File(pic_pat_out_ycbcr));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // ↓借鉴自:https://www.icodebang.com/article/268992

    /**
     * 获取图片颜色的rgb值
     * 
     * @param r
     * @param g
     * @param b
     * @return
     */
    static int colToRgb(int r, int g, int b) {
        int rgb_new = 0;

        rgb_new = rgb_new << 8;
        rgb_new += r;
        rgb_new = rgb_new << 8;
        rgb_new += g;
        rgb_new = rgb_new << 8;
        rgb_new += b;

        return rgb_new;
    }

    /**
     * 翻转rgb颜色
     * 
     * @param pic_pat_in
     * @param pic_pat_out_rgb
     */
    static void revcol(String pic_pat_in, String pic_pat_out_rgb) {
        try {
            FileInputStream in = new FileInputStream(pic_pat_in);
            java.awt.image.BufferedImage image = ImageIO.read(in);

            int wid = image.getWidth();
            int hei = image.getHeight();

            java.awt.image.BufferedImage bim = new java.awt.image.BufferedImage(wid, hei,
                    java.awt.image.BufferedImage.TYPE_INT_RGB);

            for (int i = 0; i < hei; i++) {
                for (int j = 0; j < wid; j++) {
                    int rgb = image.getRGB(j, i);
                    int r = (rgb & 0xff0000) >> 16;
                    int g = (rgb & 0x00ff00) >> 8;
                    int b = rgb & 0x0000ff;
                    int rgb_new = colToRgb(255 - r, 255 - g, 255 - b);

                    bim.setRGB(j, i, rgb_new);
                }
            }

            ImageIO.write(bim, "png", new File(pic_pat_out_rgb));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

你可能感兴趣的:(比赛WP,网络安全,java)