line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#-------------------------------------------------------------------------# |
2
|
|
|
|
|
|
|
# Crypt::OTP |
3
|
|
|
|
|
|
|
# Date Written: 07-Jul-2000 02:58:42 PM |
4
|
|
|
|
|
|
|
# Last Modified: 04-Sep-2002 01:29:36 PM |
5
|
|
|
|
|
|
|
# Author: Kurt Kincaid |
6
|
|
|
|
|
|
|
# Copyright (c) 2002, Kurt Kincaid |
7
|
|
|
|
|
|
|
# All Rights Reserved |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
# NOTICE: This is free software and may be modified and/or redistributed |
10
|
|
|
|
|
|
|
# under the same terms as Perl itself. |
11
|
|
|
|
|
|
|
#-------------------------------------------------------------------------# |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
package Crypt::OTP; |
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
608
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
36
|
|
16
|
1
|
|
|
1
|
|
4
|
use vars qw/ $VERSION @ISA @EXPORT @EXPORT_OK $pad_text $class $pad $mode $oo /; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
478
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
require Exporter; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
@ISA = qw/ Exporter /; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
$VERSION = '2.00'; |
23
|
|
|
|
|
|
|
@EXPORT = qw/ OTP /; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub new { |
26
|
0
|
|
|
0
|
0
|
|
( $class, $pad, $mode ) = @_; |
27
|
0
|
|
|
|
|
|
my $self = bless {}, $class; |
28
|
0
|
0
|
|
|
|
|
if ( $mode ) { |
29
|
0
|
|
|
|
|
|
$pad_text = $pad; |
30
|
|
|
|
|
|
|
} else { |
31
|
0
|
|
|
|
|
|
local $/ = undef; |
32
|
0
|
0
|
|
|
|
|
open( PAD, $pad ) || return $!; |
33
|
0
|
|
|
|
|
|
$pad_text = ; |
34
|
0
|
|
|
|
|
|
close( PAD ); |
35
|
|
|
|
|
|
|
} |
36
|
0
|
|
|
|
|
|
$oo = 1; |
37
|
0
|
|
|
|
|
|
return $self; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub OTP { |
41
|
0
|
0
|
|
0
|
0
|
|
shift if UNIVERSAL::isa( $_[ 0 ], __PACKAGE__ ); |
42
|
0
|
|
|
|
|
|
my ( $pad, $message ); |
43
|
0
|
0
|
|
|
|
|
if ( $oo ) { |
44
|
0
|
|
|
|
|
|
( $message, $mode ) = @_; |
45
|
|
|
|
|
|
|
} else { |
46
|
0
|
|
|
|
|
|
( $pad, $message, $mode ) = @_; |
47
|
|
|
|
|
|
|
} |
48
|
0
|
0
|
|
|
|
|
unless ( $oo ) { |
49
|
0
|
0
|
|
|
|
|
if ( $mode ) { |
50
|
0
|
|
|
|
|
|
$pad_text = $pad; |
51
|
|
|
|
|
|
|
} else { |
52
|
0
|
|
|
|
|
|
local $/ = undef; |
53
|
0
|
0
|
|
|
|
|
open( PAD, $pad ) || return $!; |
54
|
0
|
|
|
|
|
|
$pad_text = ; |
55
|
0
|
|
|
|
|
|
close( PAD ); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
while ( length( $pad_text ) < length( $message ) ) { |
60
|
0
|
|
|
|
|
|
$pad_text .= $pad_text; |
61
|
|
|
|
|
|
|
} |
62
|
0
|
|
|
|
|
|
my @message = split ( //, $message ); |
63
|
0
|
|
|
|
|
|
my @pad = split ( //, $pad_text ); |
64
|
0
|
|
|
|
|
|
my $cipher; |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
for ( my $i = 0 ; $i <= $#message ; $i++ ) { |
67
|
0
|
|
|
|
|
|
$cipher .= pack( 'C', unpack( 'C', $message[ $i ] ) ^ unpack( 'C', $pad[ $i ] ) ); |
68
|
|
|
|
|
|
|
} |
69
|
0
|
|
|
|
|
|
return $cipher; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
__END__ |