Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
117 lines (105 loc) · 4.81 KB
/
Copy pathProgram.cs
File metadata and controls
117 lines (105 loc) · 4.81 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
using System;
using System.Diagnostics;
using System.Security.Cryptography;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Metadata;
using SixLabors.ImageSharp.Formats.Png;
using Konscious.Security.Cryptography;
namespace StealthCryptPixel
{
class Program
{
static void Main(string[] args)
{
Console.ForegroundColor = ConsoleColor.Magenta;
Console.WriteLine("=== StealthCryptPixel V4 ===\n");
Console.ResetColor();
if (args.Length == 0) { PrintHelp(); return; }
if (args.Length < 2 && args[0] != "-t5") { PrintHelp(); return; }
var sw = Stopwatch.StartNew();
string mode = args[0];
byte[]? password = null;
try
{
if (mode == "-c" || mode == "-c5")
{
string inputFile = args[1];
List<string> donorImages;
if (File.Exists(args[2]) && ImageIo.IsImageFile(args[2]))
{
password = PasswordPrompt.PromptPassword(confirm: true);
donorImages = args.Skip(2).ToList();
}
else
{
password = Encoding.UTF8.GetBytes(args[2]);
donorImages = args.Skip(3).ToList();
}
ValidateInputs(inputFile, donorImages);
if (mode == "-c5") AdaptiveV5.EncryptV5(inputFile, donorImages, password);
else ShardedV4.EncryptSharded(inputFile, donorImages, password);
}
else if (mode == "-d" || mode == "-d5")
{
string lastArg = args[args.Length - 1];
List<string> stegoImages;
if (File.Exists(lastArg) && ImageIo.IsImageFile(lastArg))
{
stegoImages = args.Skip(1).ToList();
password = PasswordPrompt.PromptPassword();
}
else
{
password = Encoding.UTF8.GetBytes(lastArg);
stegoImages = args.Skip(1).Take(args.Length - 2).ToList();
}
if (mode == "-d5") AdaptiveV5.DecryptV5(stegoImages, password);
else ShardedV4.DecryptSharded(stegoImages, password);
}
else if (mode == "-t5") AdaptiveV5.SelfTest();
else PrintHelp();
}
catch (Exception ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"\n[X] ОШИБКА: {ex.Message}");
Console.ResetColor();
}
finally
{
if (password != null) Array.Clear(password, 0, password.Length);
sw.Stop();
Console.WriteLine($"\nВремя выполнения: {sw.Elapsed.TotalSeconds:F2} сек.");
}
}
static void PrintHelp()
{
Console.WriteLine("Использование:");
Console.WriteLine(" Шифровать (V4): -c <файл> [пароль] <img1> [img2] ...");
Console.WriteLine(" Дешифровать (V4): -d <stego1> [stego2] ... [пароль]");
Console.WriteLine(" Шифровать (V5 адаптивный, против ML): -c5 <файл> [пароль] <img1> ...");
Console.WriteLine(" Дешифровать (V5): -d5 <stego1> ... [пароль]");
Console.WriteLine(" Self-test V5: -t5");
Console.WriteLine();
Console.WriteLine(" V4 — прячет размер payload (хорош против простых тулз).");
Console.WriteLine(" V5 — стойкость к ML-стегоанализу, НО ёмкость ниже и размер payload не скрывается.");
}
static void ValidateInputs(string inputFile, List<string> images)
{
if (!File.Exists(inputFile)) throw new Exception($"Файл не найден: {inputFile}");
if (images.Count == 0) throw new Exception("Не указаны картинки.");
foreach (var img in images)
{
if (!File.Exists(img)) throw new Exception($"Картинка не найдена: {img}");
try { var info = Image.Identify(img); if (info == null) throw new Exception(); }
catch { throw new Exception($"Файл поврежден или не картинка: {img}"); }
}
}
}
}