Commit 3a185727 by Tobias

added gifshuffle test (currently failing)

1 parent b727a5e1
......@@ -10,7 +10,7 @@ public class Stegosuite {
public static void main(String[] args) {
Logger root = (Logger) LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
root.setLevel(Level.INFO);
root.setLevel(Level.DEBUG);
if (args.length == 0) {
new Gui(null);
} else if (args[0].startsWith("-")) {
......
......@@ -26,6 +26,15 @@ public class StegosuitePresenter implements EmbeddingDoneListener, ExtractingDon
private ImageFormat image;
private Payload payload;
private Embedding embedding;
public void setEmbedding(EmbeddingFactory embeddingAlgorithm) {
if (embeddingAlgorithm == null) {
this.embedding = embeddingFor(image);
} else {
this.embedding = embeddingAlgorithm.newEmbedding(image);
}
}
private StegosuiteUI ui;
private EmbeddingProgress progressListener = new EmbeddingProgress();
......
package org.stegosuite.image.embedding.gif;
import java.awt.Color;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.stegosuite.image.embedding.EmbeddingMethod;
import org.stegosuite.image.embedding.EmbeddingProgress;
import org.stegosuite.image.embedding.point.PointFilter;
......@@ -14,13 +26,6 @@ import org.stegosuite.util.ByteUtils;
import org.stegosuite.util.ColorDistance;
import org.stegosuite.util.CryptoUtils;
import java.awt.*;
import java.math.BigInteger;
import java.util.*;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
/**
* GIFShuffle embedding and extracting procedures. Source: http://www.darkside.com.au/gifshuffle/
*
......@@ -28,6 +33,8 @@ import java.util.stream.IntStream;
public class GIFShuffle
extends EmbeddingMethod<GIFImage> {
private static final Logger LOG = LoggerFactory.getLogger(GIFShuffle.class);
public GIFShuffle(GIFImage image, PointFilter<GIFImage> pointFilter) {
super(image, pointFilter);
}
......@@ -41,6 +48,7 @@ public class GIFShuffle
protected int doCapacity(GIFImage image) {
int numColors = image.getColorTable().size();
double sum = IntStream.range(2, numColors + 1).mapToDouble(i -> Math.log(i) / Math.log(2)).sum();
LOG.debug("Capacity: {}",(int) (sum / 8) - 1);
return (int) (sum / 8) - 1;
}
......@@ -53,6 +61,9 @@ public class GIFShuffle
List<Color> randomTable = image.getSortedColorTable(DISTANCE);
Collections.shuffle(randomTable, CryptoUtils.seededRandom(payload.getSteganoPassword()));
LOG.debug("origtable size: {}",originalTable.size());
LOG.debug("sortedtable size: {}",randomTable.size());
// Prepend 1 to the payload so that leading 0 bytes are not cut off
PayloadEmbedder embedder = new PayloadEmbedder(payload, this.capacity());
BigInteger numPayload = new BigInteger(ByteUtils.concat(new byte[] { 1 }, embedder.getPayloadBytes()));
......
......@@ -89,6 +89,9 @@ public class GIFSortedColorTable
int[] pixels = image.getPixels().clone();
List<Color> table = image.getColorTable();
List<Color> sortedTable = image.getSortedColorTable(DISTANCE);
LOG.debug("origtable size: {}",table.size());
LOG.debug("sortedtable size: {}",sortedTable.size());
Set<Color> unreferencedColorsBefore = ColorUtils.getUnreferencedColors(table, pixels);
int currentBit = 0;
......
......@@ -75,7 +75,10 @@ public class PayloadEmbedder {
// Fill header with length and encryption flag
byte[] lengthBytes = Arrays.copyOfRange(ByteUtils.intToBytes(data.length), 4 - Payload.LENGTH_NUM_BYTES, 4);
data = ByteBuffer.wrap(data).put(lengthBytes).array();
LOG.debug("lengthBytes-Array: {}",Arrays.toString(lengthBytes));
LOG.debug("data-Array: {}",Arrays.toString(data));
Double percentage = data.length * 100.0 / capacity;
LOG.debug("Packed payload to {} bytes, {}% of total capacity", data.length, DECIMAL.format(percentage));
}
......
......@@ -143,6 +143,7 @@ public class PayloadExtractor {
}
LOG.debug("Payload of {} bytes to be extracted", payloadLength + Payload.LENGTH_NUM_BYTES);
LOG.debug("Array: {}",Arrays.toString(dataSizeBytes));
data = new byte[payloadLength];
dataPos = 0;
......
......@@ -8,6 +8,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.stegosuite.application.StegosuitePresenter;
import org.stegosuite.application.StegosuiteUI;
import org.stegosuite.image.embedding.EmbeddingProgress;
import org.stegosuite.image.embedding.Visualizer;
import org.stegosuite.image.format.ImageFormat;
import org.stegosuite.model.exception.SteganoEmbedException;
......@@ -59,7 +60,7 @@ public class Cli
private void embed(String key) {
LOG.info("Embedding data...");
presenter.embed(key);
presenter.embedNotifying(new EmbeddingProgress(), key);
}
public void extract(CommandLine cmd) {
......@@ -76,7 +77,7 @@ public class Cli
private void extract(String key) {
LOG.info("Extracting data...");
presenter.extractUsing(key);
presenter.extractNotifying(new EmbeddingProgress(), key);
}
public void capacity(CommandLine cmd) {
......
......@@ -5,6 +5,7 @@ import org.junit.After;
import org.junit.Test;
import org.stegosuite.application.StegosuitePresenter;
import org.stegosuite.application.StegosuiteUI;
import org.stegosuite.application.embedding.EmbeddingFactory;
import org.stegosuite.image.embedding.EmbeddingProgress;
import org.stegosuite.image.embedding.Visualizer;
import org.stegosuite.image.format.ImageFormat;
......@@ -29,6 +30,7 @@ public class EmbeddingAndExtractingTest {
private final StegosuiteUI ui = new UIStub();
private String outputPath;
private String extractedMessage;
private EmbeddingFactory embeddingAlgorithm = null;
@After
public void tearDown() throws Exception {
......@@ -37,7 +39,14 @@ public class EmbeddingAndExtractingTest {
@Test
public void testEmbeddingAndExtractingFromGifFile() throws Exception {
testEmbeddingAndThenExtractingOk("sunflower.gif");
testEmbeddingAndThenExtractingOk("sunflower2.gif");
}
@Test
public void testEmbeddingAndExtractingFromGifFileUsingGifshuffle() throws Exception {
embeddingAlgorithm = EmbeddingFactory.GIFSHUFFLE;
testEmbeddingAndThenExtractingOk("sunflower2.gif");
embeddingAlgorithm = null;
}
@Test
......@@ -84,6 +93,7 @@ public class EmbeddingAndExtractingTest {
private void embedPayload(String imageName, String password, String message) throws SteganoImageException, SteganoEmbedException {
String imagePath = pathOf(imageName);
StegosuitePresenter presenter = getPresenterFor(imagePath);
presenter.setEmbedding(embeddingAlgorithm);
presenter.addMessageToPayload(message);
presenter.embedNotifying(new EmbeddingProgress(), password);
}
......@@ -122,5 +132,5 @@ public class EmbeddingAndExtractingTest {
@Override
public void addPayloadFile(String filename, String extension, long fileSize) {
}
}
}
}
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!