-
Notifications
You must be signed in to change notification settings - Fork 0
/
Steganography.txt
110 lines (92 loc) · 2.86 KB
/
Steganography.txt
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
function crop(image,width,height){
var croppedimg = new SimpleImage(width,height);
for(var pixel of image.values()){
var x = pixel.getX();
var y = pixel.getY();
if(x<width && y<height){
var np = croppedimg.getPixel(x,y);
np.setRed(pixel.getRed());
np.setGreen(pixel.getGreen());
np.setBlue(pixel.getBlue());
}
}
return croppedimg;
}
function clearbits(pixel){
pixel = Math.floor(pixel/16)*16;
return pixel;
}
function chop2hide(image){
for(var pixel of image.values()){
pixel.setRed(clearbits(pixel.getRed()));
pixel.setGreen(clearbits(pixel.getGreen()));
pixel.setBlue(clearbits(pixel.getBlue()));
}
return image;
}
function shift(image){
for(var pixel of image.values()){
pixel.setRed(pixel.getRed()/16);
pixel.setGreen(pixel.getGreen()/16);
pixel.setBlue(pixel.getBlue()/16);
}
return image;
}
function combineCheck(p,q){
var ans = p+q;
if(ans>255){
print("Error: Answer too big");
}
return ans;
}
function combine(start,hide){
var finalimg = new SimpleImage(start.getWidth(),start.getHeight());
for(var pixel of finalimg.values()){
var x = pixel.getX();
var y = pixel.getY();
var startpixel = start.getPixel(x,y);
var hidepixel = hide.getPixel(x,y);
pixel.setRed(combineCheck(startpixel.getRed(),hidepixel.getRed()));
pixel.setGreen(combineCheck(startpixel.getGreen(),hidepixel.getGreen()));
pixel.setBlue(combineCheck(startpixel.getBlue(),hidepixel.getBlue()));
}
return finalimg;
}
function decryption(value){
value = Math.floor(value%16)*16;
return value;
}
function extraction(image){
var result = new SimpleImage(image.getWidth(),image.getHeight());
for(var pixel of result.values()){
var x = pixel.getX();
var y = pixel.getY();
var imagepixel = image.getPixel(x,y);
pixel.setRed(decryption(imagepixel.getRed()));
pixel.setGreen(decryption(imagepixel.getGreen()));
pixel.setBlue(decryption(imagepixel.getBlue()));
}
return result;
}
var start = new SimpleImage("astrachan.jpg");
print("Original image:",start);
var hide = new SimpleImage("hilton.jpg");
print("Image to hide:",hide);
var cropWidth = start.getWidth();
if(hide.getWidth() < cropWidth){
cropWidth = hide.getWidth();
}
var cropHeight = start.getHeight();
if(hide.getHeight() < cropHeight){
cropHeight = hide.getHeight();
}
start = crop(start, cropWidth, cropHeight);
print("Cropped Original Image:",start);
hide = crop(hide, cropWidth, cropHeight);
print("Cropped Image to Hide:",hide);
start = chop2hide(start);
hide = shift(hide);
var msg = combine(start,hide);
print("Altered Orignal Image:",msg);
var decrypt = extraction(msg);
print("Extracted Image:",decrypt);