Crypt::Mimetic::None - No Encryption


Crypt-Mimetic documentation Contained in the Crypt-Mimetic distribution.

Index


Code Index:

NAME

Top

Crypt::Mimetic::None - No Encryption

DESCRIPTION

Top

This module is a part of Crypt::Mimetic.

This modules does not encrypt anything: it only do a bitwise negation. DecryptFile needs @info containing generic-blocks-length and last-block-length (padlen). EncryptString and DecryptString return the bitwise negated string.

PROCEDURAL INTERFACE

Top

Return a short description of algorithm

Return true if password is needed by this algorithm, false otherwise. ('None' return always false)

Do a bitwise negation of $filename. See Crypt::Mimetic::EncryptFile.

Do a bitwise negation of $string. See Crypt::Mimetic::EncryptString.

Do a bitwise negation of $filename. See Crypt::Mimetic::DecryptFile.

Do a bitwise negation of $string. See Crypt::Mimetic::DecryptString.

NEEDED MODULES

Top

This module needs: Crypt::Mimetic Error::Mimetic

SEE ALSO

Top

Crypt::Mimetic

LICENSE

Top

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself (Artistic/GPL2).

AUTHOR

Top

Erich Roncarolo <erich-roncarolo@users.sourceforge.net>


Crypt-Mimetic documentation Contained in the Crypt-Mimetic distribution.
package Crypt::Mimetic::None;
use strict;
use Error::Mimetic;
use vars qw($VERSION);
$VERSION = '0.01';

sub ShortDescr {
	return "None - Special algorithm to not encrypt; very fast.";
}

sub PasswdNeeded {
	return 0;
}

sub EncryptFile {
	my ($filename,$output,$algorithm,$key,@info) = @_;
	my ($buf, $text, $txt) = ("","","");
	my ($len,$blocklen,$padlen) = (0,0,0);
	if ($output) {
		open(OUT,">>$output") or throw Error::Mimetic "Cannot open $output: $!";
	}
	open(IN,"$filename") or throw Error::Mimetic "Cannot open $filename: $!";
	while ( read(IN,$buf,32768) ) {
		$blocklen = $padlen;
		$text = ~$buf;
		$padlen = length($text);
		$len += $padlen;
		if ($output) {
			print OUT $text;
		} else {
			$txt .= $text;
		}
	}
	close(IN);
	if ($output) {
		close(OUT);
		return ($len,$blocklen,$padlen);
	}
	return ($len,$blocklen,$padlen,$txt);
}

sub EncryptString {
	my ($string,$algorithm,$key,@info) = @_;
	return ~$string;
}

sub DecryptFile {
	my ($filename,$output,$offset,$len,$algorithm,$key,@info) = @_;
	my ($blocklen,$padlen) = @info;
	my ($buf, $text, $i, $txt) = ("","",0,"");
	$blocklen = 32768 unless $blocklen;
	my $blocks = 0;
	$blocks = int($len/$blocklen) if $blocklen;
	if ($output) {
		open(OUT,">$output") or throw Error::Mimetic "Cannot open $output: $!";
	}
	open(IN,"$filename") or throw Error::Mimetic "Cannot open $filename: $!";
	seek IN, $offset, 0;
	for ($i = 0; $i < $blocks; $i++ ) {
		read(IN,$buf,$blocklen);
		$text = ~$buf;
		if ($output) {
			print OUT $text;
		} else {
			$txt .= $text;
		}
	}
	read(IN,$buf,$padlen);
	$text = ~$buf;
	if ($output) {
		print OUT $text;
	} else {
		$txt .= $text;
	}
	close(IN);
	if ($output) {
		close(OUT);
	} else {
		return $txt;
	}
}

sub DecryptString {
	my ($string,$algorithm,$key,@info) = @_;
	return ~$string;
}

1;
__END__