Commit 74a370f8 authored by Ethan Ordentlich's avatar Ethan Ordentlich
Browse files

Initial commit

parents
No related merge requests found
Pipeline #47468 canceled with stage
Showing with 369 additions and 0 deletions
+369 -0
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
#.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
static:
script: /testers/cs2/lab10/static/test
A:
script: /testers/cs2/lab10/suite/test
B:
script: /testers/cs2/lab10/suite/test
C:
script: /testers/cs2/lab10/suite/test
<component name="libraryTable">
<library name="com.github.javaparser:javaparser-core:3.5.12" type="repository">
<properties maven-id="com.github.javaparser:javaparser-core:3.5.12" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/com/github/javaparser/javaparser-core/3.5.12/javaparser-core-3.5.12.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="org.hamcrest:hamcrest-core:2.2" type="repository">
<properties maven-id="org.hamcrest:hamcrest-core:2.2" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/2.2/hamcrest-core-2.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest/2.2/hamcrest-2.2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="org.junit.jupiter:junit-jupiter:5.6.0-M1" type="repository">
<properties maven-id="org.junit.jupiter:junit-jupiter:5.6.0-M1" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter/5.6.0-M1/junit-jupiter-5.6.0-M1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.6.0-M1/junit-jupiter-api-5.6.0-M1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/apiguardian/apiguardian-api/1.1.0/apiguardian-api-1.1.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.6.0-M1/junit-platform-commons-1.6.0-M1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-params/5.6.0-M1/junit-jupiter-params-5.6.0-M1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-engine/5.6.0-M1/junit-jupiter-engine-5.6.0-M1.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-engine/1.6.0-M1/junit-platform-engine-1.6.0-M1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/lab10-steganography.iml" filepath="$PROJECT_DIR$/lab10-steganography.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="A Tests" type="JUnit" factoryName="JUnit">
<module name="lab10-steganography" />
<option name="MAIN_CLASS_NAME" value="A" />
<option name="METHOD_NAME" value="" />
<option name="TEST_OBJECT" value="tags" />
<option name="PARAMETERS" value="" />
<tag value="A" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>
\ No newline at end of file
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="B Tests" type="JUnit" factoryName="JUnit">
<module name="lab10-steganography" />
<option name="MAIN_CLASS_NAME" value="B" />
<option name="METHOD_NAME" value="" />
<option name="TEST_OBJECT" value="tags" />
<option name="PARAMETERS" value="" />
<tag value="B" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>
\ No newline at end of file
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="C Tests" type="JUnit" factoryName="JUnit">
<module name="lab10-steganography" />
<option name="MAIN_CLASS_NAME" value="" />
<option name="METHOD_NAME" value="" />
<option name="TEST_OBJECT" value="tags" />
<option name="PARAMETERS" value="" />
<tag value="C" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>
\ No newline at end of file
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="ImageManipulator" type="Application" factoryName="Application">
<option name="MAIN_CLASS_NAME" value="edu.caltech.cs2.lab10.ImageManipulator" />
<module name="lab10-steganography" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/images" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="com.github.javaparser:javaparser-core:3.5.12" level="project" />
<orderEntry type="library" name="org.hamcrest:hamcrest-core:2.2" level="project" />
<orderEntry type="library" name="org.junit.jupiter:junit-jupiter:5.6.0-M1" level="project" />
</component>
</module>
\ No newline at end of file
package edu.caltech.cs2.lab10;
import edu.caltech.cs2.libraries.Pixel;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
public class Image {
private Pixel[][] pixels;
public Image(File imageFile) throws IOException {
BufferedImage img = ImageIO.read(imageFile);
this.pixels = new Pixel[img.getWidth()][img.getHeight()];
for (int i = 0; i < img.getWidth(); i++) {
for (int j = 0; j < img.getHeight(); j++) {
this.pixels[i][j] = Pixel.fromInt(img.getRGB(i, j));
}
}
}
private Image(Pixel[][] pixels) {
this.pixels = pixels;
}
public Image transpose() {
return null;
}
public String decodeText() {
return null;
}
public Image hideText(String text) {
return null;
}
public BufferedImage toBufferedImage() {
BufferedImage b = new BufferedImage(this.pixels.length, this.pixels[0].length, BufferedImage.TYPE_4BYTE_ABGR);
for (int i = 0; i < this.pixels.length; i++) {
for (int j = 0; j < this.pixels[0].length; j++) {
b.setRGB(i, j, this.pixels[i][j].toInt());
}
}
return b;
}
public void save(String filename) {
File out = new File(filename);
try {
ImageIO.write(this.toBufferedImage(), filename.substring(filename.lastIndexOf(".") + 1, filename.length()), out);
} catch (IOException e) {
e.printStackTrace();
}
}
}
package edu.caltech.cs2.lab10;
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
public class ImageManipulator {
public static void main(String[] args) throws IOException {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the filename you'd like to work with: ");
String inFilename = scanner.nextLine();
// get the filename without the .png
String[] splitfile = inFilename.split("\\.");
String name = splitfile[0];
// turn the file into an image
File in = new File("images/" + inFilename);
Image img = new Image(in);
boolean keepAsking = true;
while(keepAsking) {
System.out.print("What would you like to do wih the image (transpose, hide, decode or quit)? ");
String action = scanner.nextLine();
if (action.equals("transpose")) {
String outFilename = name + ".transpose.png";
//transpose image and save it
Image transposedImage = img.transpose();
transposedImage.save("images/" + outFilename);
System.out.println("Image was transposed!");
}
else if (action.equals("hide")) {
System.out.print("What message would you like to hide? ");
String textToHide = scanner.nextLine();
// setup the output file
String outFilename = name + ".hidden.png";
// output file with hidden text
Image imgWithText = img.hideText(textToHide);
imgWithText.save("images/" + outFilename);
System.out.println("Message was hidden!");
}
else if (action.equals("decode")) {
System.out.println("The hidden message is: " + img.decodeText());
}
else if (action.equals("quit")) {
keepAsking = false;
}
else {
System.out.println("Invalid input.");
}
}
}
}
package edu.caltech.cs2.libraries;
/**
* This class represents an ARGB pixel in an image.
*/
public class Pixel {
public final int a;
public final int r;
public final int g;
public final int b;
private Pixel(int a, int r, int g, int b) {
this.a = a;
this.r = r;
this.g = g;
this.b = b;
}
public static Pixel fromInt(int argb) {
int a = (argb & 0xFF000000) >> 24;
int r = (argb & 0x00FF0000) >> 16;
int g = (argb & 0x0000FF00) >> 8;
int b = (argb & 0x000000FF) >> 0;
return new Pixel(a, r, g, b);
}
public int toInt() {
return (a << 24) | (r << 16) | (g << 8) | b;
}
/**
* Returns a new pixel with the lowest bit of the red channel set to {@code lowR}.
* @param lowR the value to set the low bit of the red channel to
* @return an altered pixel that has the lowest bit of the red channel set to {@code lowR}
*/
public Pixel fixLowestBitOfR(int lowR) {
if ((lowR != 0 && lowR != 1)) {
throw new IllegalArgumentException("lowR must represent a bit!");
}
int r = (this.r & 0xFE) | lowR;
return new Pixel(this.a, r, this.g, this.b);
}
/**
* Returns the LSB of the red channel in this pixel
* @return the LSB of the red channel in this pixel
*/
public int getLowestBitOfR() {
return this.r & 0x1;
}
}
tests/data/MonaLisa.hidden.png

58.3 KB

tests/data/MonaLisa.png

46.5 KB

tests/data/MonaLisa.transposed.png

65.3 KB

tests/data/SonOfMan.hidden.png

213 KB

Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment