Acme-Stegano

 view release on metacpan or  search on metacpan

Stegano/Stegano.pm  view on Meta::CPAN

        my ($class,$filename) = @_;
        my @file;
        tie @file, 'Tie::File', $filename
                or croak "Cant tie filename $filename: $!";
        bless \@file, $class
}

sub insert
{
        my ($self,$text) = @_;
        my ($max_str,$max_cont,@map_letters) = (0,0);
        my $binstr = unpack "b*", " $text";             # It must begin with 0
        $_ > $max_str and $max_str = $_ for map { length } @$self;
        while ($binstr =~ /((.)\2*)/g)
        {
                my $len = length($1);
                $max_cont = $len if $len > $max_cont;
                push(@map_letters,$len);
        }

        my @map_file = map { $max_str - length($_) > $max_cont } @$self;

        for (my $i=0;$i<@$self;$i++)
        {
                $self->[$i] .= " " x shift(@map_letters)
                        if $map_file[$i] and @map_letters;
        }
        carp "Text is not enougth large to insert all chars" if @map_letters;
        return ! @map_letters;
}

sub extract
{
        my $self = shift;
        my ($binstr,$i);
        for my $line (@$self)
        {
                $binstr .= ++$i % 2 ? 0 x length($1) : 1 x length($1)
                        if $line =~ s/( +)$//



( run in 2.494 seconds using v1.01-cache-2.11-cpan-49f99fa48dc )