Skip to content

Instantly share code, notes, and snippets.

@kurtkaiser
Last active August 15, 2018 22:54
Show Gist options
  • Save kurtkaiser/2c4df3c77b8be04a5120de4ad10f01da to your computer and use it in GitHub Desktop.
Save kurtkaiser/2c4df3c77b8be04a5120de4ad10f01da to your computer and use it in GitHub Desktop.
This was an assignment for an advance java class at my local community college. I was asked to get the Least Significant Bit from a text file of binary numbers. Then output the last bit of each line, the LSB, to a new text file. Each line of the new file needed to be eight characters.
/*
Kurt Kaiser
CTIM 168
07.28.2018
Homework: Steganography
Least Significant Bit Insertion
*/
import java.io.*;
import java.util.Scanner;
public class lsbi_KK {
public static void main(String[] args) {
//File stage = new File ("stage.txt");
String fileName = "stage.txt";
PrintWriter outputStream = null;
String[] data = new String[100];
String line = "";
int count = 0;
try {
Scanner inputStream = new Scanner(new File("binary.txt"));
outputStream = new PrintWriter(fileName);
while (inputStream.hasNextLine()) {
// Scan each line of file into a string array
data[count] = inputStream.nextLine();
// Get last character of each line and add to string line
line += data[count].charAt(14);
// Output to document once line is 8 characters
if ((count+1) % 8 == 0) {
outputStream.println(line);
line = "";
}
count++;
}
} catch (FileNotFoundException e){
System.out.println("Error opening the file " + fileName);
System.exit(0);
}
// Output final line to the file, in case final line not 8 characters
outputStream.println(line);
outputStream.close();
}
}
1 1 0 1 1 0 1 1
1 1 0 0 1 0 0 1
1 1 0 1 1 1 0 0
1 0 1 0 0 0 1 1
0 1 0 0 0 0 0 1
1 1 0 1 0 1 0 0
0 1 1 1 1 0 0 1
1 1 1 0 0 1 1 1
1 1 0 0 0 0 1 0
1 0 0 1 0 0 1 1
1 1 0 1 0 0 1 1
0 0 0 0 0 0 1 0
1 0 1 0 0 0 0 0
0 0 0 0 1 1 1 0
1 0 0 0 1 0 1 0
1 1 1 0 0 1 0 1
1 0 0 0 0 1 1 1
1 1 0 1 0 1 0 0
0 1 1 0 0 0 0 0
0 0 1 1 1 1 1 0
1 0 0 1 0 1 0 1
0 1 1 1 0 1 0 1
0 1 1 1 1 1 0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 1
0 0 1 0 1 1 0 1
0 0 1 0 0 1 1 0
0 1 0 0 1 0 0 0
0 1 1 1 1 0 1 0
0 0 1 0 1 0 0 0
1 0 0 1 0 1 1 0
0 0 0 0 0 1 1 1
1 1 1 1 0 1 0 1
0 0 0 1 0 0 0 0
0 1 1 0 1 0 1 0
1 0 1 1 1 1 1 1
1 0 0 0 1 0 1 0
0 1 1 1 1 1 0 0
11011011
01100001
10001100
11011111
10001001
11011101
01001101
00101111
00001100
01001101
00010111
00000110
0100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment