-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstego.pl
executable file
·93 lines (83 loc) · 2.13 KB
/
stego.pl
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
#!/usr/bin/perl
use GD;
unless ($ARGV[1]){
die "usage: stego.pl Cover.gif Message.txt {Key.txt}"
}
#foreach (0..$#ARGV) {print "$ARGV[$_]\n";}
$img = GD::Image->newFromGif($ARGV[0]) || die"can't open file";
#$stego = $img -> clone();
open(MESS , "$ARGV[1]") or die "can't open message";
while(<MESS>){
@mess = split(//,$_);
foreach $char(@mess){
$encode = sprintf( "%08b",ord($char));
$secret .= $encode;
}
#print $secret."\n";
}
close MESS;
@mess = split(//,$secret);
if (open (KEY , "$ARGV[2]") ){
$key = <KEY>;
close KEY;
}else{
$key = "1" x length($secret);
#print length($mess);
}
@key = split (//,$key);
#print $key;
#print $img->width()."x".$img->height()."\n" ;
my $total = $img->width()*$img->height()*3;
print "Q=".length($secret)/$total."\n";
foreach $intX (1 .. $img->width()){
foreach $intY (1 .. $img->height()){
$pixel = $img->getPixel($intX,$intY);
# print $intX.":".$intY.":".$pixel."\n" unless $intY <= 370 ;
($r,$g,$b) = $img->rgb($pixel);
#printf("%08d\t", $r);
if (defined($key = shift @key)){
if ($key){
my $mess = shift @mess;
my $lsb = $r % 2;
if ($lsb ^ $mess){
if ($lsb){$r--;}else{$r++;}
}
}
}
if (defined( $key = shift @key)){
if ($key){
$mess = shift @mess;
$lsb = $g % 2;
if ($lsb ^ $mess){
if ($lsb){$g--;}else{$g++}
}
}
}
if (defined ( $key = shift @key)){
if ($key){
$mess = shift @mess;
$lsb = $b % 2;
if ($lsb ^ $mess){
if ($lsb){$b--;}else{$b++}
}
}
}
#printf("\t%08d\n",$r);
#if ($r%2) {$r--};
#print $intX."-".$intY."--";
#printf("%08d\n",$r);
#if ($g%2) {$g--};
#if ($b%2) {$b--};
$pixel2 = $img -> colorResolve($r,$g,$b);
$img -> setPixel($intX,$intY,$pixel2);
# print $intX.".".$intY.":".$r."\t".$g."\t".$b."\n";
# $grey = ($r+$g+$b);
# $pixel2=$img->colorResolve($grey,$grey,$grey);
#warn "Everything's coming up roses.\n" if $pixel2 >= 0;
# $img->setPixel($intX,$intY,$pixel2);
}
}
open(OUT,"> output.gif") || die;
binmode OUT;
print OUT $img->gif();
close OUT;