From db488b39bb18ecb992409775584ac868e068a819 Mon Sep 17 00:00:00 2001 From: "pixeebot[bot]" <23113631+pixeebot@users.noreply.github.com> Date: Thu, 5 Oct 2023 20:29:56 +0000 Subject: [PATCH] Introduced protections against predictable RNG abuse --- .../SPDF/controller/api/misc/FakeScanControllerWIP.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/stirling/software/SPDF/controller/api/misc/FakeScanControllerWIP.java b/src/main/java/stirling/software/SPDF/controller/api/misc/FakeScanControllerWIP.java index 68e026ab..099e8411 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/misc/FakeScanControllerWIP.java +++ b/src/main/java/stirling/software/SPDF/controller/api/misc/FakeScanControllerWIP.java @@ -13,6 +13,7 @@ import java.io.ByteArrayOutputStream; //Required for file input/output import java.io.File; import java.io.IOException; +import java.security.SecureRandom; //Other required classes import java.util.Random; @@ -85,7 +86,7 @@ public class FakeScanControllerWIP { op.filter(sourceImage, destinationImage); // Apply a rotation effect - double rotationRequired = Math.toRadians((new Random().nextInt(3 - 1) + 1)); // Random angle between 1 and 3 degrees + double rotationRequired = Math.toRadians((new SecureRandom().nextInt(3 - 1) + 1)); // Random angle between 1 and 3 degrees double locationX = destinationImage.getWidth() / 2; double locationY = destinationImage.getHeight() / 2; AffineTransform tx = AffineTransform.getRotateInstance(rotationRequired, locationX, locationY); @@ -103,7 +104,7 @@ public class FakeScanControllerWIP { destinationImage = blurOp.filter(destinationImage, null); // Add noise to the image based on the "dirtiness" - Random random = new Random(); + Random random = new SecureRandom(); for (int y = 0; y < destinationImage.getHeight(); y++) { for (int x = 0; x < destinationImage.getWidth(); x++) { if (random.nextInt(100) < dirtiness) {