-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStegoMain.java
More file actions
62 lines (51 loc) · 2.52 KB
/
StegoMain.java
File metadata and controls
62 lines (51 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Scanner;
public class StegoMain {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
try {
System.out.print("Podaj ścieżkę do obrazu PNG lub BMP: ");
String imagePath = scanner.nextLine().trim();
File imageFile = new File(imagePath);
if (!imageFile.exists()) {
System.err.println("Plik obrazu nie istnieje: " + imageFile.getAbsolutePath());
return;
}
BufferedImage image = ImageIO.read(imageFile);
if (image == null) {
System.err.println("Nie można wczytać obrazu. Czy to poprawny PNG/BMP?");
return;
}
System.out.print("1. Ukryj wiadomość\n2. Odczytaj wiadomość\nWybierz (1/2): ");
String choice = scanner.nextLine().trim();
if (choice.equals("1")) {
System.out.print("Podaj ścieżkę do pliku tekstowego do ukrycia: ");
String textFilePath = scanner.nextLine().trim();
String message = new String(Files.readAllBytes(Paths.get(textFilePath)), "UTF-8");
System.out.print("Podaj nazwę pliku wynikowego (np. ukryty.png): ");
String outputPath = scanner.nextLine().trim();
Steganography.hideMessage(image, message, outputPath);
System.out.println("Wiadomość została ukryta w obrazie: " + outputPath);
} else if (choice.equals("2")) {
String extracted = Steganography.extractMessage(image);
System.out.println("Odczytana wiadomość:\n" + extracted);
System.out.print("Zapisz wynik do pliku? (t/n): ");
String save = scanner.nextLine().trim();
if (save.equalsIgnoreCase("t")) {
System.out.print("Podaj nazwę pliku wyjściowego: ");
String outputTextPath = scanner.nextLine().trim();
Files.write(Paths.get(outputTextPath), extracted.getBytes("UTF-8"));
System.out.println("Zapisano do pliku: " + outputTextPath);
}
} else {
System.out.println("Niepoprawny wybór.");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}