Java Steganography \"Least Significant Bit Insertion\" Program The file binary.t
ID: 3822959 • Letter: J
Question
Java Steganography "Least Significant Bit Insertion" Program
The file binary.txt contains 800 lines representing bytes (one byte per line, each bit represented by a 0 or 1). Write a Java program that will isolate the least significant bit on each line of the file binary.txt and write those bits, eight per line, to a new file. Here is what is in the binary.txt file:
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 0
1 0 1 0 1 0 0 0
1 1 0 0 1 0 1 1
1 1 1 0 0 0 1 1
0 0 0 1 1 1 1 0
1 0 0 1 1 1 1 1
1 0 0 1 1 0 0 1
1 0 0 0 0 0 1 1
0 1 1 1 1 1 0 1
1 1 1 0 1 0 1 1
0 0 0 1 0 1 1 1
0 1 0 1 0 1 0 0
0 1 1 1 0 1 1 0
1 0 0 1 1 0 0 0
1 0 0 1 1 1 1 1
1 0 0 1 1 0 0 0
1 1 1 1 1 0 0 0
1 1 0 1 0 0 0 1
0 1 0 0 0 1 1 1
1 1 1 1 0 1 1 1
1 1 1 1 1 0 0 0
0 0 1 0 1 1 1 1
1 1 1 1 1 0 0 1
0 1 0 0 0 0 0 1
1 1 0 1 1 1 1 0
0 0 0 0 1 0 0 1
1 0 0 1 0 1 0 0
0 1 1 1 0 0 0 1
1 0 0 0 0 1 1 0
1 0 0 0 0 0 0 0
0 1 1 0 1 1 1 1
1 0 0 1 0 1 0 1
1 1 0 1 1 1 0 0
0 0 1 0 1 1 1 1
0 1 0 0 1 1 1 0
0 0 0 0 0 0 0 0
0 1 0 0 1 1 0 1
0 0 1 1 0 0 1 0
0 0 1 0 0 0 1 1
0 0 1 1 0 0 1 1
1 1 1 1 1 0 1 1
0 1 1 1 0 0 0 1
0 1 0 0 0 1 1 0
1 1 0 1 0 1 0 0
1 0 0 1 1 1 1 0
1 0 0 0 1 1 0 0
0 0 1 1 0 0 0 1
1 0 1 1 1 0 0 1
0 0 1 1 0 0 1 0
1 1 1 0 0 1 1 0
1 1 1 0 1 1 1 0
1 1 1 1 0 0 1 1
1 1 1 0 1 1 1 0
0 0 0 1 0 1 1 0
0 1 0 0 1 1 0 1
0 0 0 1 1 1 1 1
1 1 0 1 0 0 1 0
1 1 0 1 1 0 0 1
0 1 0 0 0 1 0 0
1 0 1 0 1 0 0 0
1 1 1 0 0 1 0 0
0 1 0 0 0 0 0 1
1 0 0 1 1 1 0 0
1 0 1 0 1 0 0 1
0 0 0 0 1 1 0 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
Given the input file above the first three lines would be:
0 1 1 0 1 1 0 1
0 0 0 0 1 0 1 1
1 0 1 0 0 1 1 0
Explanation / Answer
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
public class Steganography {
public static void main(String[] args) throws IOException
{
FileReader fr = new FileReader("binary.txt");
Scanner sc = new Scanner(fr);
FileWriter fw = new FileWriter("lsbi.txt");
int i = 1;
while(sc.hasNextLine())
{
String line = sc.nextLine();
fw.write(line.charAt(line.length()-1) + " ");
if (i%8 == 0)
{
i = 0;
fw.write(" ");
}
i++;
}
fw.close();
sc.close();
fr.close();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.