此题考察的是qr码的纠错冗余,利用纠错冗余,将隐写的数据混入到正常数据中,解这个题时用到了boofcv这个java库。原理参考https://jcs.iie.ac.cn/ch/reader/view_abstract.aspx?file_no=20230201&flag=1
/*
* Copyright (c) 2025, Peter Abeles. All Rights Reserved.
*
* This file is part of BoofCV (http://boofcv.org).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package boofcv.examples.fiducial;
import boofcv.abst.fiducial.MicroQrCodeDetector;
import boofcv.alg.fiducial.microqr.MicroQrCode;
import boofcv.alg.fiducial.microqr.MicroQrCodeDecoderBits;
import boofcv.alg.fiducial.microqr.MicroQrCodeEncoder;
import boofcv.alg.fiducial.microqr.MicroQrCodeGenerator;
import boofcv.alg.fiducial.microqr.MicroQrCode.ErrorLevel;
import boofcv.alg.fiducial.qrcode.EciEncoding;
import boofcv.alg.fiducial.qrcode.PackedBits8;
import boofcv.alg.fiducial.qrcode.QrCode;
import boofcv.alg.fiducial.qrcode.QrCodeEncoder;
import boofcv.alg.fiducial.qrcode.QrCode.Mode;
import boofcv.factory.fiducial.ConfigMicroQrCode;
import boofcv.factory.fiducial.FactoryFiducial;
import boofcv.gui.feature.VisualizeShapes;
import boofcv.gui.image.ShowImages;
import boofcv.io.UtilIO;
import boofcv.io.image.ConvertBufferedImage;
import boofcv.io.image.UtilImageIO;
import boofcv.struct.image.GrayU8;
import georegression.struct.point.Point2D_I32;
import static boofcv.alg.fiducial.qrcode.QrCode.Failure.STRING_ENCODING_UNAVAILABLE;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.UnsupportedEncodingException;
import java.util.List;
import org.apache.commons.codec.binary.Hex;
import org.ddogleg.struct.DogArray_I8;
/**
* Shows you how to detect a Micro QR Code inside an image and process the extracted data. Much of the information that
* is computed while detecting and decoding a QR Code is saved inside the {@link MicroQrCode} class. This can be useful
* for application developers.
*
* @author Peter Abeles
*/
public class ExampleDetectMicroQrCode {
public static void main( String[] args ) {
BufferedImage input = UtilImageIO.loadImageNotNull(UtilIO.pathExample("/home/ctf/workspace/MISC_attack/QR/flag_1.png"));
GrayU8 gray = ConvertBufferedImage.convertFrom(input, (GrayU8)null);
var config = new ConfigMicroQrCode();
// config.considerTransposed = false; // by default, it will consider incorrectly encoded markers. Faster if false
MicroQrCodeDetector<GrayU8> detector = FactoryFiducial.microqr(config, GrayU8.class);
detector.process(gray);
// Gets a list of all the qr codes it could successfully detect and decode
List<MicroQrCode> detections = detector.getDetections();
Graphics2D g2 = input.createGraphics();
int strokeWidth = Math.max(4, input.getWidth()/200); // in large images the line can be too thin
g2.setColor(Color.GREEN);
g2.setStroke(new BasicStroke(strokeWidth));
int i=0;
String m="";
String n="";
String o="";
String flipn="";
String flipo="";
for (MicroQrCode qr : detections) {
//System.out.println("corrected: '" + Hex.encodeHexString(qr.corrected) + "'");
//System.out.println("rawbits : '" + Hex.encodeHexString(qr.rawbits).substring(0, 28) + "'");
//System.out.println("totalBitErrors: '" + qr.totalBitErrors + "'");
// The message encoded in the marker
m+=qr.message;
//System.out.println("message: '" + qr.message + "'");
DogArray_I8 flipr=new DogArray_I8();
flipr.data=qr.rawbits;
flipr.size=qr.rawbits.length;
flipBits8(flipr);
flipo+=Hex.encodeHexString(flipr.data).substring(24, 28);
}
System.out.println("flipo: '" + flipo+ "'");
}
public static void flipBits8( DogArray_I8 array ) {
flipBits8(array.data, array.size);
}
public static void flipBits8( byte[] array, int size ) {
for (int j = 0; j < size; j++) {
array[j] = flipBits8(array[j] & 0xFF);
}
}
public static byte flipBits8( int x ) {
int b = 0;
for (int i = 0; i < 8; i++) {
b <<= 1;
b |= (x & 1);
x >>= 1;
}
return (byte)b;
}
}
输出
flipo: '789c73710c760e71ab4ece482c4a4c2e492d8a4fce2fcd2b89cfcc4bc94c4e2cc92f8acf2c8e4f8ccfc94cad050056e11093'
得到的结果其实是zllib压缩的
Cyberchef解压一下