| 1 | # | ||
| 2 | # Copyright (C) 1995, 1996 Systemics Ltd (http://www.systemics.com/) | ||
| 3 | # All rights reserved. | ||
| 4 | # | ||
| 5 | # Modifications are Copyright (c) 2000, W3Works, LLC | ||
| 6 | # All Rights Reserved. | ||
| 7 | |||
| 8 | package Crypt::DES; | ||
| 9 | |||
| 10 | require Exporter; | ||
| 11 | require DynaLoader; | ||
| 12 | use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); | ||
| 13 | |||
| 14 | @ISA = qw(Exporter DynaLoader); | ||
| 15 | |||
| 16 | # Items to export into callers namespace by default | ||
| 17 | @EXPORT = qw(); | ||
| 18 | |||
| 19 | # Other items we are prepared to export if requested | ||
| 20 | @EXPORT_OK = qw(); | ||
| 21 | |||
| 22 | $VERSION = '2.09'; | ||
| 23 | bootstrap Crypt::DES $VERSION; | ||
| 24 | |||
| 25 | use strict; | ||
| 26 | use Carp; | ||
| 27 | |||
| 28 | sub usage | ||
| 29 | { | ||
| 30 | my ($package, $filename, $line, $subr) = caller(1); | ||
| 31 | $Carp::CarpLevel = 2; | ||
| 32 | croak "Usage: $subr(@_)"; | ||
| 33 | } | ||
| 34 | |||
| 35 | |||
| 36 | sub blocksize { 8; } | ||
| 37 | sub keysize { 8; } | ||
| 38 | |||
| 39 | sub new | ||
| 40 | { | ||
| 41 | usage("new DES key") unless @_ == 2; | ||
| 42 | |||
| 43 | my $type = shift; | ||
| 44 | my $self = {}; | ||
| 45 | bless $self, $type; | ||
| 46 | |||
| 47 | $self->{'ks'} = Crypt::DES::expand_key(shift); | ||
| 48 | |||
| 49 | return $self; | ||
| 50 | } | ||
| 51 | |||
| 52 | sub encrypt | ||
| 53 | { | ||
| 54 | usage("encrypt data[8 bytes]") unless @_ == 2; | ||
| 55 | |||
| 56 | my ($self,$data) = @_; | ||
| 57 | return Crypt::DES::crypt($data, $data, $self->{'ks'}, 1); | ||
| 58 | } | ||
| 59 | |||
| 60 | sub decrypt | ||
| 61 | { | ||
| 62 | usage("decrypt data[8 bytes]") unless @_ == 2; | ||
| 63 | |||
| 64 | my ($self,$data) = @_; | ||
| 65 | return Crypt::DES::crypt($data, $data, $self->{'ks'}, 0); | ||
| 66 | } | ||
| 67 | |||
| 68 | 1; | ||
| 69 | |||
| 70 | __END__ |