| 1 | package Palm::Zetetic::Strip::CryptV05i; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use Digest::MD5 qw(md5); | ||
| 5 | use Crypt::IDEA; | ||
| 6 | |||
| 7 | use vars qw(@ISA $VERSION); | ||
| 8 | |||
| 9 | require Exporter; | ||
| 10 | |||
| 11 | @ISA = qw(Palm::Raw); | ||
| 12 | $VERSION = "1.02"; | ||
| 13 | |||
| 14 | sub new | ||
| 15 | { | ||
| 16 | my $class = shift; | ||
| 17 | my ($plaintext_key) = @_; | ||
| 18 | my $hashed_key; | ||
| 19 | my $self = {}; | ||
| 20 | |||
| 21 | bless $self, $class; | ||
| 22 | $hashed_key = $self->hash($plaintext_key); | ||
| 23 | |||
| 24 | $self->{hashed_key} = $hashed_key; | ||
| 25 | $self->{cipher} = new IDEA($hashed_key); | ||
| 26 | return $self; | ||
| 27 | } | ||
| 28 | |||
| 29 | sub get_hashed_key | ||
| 30 | { | ||
| 31 | my ($self) = @_; | ||
| 32 | return $self->{hashed_key}; | ||
| 33 | } | ||
| 34 | |||
| 35 | sub encrypt | ||
| 36 | { | ||
| 37 | my ($self, $plain_text) = @_; | ||
| 38 | my $block; | ||
| 39 | my $cipher_text; | ||
| 40 | my $cipher; | ||
| 41 | |||
| 42 | $cipher = $self->{cipher}; | ||
| 43 | $cipher_text = ""; | ||
| 44 | |||
| 45 | while(1) | ||
| 46 | { | ||
| 47 | $block = substr($plain_text, 0, 8, ""); | ||
| 48 | last if $block eq ""; | ||
| 49 | |||
| 50 | $cipher_text .= $cipher->encrypt($block); | ||
| 51 | } | ||
| 52 | |||
| 53 | return $cipher_text; | ||
| 54 | } | ||
| 55 | |||
| 56 | |||
| 57 | sub decrypt | ||
| 58 | { | ||
| 59 | my ($self, $cipher_text) = @_; | ||
| 60 | my $block; | ||
| 61 | my $plain_text; | ||
| 62 | my $cipher; | ||
| 63 | |||
| 64 | $cipher = $self->{cipher}; | ||
| 65 | $plain_text = ""; | ||
| 66 | |||
| 67 | while(1) | ||
| 68 | { | ||
| 69 | $block = substr($cipher_text, 0, 8, ""); | ||
| 70 | last if $block eq ""; | ||
| 71 | |||
| 72 | $plain_text .= $cipher->decrypt($block); | ||
| 73 | } | ||
| 74 | |||
| 75 | return $plain_text; | ||
| 76 | } | ||
| 77 | |||
| 78 | sub hash | ||
| 79 | { | ||
| 80 | my ($self, $string) = @_; | ||
| 81 | return md5($string); | ||
| 82 | } | ||
| 83 | |||
| 84 | |||
| 85 | 1; |