This file is indexed.

/usr/share/perl5/Algorithm/CheckDigits/M97_002.pm is in libalgorithm-checkdigits-perl 0.50-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
package Algorithm::CheckDigits::M97_002;
# vim: set sw=4 ts=4 tw=78 et si:

use 5.006;
use strict;
use warnings;
use integer;

#use Math::BigInt;

our @ISA = qw(Algorithm::CheckDigits);

my %subst = (
    A => 10, B => 11, C => 12, D => 13, E => 14,
    F => 15, G => 16, H => 17, I => 18, J => 19,
    K => 20, L => 21, M => 22, N => 23, O => 24,
    P => 25, Q => 26, R => 27, S => 28, T => 29,
    U => 30, V => 31, W => 32, X => 33, Y => 34,
    Z => 35,
);

sub new {
    my $proto = shift;
    my $type  = shift;
    my $class = ref($proto) || $proto;
    my $self  = bless({}, $class);
    $self->{type} = lc($type);
    return $self;
} # new()

sub is_valid {
    my $self = shift;

    if (my ($checkdigit,$number) = _prepare_number(shift)) {

        return $checkdigit eq _compute_checkdigit($number);
    }
	return ''
} # is_valid()

sub complete {
    my $self = shift;
    my $incomplete = uc(shift);

    if (my ($checkdigit,$number) = _prepare_number($incomplete)) {

        $incomplete =~ /^(..)..(.+)/;

		return $1 . _compute_checkdigit($number) . $2;
    }
    return '';
} # complete()

sub basenumber {
    my $self = shift;
    my $unchecked = shift;

    if (my ($checkdigit,$number) = _prepare_number($unchecked)) {

        $unchecked =~ /^(..)..(.+)/;

		return $1.'00'.$2
            if ($checkdigit eq _compute_checkdigit($number));
    }
    return '';
} # basenumber()

sub checkdigit {
    my $self = shift;

    if (my ($checkdigit,$number) = _prepare_number(shift)) {
		return $checkdigit
            if ($checkdigit eq _compute_checkdigit($number));
    }
    return '';
} # checkdigit()

sub _compute_checkdigit {
    my $number = shift;

#    my $bignum = Math::BigInt->new($number);
#    my $mod    = $bignum % 97;
#
# A comparison with Benchmark::compthese() brought:
#
#             Rate   bignum 9_digits
# bignum    2502/s       --     -95%
# 9_digits 46225/s    1748%       --
#
# so I reverted _compute_checkdigit to this code.
# Thanks to Detlef Pilzecker for making me aware of this.

    my $mod = '';
    while ($number ne '') {
        $number = $mod . $number;
        $mod    = substr($number,0,9,'') % 97;
    }
    return sprintf("%02d",(98 - $mod));
} # _compute_checkdigit()

sub _prepare_number {
    my $number = uc(shift);

    $number        =~ s/\s//g;

    if ($number =~ /^([A-Z]{2})(\d\d)([A-Z\d]{2,30})$/) {
        my $checkdigit = $2;
        $number        = $3 . $1 . '00';
        $number        =~ s/([A-Z])/$subst{$1}/g;
        return ($checkdigit,$number);
    }
    return;
} # _prepare_number()

# Preloaded methods go here.

1;
__END__

=head1 NAME

CheckDigits::M97_002 - compute check digits for International Bank
Account Number (IBAN)

=head1 SYNOPSIS

  use Algorithm::CheckDigits;

  $iban = CheckDigits('iban');

  if ($iban->is_valid('DE88 2008 0000 09703 7570 0')) {
	# do something
  }

  $cn = $iban->complete('DE00 2008 0000 09703 7570 0');
  # $cn = 'DE88 2008 0000 09703 7570 0'

  $cd = $iban->checkdigit('DE88 2008 0000 09703 7570 0');
  # $cd = '88'

  $bn = $iban->basenumber('DE88 2008 0000 09703 7570 0');
  # $bn = 'DE00 2008 0000 09703 7570 0'
  
=head1 DESCRIPTION

=head2 ALGORITHM

=over 4

=item 0

The IBAN number must be prepared. The first two letters and the
checksum will be moved to the right end. The letters are substituted
according to the substitute table and the checksum is set to '00'.

=item 1

The whole number is taken modulo 97.

=item 2

The checksum is difference between 98 and the sum of step 2.

=item 3

If the checksum is smaller then 10, a leading zero will be
prepended.

=back

=head2 METHODS

=over 4

=item is_valid($number)

Returns true only if C<$number> consists solely of numbers and the last digit
is a valid check digit according to the algorithm given above.

Returns false otherwise,

=item complete($number)

The check digit for C<$number> is computed and concatenated to the end
of C<$number>.

Returns the complete number with check digit or '' if C<$number>
does not consist solely of digits and spaces.

=item basenumber($number)

Returns the basenumber of C<$number> if C<$number> has a valid check
digit.

Return '' otherwise.

=item checkdigit($number)

Returns the checkdigits of C<$number> if C<$number> has a valid check
digit.

Return '' otherwise.

=back

=head2 EXPORT

None by default.

=head1 AUTHOR

Mathias Weidner, E<lt>mathias@weidner.in-bad-schmiedeberg.deE<gt>

=head1 THANKS

Detlef Pilzecker pointed out to me that there may be more letters as the first
two in an IBAN number. He also made me aware of a faster method to compute the
check number than using Math::BigInt.

=head1 SEE ALSO

L<perl>,
L<CheckDigits>,
F<www.pruefziffernberechnung.de>,
F<www.sic.ch/en/tkicch_home/tkicch_standardization/
tkicch_financialinstitutions_ibanipi.htm>.

=cut