-
Notifications
You must be signed in to change notification settings - Fork 0
/
LSB.cs
61 lines (58 loc) · 2.28 KB
/
LSB.cs
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
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Filtermap
{
class LSB
{
public static Bitmap HideImage(Bitmap bm_visible, Bitmap bm_hidden, int hidden_bits)
{
int shift = (8 - hidden_bits);
int visible_mask = 0xFF << hidden_bits;
int hidden_mask = 0xFF >> shift;
Bitmap bm_combined = new Bitmap(bm_visible.Width, bm_visible.Height);
for (int x = 0; x < bm_visible.Width; x++)
{
for (int y = 0; y < bm_visible.Height; y++)
{
try
{
Color clr_visible = bm_visible.GetPixel(x, y);
Color clr_hidden = bm_hidden.GetPixel(x, y);
int r = (clr_visible.R & visible_mask) + ((clr_hidden.R >> shift) & hidden_mask);
int g = (clr_visible.G & visible_mask) + ((clr_hidden.G >> shift) & hidden_mask);
int b = (clr_visible.B & visible_mask) + ((clr_hidden.B >> shift) & hidden_mask);
bm_combined.SetPixel(x, y, Color.FromArgb(255, r, g, b));
}
catch (Exception e)
{
e.ToString();
}
}
}
return bm_combined;
}
// Recover a hidden image.
public static Bitmap RecoverImage(Bitmap bm_combined, int hidden_bits)
{
int shift = (8 - hidden_bits);
int hidden_mask = 0xFF >> shift;
Bitmap bm_hidden = new Bitmap(bm_combined.Width, bm_combined.Height);
for (int x = 0; x < bm_combined.Width; x++)
{
for (int y = 0; y < bm_combined.Height; y++)
{
Color clr_combined = bm_combined.GetPixel(x, y);
int r = (clr_combined.R & hidden_mask) << shift;
int g = (clr_combined.G & hidden_mask) << shift;
int b = (clr_combined.B & hidden_mask) << shift;
bm_hidden.SetPixel(x, y, Color.FromArgb(255, r, g, b));
}
}
return bm_hidden;
}
}
}