[10141] in Perl-Users-Digest
Perl-Users Digest, Issue: 3734 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 16 22:07:23 1998
Date: Wed, 16 Sep 98 19:00:17 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 16 Sep 1998 Volume: 8 Number: 3734
Today's topics:
Re: and? or? (logical operator question) (Larry Rosler)
any way to encrypt my script? (GEMINI)
Re: any way to encrypt my script? (Alastair)
Re: Can I foreach multiple arrays? <J.D.Gilbey@qmw.ac.uk>
Re: Comparing arrays ? (Larry Rosler)
Re: Comparing arrays ? <ajohnson@gpu.srv.ualberta.ca>
Re: Comparing arrays ? (Larry Rosler)
Re: how safe is xor encryption ? <fsg@newsguy.com>
Re: how safe is xor encryption ? <fsg@newsguy.com>
Re: how safe is xor encryption ? (Mark-Jason Dominus)
Re: how safe is xor encryption ? (Mark-Jason Dominus)
Re: how safe is xor encryption ? (Michael J Gebis)
Re: how safe is xor encryption ? <dejah@DejahsPrivateIce.com>
Re: how safe is xor encryption ? <dejah@DejahsPrivateIce.com>
Re: Is there any FAQ? <p-fein@uchicago.edu>
Re: MD5 or SHA as Perl functions? (Sean McAfee)
not to create console with Win32::GUI script? (GEMINI)
Re: Perl & Java - differences and uses <dalke@bioreason.com>
Re: Perl & Java - differences and uses <zenin@bawdycaste.org>
searching a file in ranges <ash@rem.hotmail.com>
shell-init: could not get current directory: getwd: can <jim@siteplus.com>
Re: trying to use print<<END; with CGI.pm (Alastair)
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 16 Sep 1998 17:01:20 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: and? or? (logical operator question)
Message-Id: <MPG.1069f12c11cff7409897a6@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and a copy mailed.]
In article <36001932.1329@DejahsPrivateIce.com> on Wed, 16 Sep 1998
15:01:56 -0500, Mary E Tyler <dejah@DejahsPrivateIce.com> says...
...
> open (SLOG, ">>$MyLog") and open (CLOG, ">>$MyComments") or die"etc";
>
> will this do what i think it will do... it will try to open the two
> files and if either one fails, it will die? or will it evaluate the
> first open and then say "i'm successful" and not evaluate the second
> open?
>
> i guess what i mean is does the "and" in perl work like the && in C
> where if the first operand is true then the second is evaluated, if it
> is false then the whole thing is false and it doesn't bother. at least,
> that is what i think i am asking.
>
> maybe what i really want to know is: will this work?
There are several ways to respond.
1. What happened when you tried it?
2. What does `perldoc perlop` say about these operators?
3. Yes, and 'better' than in C, for a couple of reasons:
a. There are operators with different priorities but the same behavior
(&& and 'and'; || and 'or') so you don't need as much parenthesizing.
b. Whereas in C the boolean operators return only a boolean value, in
Perl, they return the value of the last expression evaluated. Thus
(expr1 && expr2) returns FALSE if expr1 is FALSE, otherwise the value of
expr2; (expr1 || expr2) returns the value of expr1 if TRUE, otherwise the
value of expr2. This lets you do many neat things directly that would
require conditional expressions in C. For example,
$arg = shift || 'default';
4. Despite all that, you shouldn't write it that way, because if one of
the 'open's fails, you won't be sure which one, and $! (which you should
report in the 'die") will be unclear.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 17 Sep 1998 01:23:42 GMT
From: dennis@info4.csie.nctu.edu.tw (GEMINI)
Subject: any way to encrypt my script?
Message-Id: <6tpoau$iqa$1@netnews.csie.NCTU.edu.tw>
Using script has a lot of flexibility than compiled executable.
However, if I don't want to show my source code
to the world, what should I do with my script? Can
I encrypt my script so that it can be executed but not read?
thanks.
------------------------------
Date: Thu, 17 Sep 1998 01:26:45 GMT
From: alastair@calliope.demon.co.uk (Alastair)
Subject: Re: any way to encrypt my script?
Message-Id: <slrn700t1l.4k.alastair@calliope.demon.co.uk>
GEMINI <dennis@info4.csie.nctu.edu.tw> wrote:
>Using script has a lot of flexibility than compiled executable.
>However, if I don't want to show my source code
>to the world, what should I do with my script? Can
>I encrypt my script so that it can be executed but not read?
>thanks.
Do you really want to start a religious argument here? This has been
discussed very recently - do search at dejanews.
--
Alastair
work : alastair@psoft.co.uk
home : alastair@calliope.demon.co.uk
------------------------------
Date: Thu, 17 Sep 1998 01:05:50 +0100
From: Julian Gilbey <J.D.Gilbey@qmw.ac.uk>
Subject: Re: Can I foreach multiple arrays?
Message-Id: <3600525E.55CA04AF@qmw.ac.uk>
Abigail wrote:
>
> Colin Kuskie (ckuskie@cadence.com) wrote on MDCCCXLII September MCMXCIII
> in <URL: news:Pine.GSO.3.96.980916095515.20066A-100000@pdxue150.cadence.com>:
> ++ On 15 Sep 1998, Abigail wrote:
> ++
> ++ > Tom Christiansen (tchrist@mox.perl.com) wrote on MDCCCXLI September
> ++ > MCMXCIII in <URL: news:6tmlgd$hbp$2@csnews.cs.colorado.edu>:
Why 1841, 1842 and 1993?
Julian
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Julian Gilbey Email: J.D.Gilbey@qmw.ac.uk
Dept of Mathematical Sciences, Queen Mary & Westfield College,
Mile End Road, London E1 4NS, ENGLAND
-*- Finger jdg@goedel.maths.qmw.ac.uk for my PGP public key. -*-
------------------------------
Date: Wed, 16 Sep 1998 17:34:46 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Comparing arrays ?
Message-Id: <MPG.1069f906e1c198519897a7@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and a copy mailed.]
In article <36003a0f.14962015@news.demon.co.uk> on Wed, 16 Sep 1998
22:29:29 GMT, Phil Taylor <phil@ackltd.demon.co.uk> says...
> I've got an array which contains a series of codes ie
>
> @array1 = ("01", "02");
>
> and I have another array which contains the above codes with a decode
> separated by a colon ie
>
> @array2 = ("01:Element01", "02:Element02", "03:Element03", ........)
>
> I want to end up with @array2 to only contain elements relating to
> codes "01" and "02" ie
>
> @array2 = ("01:Element01", "02:Element02")
>
> Can anyone suggest a neat way to achieve this?
Your question is closely related to perlfaq4: "How can I tell whether an
array contains a certain element?"
Here's one way to do it (which is efficient for lots of data, but
overkill for your trivial example):
#!/usr/local/bin/perl -w
use strict;
my @array1 = qw( 01 02 );
my @array2 = qw( 01:Element01 02:Element02 03:Element03 );
my %array1;
@array1{ @array1 } = (1) x @array1;
my @array3 = grep { /^../; $array1{$1} } @array2;
print "@array3\n";
__END__
prints:
01:Element01 02:Element02
For a little fun, here's a neater IMO but more obfuscated way of doing
the grep:
my @array3 = grep $array1{"@{[/^../]}"} => @array2;
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 16 Sep 1998 19:40:19 -0500
From: Andrew Johnson <ajohnson@gpu.srv.ualberta.ca>
Subject: Re: Comparing arrays ?
Message-Id: <36005A73.757EE47C@gpu.srv.ualberta.ca>
Phil Taylor wrote:
>
> I've got an array which contains a series of codes ie
>
> @array1 = ("01", "02");
>
> and I have another array which contains the above codes with a decode
> separated by a colon ie
>
> @array2 = ("01:Element01", "02:Element02", "03:Element03", ........)
>
> I want to end up with @array2 to only contain elements relating to
> codes "01" and "02" ie
>
> @array2 = ("01:Element01", "02:Element02")
>
> Can anyone suggest a neat way to achieve this?
see perlfaq4:
perlfaq4.pod:=head2 How do I compute the difference of two arrays?
How do I compute the intersection of two arrays?
perlfaq4.pod:=head2 How can I extract just the unique elements of an
array?
here's one way:
my @array1 = ("01", "02");
my @array2 = ("01:Element01", "02:Element02", "03:Element03");
my %seen;
@seen{@array1}=(1) x @array1;
@array2 = grep{$seen{(split /:/)[0]}}@array2;
print "@array2\n";
regards
andrew
------------------------------
Date: Wed, 16 Sep 1998 17:53:07 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Comparing arrays ?
Message-Id: <MPG.1069fd4bc59582109897a9@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and a copy mailed.]
In article <36003a0f.14962015@news.demon.co.uk> on Wed, 16 Sep 1998
22:29:29 GMT, Phil Taylor <phil@ackltd.demon.co.uk> says...
> I've got an array which contains a series of codes ie
>
> @array1 = ("01", "02");
>
> and I have another array which contains the above codes with a decode
> separated by a colon ie
>
> @array2 = ("01:Element01", "02:Element02", "03:Element03", ........)
>
> I want to end up with @array2 to only contain elements relating to
> codes "01" and "02" ie
>
> @array2 = ("01:Element01", "02:Element02")
>
> Can anyone suggest a neat way to achieve this?
Your question is closely related to perlfaq4: "How can I tell whether an
array contains a certain element?"
Here's one way to do it (which is efficient for lots of data, but
overkill for your trivial example):
#!/usr/local/bin/perl -w
use strict;
my @array1 = qw( 01 02 );
my @array2 = qw( 01:Element01 02:Element02 03:Element03 );
my %array1;
@array1{ @array1 } = (1) x @array1;
my @array3 = grep $array1{substr $_, 0, 2} => @array2;
print "@array3\n";
__END__
prints:
01:Element01 02:Element02
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 16 Sep 1998 16:31:12 -0700
From: "Felix S. Gallo" <fsg@newsguy.com>
Subject: Re: how safe is xor encryption ?
Message-Id: <6tphj5$6ap@enews4.newsguy.com>
Abigail writes:
>Mark-Jason Dominus (mjd@op.net) writes:
>++ Yes, but it's not clear that you can trust the user to select a 53-bit
key.
>
>But what keeps you from selecting one for them?
Sociology and physics, normally. Which is to say, imagine if
your bank asked you to remember a 300 word text, or to recite
a 120 letter 'random string' over the telephone. People wouldn't
accept it, even if it were truly secure (and if they did, they'd likely
make errors and get mad). Until recently, it was also surprisingly
difficult to physically carry around 2 megabits.
Having thus achieved one boxtop for flagrant use of male
answer syndrome, I again go for the bonus round by suggesting
that this discussion be moved to sci.crypt after all the contestants
have thoroughly read the sci.crypt FAQs and Applied Cryptography
by Bruce Schneier. The important point that any reader will instantly
derive from holding this kind of discussion in sci.crypt is that there
are more innocent, naive and commonsensical ways to do something
absolutely stupid than there are in a room full of boobytrapped pinatas.
The person who is serious about the use of cryptography hires a
serious cryptography professional, lays out for expensive cryptographic
systems, or spends years of her life in menial toil pulling her hair out
over minutiae.
Felix
not a cryptography professional
------------------------------
Date: Wed, 16 Sep 1998 16:40:27 -0700
From: "Felix S. Gallo" <fsg@newsguy.com>
Subject: Re: how safe is xor encryption ?
Message-Id: <6tpi4n$6ig@enews4.newsguy.com>
beyret@my-dejanews.com writes:
>if the secret key is not an easy to remember key, than all these are
useless.
>that's why i did not want its length to be restricted with CC#+expiration.
if
>a shorter secret key is supplied, then the script will generate the other
>parts from the supplied one.
Length is not an important thing _at all_.
Entropy is the only important thing.
With Length _usually_ comes some amount of entropy, in practice; and
the maximum amount of available entropy does increase as length
increases; but the correlation is entropy-causes-length, not length-
causes-entropy.
>CC#: 123412341234 1234
>key: merhaba
>
>the perl script must be able to generate the remaining part of the key from
>the supplied one :"merhaba".
If it can do this, then the cracker can also generate the remaining part
of the key as part of her dictionary attack.
>actually, this would me more secure than having 16 digits of long phrase.
No, it depends on the entropy.
>because, users will give meaningfull phrases to make it easy to remmember.
>but that increases the vulnerability to a dictionary attack. but instead of
>16 characters, if user enters (or restricted to enter) say 10 characters
and
>remainig part is generated by an algorithm which will make dictionary
>attackers job difficult by generating meaningless combination of
characters,
>i think that would make it safer.
You are, in general, wrong -- 16 characters will, all else being equal, tend
to contain more entropy than 10 + any amount of algorithmic adding-on
(which, as it happens, totals to 10).
>in any case, if you were a cracker, would you attack to a system if you
knew
>that even if you could reach to the database, you still have to deal with
>each CC# uniquely. or would you go for other system where credit cards are
>available in chunks, either because they are stored as clear text or keys
are
>also stored in system or there is one key for all.
This argument is normally pretty good (when in a hunting group, it is not
important to be able to outrun a bear, but rather to be able to outrun the
slowest member of your group) -- but let's say someone does decide to
go after your database, and since it's weakly protected, gets it and starts
abusing the credit card numbers. Do you stand up in court and say,
"your honor, I'm completely vexed; there were easier targets than me"?
I'd rather not be in court at all.
>btw, i am not a professional programmer, thus my approach to the issue is
as
>good as my logic allows.
Nice try -- but the security world is littered with the heaped entrails of
a million nice tries.
Felix
mine own included
------------------------------
Date: 16 Sep 1998 20:58:06 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: how safe is xor encryption ?
Message-Id: <6tpmqu$84g$1@monet.op.net>
In article <6tpfbv$3an@mozo.cc.purdue.edu>,
Michael J Gebis <gebis@fee.ecn.purdue.edu> wrote:
>In response to M-J-D's challenge:
>
>#!/usr/bin/perl5 -w
>$cc="012345678";
I'm sorry I wasted your time by not making this clear earlier, but
you're not looking for the right thing here. You mustn't encode the
16-digit credit card number as 16 ascii digits, because that pads it
out to 128 bits, so that 75 of them are redundant. Of course it's
easy to brute-force when there's so much redundancy; you need 128-bit
keys, and the dictionary has only 14.
Instead, to properly encrypt a number, you should convert the 16-digit
credit card number to a 54-bit binary number, and pack it into 7 ascii
characters. The number 4071-2345-6789-3333, converted to binary, is
00001110,01110110,11000100,00101010,00110111,01110001,01010101. This
packs down to the string "\cNv\xc4*7qU". Xor this with a similarly
packed version of the secret key. The result, say "~\c^\xbbFV\c_-",
is your target that you stole from the database. If you xor this with
the correct key, you get the original credit card number back. If you
xor it with "Angstrom" instead, you get "?p\xDB) z_", which unpacks to
credit card number 17857010122914399. You can reject this one,
because it's too big, but in general you won't be so lucky.
>I sure hope this proves my point.
Again, I'm sorry I was unclear.
I invite you to discover my credit card number. I have selected a
random word from /usr/dict/words and xored it with the packed version
of the number. The result is "k\cN\242\324\352\303~".
------------------------------
Date: 16 Sep 1998 21:10:00 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: how safe is xor encryption ?
Message-Id: <6tpnh8$866$1@monet.op.net>
In article <6tpmqu$84g$1@monet.op.net>, Mark-Jason Dominus <mjd@op.net> wrote:
>I have selected a random word from /usr/dict/words
Sorry; I forgot to include: When the words were longer than seven
characters, I truncated them; when they were shorter, I padded them on
the end with digits 1234567, so that "foo" became "foo1234", etc.
Obviously the real application would do better than this, mingling
extra bits as appropriate, but I was being lazy.
------------------------------
Date: 17 Sep 1998 01:35:53 GMT
From: gebis@fee.ecn.purdue.edu (Michael J Gebis)
Subject: Re: how safe is xor encryption ?
Message-Id: <6tpp1p$72c@mozo.cc.purdue.edu>
mjd@op.net (Mark-Jason Dominus) writes:
}In article <6tpfbv$3an@mozo.cc.purdue.edu>,
}Michael J Gebis <gebis@fee.ecn.purdue.edu> wrote:
}>In response to M-J-D's challenge:
}>#!/usr/bin/perl5 -w
}>$cc="012345678";
}I'm sorry I wasted your time by not making this clear earlier, but
}you're not looking for the right thing here.
I feel I must point out that this _is_ the method described in the
original post of the thread. So I hope that I've at least proven THAT
method insecure. (I also think my program was pretty cool.)
}I invite you to discover my credit card number. I have selected a
}random word from /usr/dict/words and xored it with the packed version
}of the number. The result is "k\cN\242\324\352\303~".
This is a more interesting challenge, for certain. I'm not _yet_
convinced that it is secure. Providing the following
reference function would answer some questions I have about your
proposed method.
sub funkycrypt ($$) {
my($cc,$key)=@_;
#
# Do your stuff here
#
return $ciphertext;
}
Thanks.
--
Mike Gebis gebis@ecn.purdue.edu mgebis@eternal.net
------------------------------
Date: Wed, 16 Sep 1998 20:18:22 -0500
From: Mary E Tyler <dejah@DejahsPrivateIce.com>
Subject: Re: how safe is xor encryption ?
Message-Id: <3600635B.6CA8@DejahsPrivateIce.com>
Michael J Gebis wrote:
>
> Elaine -HappyFunBall- Ashton <eashton@bbnplanet.com> writes:
>
> }Ok. I stand corrected. I am still not absolutely certain that this is
> }100% secure, but certainly much more than I thought. I'll just go mug
> }the cute waiter instead for my CC fix. ;)
>
> }Interesting tidbit from www.cypher.net.
>
> }Why are One-Time Pads Perfectly Secure?
>
> }If the key is truly random, an xor-based one-time pad is perfectly
> ^^^^^^^^^^^^^^^^^^^^^^^^^^
>
> Nobody chooses "truly random" bitstrings for a key.
>
> (Well, maybe Data does, but no _humans_)
>
> --
> Mike Gebis gebis@ecn.purdue.edu mgebis@eternal.net
okay, so how random is random enough? if, as i suggested before, a
random key is generated using the password provided by the user... is
this random enough?
this is an actual question.
dejah
--
i trust i make myself obscure, i have need of obscurity now- robert bolt
a heated exchange of unread mail would be welcomed by all- christensen
Skating Fiction. Featuring the highly acclaimed serial On The Edge!
http://www.DejahsPrivateIce.com
------------------------------
Date: Wed, 16 Sep 1998 20:08:16 -0500
From: Mary E Tyler <dejah@DejahsPrivateIce.com>
Subject: Re: how safe is xor encryption ?
Message-Id: <360060FF.101E@DejahsPrivateIce.com>
Felix S. Gallo wrote:
>
> Mark-Jason writes:
> >[...]
> >If the customer-selected key phrases have at least 53 bits of entropy,
> >then a brute force search will fail utterly. A CC# is about 53 bits
> >long, so with a 53-bit key phrase you are doing one-time pad, and the
> >result of your brute-force search is nothing more than a list of every
> >possible credit card number.
>
> What M-J said is basically correct. But as a novitiate crank pedant,
> I earn valuable Usenet points towards my next advancement by
> pointing out that some of his language here tends towards the
> careless: there's a difference between a '53-bit key phrase' and
> a key phrase with 53 bits of entropy
snip
though this is not exactly PERL related, it has been mentioned here? how
does one apply for the Usenet points system... i can think of several
people on my other favorite news group who need to have applications for
the program sent to them... i'd love to be able to oblige...
dejah, is being pedantic a cross newsgroup phenomina?
#Obligatiory perl comment
for (;;) {print "You msut bring us a shrubbery!";}
--
i trust i make myself obscure, i have need of obscurity now- robert bolt
a heated exchange of unread mail would be welcomed by all- christensen
Skating Fiction. Featuring the highly acclaimed serial On The Edge!
http://www.DejahsPrivateIce.com
------------------------------
Date: Thu, 17 Sep 1998 00:42:19 GMT
From: Peter A Fein <p-fein@uchicago.edu>
Subject: Re: Is there any FAQ?
Message-Id: <opg3e9refis.fsf@harper.uchicago.edu>
"Hansi Hinterseer" <elchmann@hotmail.com> writes:
>
> Hi!
>
> I wondered if there is a FAQ about Perl or the NGs. Is there? Or any
> recommended tutorials?
Would this be a meta-FAQ? ;D
--
Peter A Fein Summering in SF!
Home: Work: 650-628-2172
p-fein@uchicago.edu pfein@us.checkpoint.com
Let the fucking elk do it. --Grey Claw
------------------------------
Date: Thu, 17 Sep 1998 01:07:57 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: Re: MD5 or SHA as Perl functions?
Message-Id: <NhZL1.3228$F7.12753959@news.itd.umich.edu>
In article <mike.elness-1609980815320001@stealthmac.lmms.lmco.com>,
Mike Elness <mike.elness@lmco.com> wrote:
>I need a message digest function (one-way hash) written in Perl that I can
>include in a Perl script. I know that others have developed Perl
>_extensions_ (i.e., Perl interface to C code) for the two most common
>ones, SHA and MD5, but I instead need one (or both ;-) of these written in
>real Perl code, ideally as a function that I can just pass some text to
>(and receive the message digest as the return value).
It just so happens that I've been testing the waters of cryptography
lately, and have coded such a thing.
>I know it'd be pretty slow in Perl due to the numerous computations
>required,
Boy, and how! Beyond that, I also sacrificed some speed for conciseness.
Use as follows:
----------------------------------------------------------------------
use SlowMD5;
$md = new SlowMD5("msg"); # equiv. to: $md = new SlowMD5; $md->add("msg");
$md->add("Input:", \*STDIN);
$md->add(... any combination of strings or glob references ...);
print $md->digest;
$binary_string = $md->digest(-binary);
$md->reset; # if needed
----------------------------------------------------------------------
It could still stand a little polishing, but here it is:
----------------------------------------------------------------------
package SlowMD5;
use integer;
sub new {
my $pkg = shift;
my $self = bless { }, $pkg;
$self->reset;
$self->add(@_) if @_;
$self;
}
sub reset {
my $self = shift;
$self->{accum} = "";
$self->{len} = 0;
$self->{state} = [ 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476 ];
}
sub add {
my $self = shift;
my ($i, $j, $n, $X, @tmpstate);
foreach my $data (@_) {
eval { use strict 'refs'; *{$data} };
unless ($@) {
local $/;
$data = <$data>;
}
$self->{accum} .= $data;
$self->{len} += length($data);
for ($n = 0; $self->{accum} =~ /(.{64})/gs; $n++) {
$X = [ unpack "V16", $1 ];
@tmpstate = @{$self->{state}};
for ($i = 0; $i < 4; $i++) {
for ($j = 0; $j < 16; $j++) {
$self->transform($X, $i, $j);
}
}
for (0..3) { $self->{state}[$_] += $tmpstate[$_] }
}
$self->{accum} = substr($self->{accum}, 64 * $n) if $n;
}
}
sub digest {
my $self = shift;
my $binary = shift eq "-binary";
my $tmpself = bless { accum => $self->{accum}, len => $self->{len},
state => [ @{$self->{state}} ] }, ref $self;
my $len = $tmpself->{len};
$tmpself->add("\x80", "\x00" x ((119 - $len % 64) % 64 || 64),
pack("V", $len * 8), "\x00" x 4);
my $result = join "", map { pack "V", $_ } @{$tmpself->{state}};
$binary ? $result : unpack("H*", $result);
}
my @T;
my @Q = ( 1, 2, 3, 0, 1, 2, 3 );
my @func = ( \&F, \&G, \&H, \&I );
sub transform {
my ($self, $X, $i, $j) = @_;
my ($k, $s, $t) = @{$round[$i][$j]};
my $n = $j % 4;
my $a = \$self->{state}[$Q[3-$n]];
my ($b, $c, $d) = @{$self->{state}}[@Q[4-$n..6-$n]];
$$a = $b + &rotbits($$a + &{$func[$i]}($b, $c, $d) + $X->[$k] + $T[$t], $s);
}
sub rotbits {
no integer; # need unsigned bit manipulation
my ($val, $bits) = @_;
$val << $bits | $val >> (32 - $bits);
}
sub F {
my ($X, $Y, $Z) = @_;
$X & $Y | ~$X & $Z;
}
sub G {
my ($X, $Y, $Z) = @_;
$X & $Z | $Y & ~$Z;
}
sub H {
my ($X, $Y, $Z) = @_;
$X ^ $Y ^ $Z;
}
sub I {
my ($X, $Y, $Z) = @_;
$Y ^ ($X | ~$Z);
}
@round = (
[
[ 0, 7, 1 ], [ 1, 12, 2 ], [ 2, 17, 3 ], [ 3, 22, 4 ],
[ 4, 7, 5 ], [ 5, 12, 6 ], [ 6, 17, 7 ], [ 7, 22, 8 ],
[ 8, 7, 9 ], [ 9, 12, 10 ], [ 10, 17, 11 ], [ 11, 22, 12 ],
[ 12, 7, 13 ], [ 13, 12, 14 ], [ 14, 17, 15 ], [ 15, 22, 16 ]
], [
[ 1, 5, 17 ], [ 6, 9, 18 ], [ 11, 14, 19 ], [ 0, 20, 20 ],
[ 5, 5, 21 ], [ 10, 9, 22 ], [ 15, 14, 23 ], [ 4, 20, 24 ],
[ 9, 5, 25 ], [ 14, 9, 26 ], [ 3, 14, 27 ], [ 8, 20, 28 ],
[ 13, 5, 29 ], [ 2, 9, 30 ], [ 7, 14, 31 ], [ 12, 20, 32 ]
], [
[ 5, 4, 33 ], [ 8, 11, 34 ], [ 11, 16, 35 ], [ 14, 23, 36 ],
[ 1, 4, 37 ], [ 4, 11, 38 ], [ 7, 16, 39 ], [ 10, 23, 40 ],
[ 13, 4, 41 ], [ 0, 11, 42 ], [ 3, 16, 43 ], [ 6, 23, 44 ],
[ 9, 4, 45 ], [ 12, 11, 46 ], [ 15, 16, 47 ], [ 2, 23, 48 ]
], [
[ 0, 6, 49 ], [ 7, 10, 50 ], [ 14, 15, 51 ], [ 5, 21, 52 ],
[ 12, 6, 53 ], [ 3, 10, 54 ], [ 10, 15, 55 ], [ 1, 21, 56 ],
[ 8, 6, 57 ], [ 15, 10, 58 ], [ 6, 15, 59 ], [ 13, 21, 60 ],
[ 4, 6, 61 ], [ 11, 10, 62 ], [ 2, 15, 63 ], [ 9, 21, 64 ]
]
);
for ($i = 1; $i <= 64; $i++) {
no integer;
$T[$i] = int(4294967296*abs(sin($i)));
}
1;
----------------------------------------------------------------------
--
Sean McAfee | GS d->-- s+++: a26 C++ US+++$ P+++ L++ E- W+ N++ |
| K w--- O? M V-- PS+ PE Y+ PGP?>++ t+() 5++ X+ R+ | mcafee@
| tv+ b++ DI++ D+ G e++>++++ h- r y+>++** | umich.edu
------------------------------
Date: 17 Sep 1998 01:30:19 GMT
From: dennis@info4.csie.nctu.edu.tw (GEMINI)
Subject: not to create console with Win32::GUI script?
Message-Id: <6tponb$iqa$2@netnews.csie.NCTU.edu.tw>
If I run my script that use Win32::GUI as the user interface.
But there would be a console created as well, though it is not
needed at all. So can I execute such a script as normal
window based application?
thanks.
------------------------------
Date: Wed, 16 Sep 1998 19:57:25 -0700
From: Andrew Dalke <dalke@bioreason.com>
Subject: Re: Perl & Java - differences and uses
Message-Id: <36007A95.7C1BA658@bioreason.com>
[My concerns about re's not being first class types in perl]
Uri Guttman <uri@fastengines.com> replied:
> the technique of building a regex sub on the fly and eval'ing it
> is very old and was the standard way to test multiple regexes with
> decent efficiency. it is not well know by newbies but most perl
> hackers had it in their idiom toolbox.
Ack, I'm showing my age :) Yes, I learned on perl4 (which is
when I got the trick) but switched over to python around 5.004_02,
and haven't read the docs since about 5.003. I hadn't seen anything
about the qr// construct, but
> Date: Sun, 12 Jul 1998 19:57:47 CDT
> Message-Id: <19980712195747.C493@pobox.com>
> Subject: [ PATCH perl5.004_72] patch to add qr//
it appears I'm only a few months behind :)
I'm glad its available. I've had to write a lot of files
that are "human formatted" and often end up using a dispatch
table to drive parser for each line. It is a lot easier and
maintainable to say:
@parse_table = (
[qr("range\s+(\d+)"), \&parse_range],
[qr(", \&parse_total_units],
[qr("^TOTAL.{40}SUBUNITS"), \&parse_total_subunits],
);
foreach $term (@parse_table) {
if (/$term->[0]/ =~ $str) { # if it matches the pattern
${$term->[1]}($str); # call the function
break;
}
}
than
if ( /range\s+(\d+)/ =~ $str ) {
&parse_range($str);
} elsif ( /^TOTAL.{40}UNITS"/) {
&parse_total_units($s);
} elsif ( /^TOTAL.{40}SUBUNITS"/) {
&parse_total_subunits($s);
}
(I cannot test this as we only have 5.004_04 installed, which doesn't
support qr.)
BTW, perhaps someone can answer me this question. I originally
wanted the above example to be the equivalent of (in Python):
m = term[0].match(str);
if m:
term[1](str, m)
that is, to pass the match information to the function handler.
In the above example I have "range\s+(\d+)" to parse "range 20"
and I don't want to have to reparse the string to get the 20.
In python I can have
def parse_range(str, match_obj):
print "The range is", match_obj.group(1)
but I can't figure out the right perl way. Best I can do is:
if (/$term->[0]/ =~ $str) { # if it matches the pattern
${$term->[1]}($str, $1, $2, $3, $4); # call the function
and assume I'll never pass more than 4 terms. This cannot
be right, which means there's probably some to get the list of
matches from the last re match. I don't know how and I don't
see that information in the perl documentation or FAQ.
Andrew
dalke@bioreason.com
------------------------------
Date: 17 Sep 98 01:48:42 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: Perl & Java - differences and uses
Message-Id: <905997200.798585@thrush.omix.com>
Andrew Dalke <dalke@bioreason.com> wrote:
: Not sure why I'm getting involved in a language war, but ...
:-)
: Zenin <zenin@bawdycaste.org> asked:
: > Please show *any* Python or Java code that when translated to Perl
: > would be done uncleanly by default. *Any* code.
:
: As I recall, regular expressions in Perl are not first class
: elements.
This has/had efficiency issues only, not code issues. In
any event, 5.005 has first class patterns so this issue is
mute.
: For example, you cannot make a list of regular expressions.
Sure you can, even in perl 4. They are only strings after
all.
my @list_o_patterns = qw(this that dog (?i)insensitive);
foreach my $pat (@list_o_patterns) {
something() if ($string =~ /$pat/);
}
: Eg (written on the fly so there are probably errors):
:
: import re
: patterns = []
: def add_pattern(pat, name):
: patterns.append( (re.compile(pat), name) )
:
: # returns number of matches found
: def search(str):
: count = 0
: for pat in patterns:
: m = pat[0].search(str)
: if m:
: # could put more info here, like start&end pos, match text
: print "Found", pat[1]
: count = count + 1
: return count
In a language that relies entirely on magic whitespace for block
roles, isn't a 2 space indent a really bad idea, readability and
maintainance wise?
Anyway, the Perl code has nearly the same algorithm:
@patterns = (); ## Global? Bad form. I'd pass by ref myself.
sub add_pattern ($$) {
my $pat = shift;
my $name = shift;
push @patterns, [ $pat, $name ];
}
sub search ($) {
my $str = shift;
my $count = 0;
foreach my $pat (@patterns) {
if ($str =~ /$pat->[0]/) {
print "Found $pat->[1]\n";
## Does Python really need the archaic "count = count + 1"?
$count++;
}
}
return $count;
}
: The closest I can think of in Perl is to construct some perl
: code and eval it dynamically, like:
>snip<
The only reasons you'd eval() code in the past was to get around
efficiency issues for some dynamic tasks. 5.005 makes this obsolete
as well. It was never needed to pass patterns around, even in perl 4.
: They are about the same size, but (IMHO, YMMV) the Perl code
: looks "unclean" becuase of the dynamic code construction,
Agreed. However the dynamic code construction wasn't
needed here, so this is a non-issue.
: and the requirement that "add_pattern" know the
: local variable names used in "search".
You say this, but you use a global pattern list in both
functions in both languages? Anyway, it isn't needed.
: As long as I'm here, there's what I consider to be the number one
: bug in Perl code that deals with files -- how do you read from the
: file " spaces " (with the leading and trailing space characters).
$ cat foo.pl
#!/usr/local/bin/perl
use Fcntl;
sysopen SESAME, " spaces ", undef, O_RDONLY
or die "open: $!";
print while <SESAME>;
$ cat > ' spaces '
this
is a
test
$ perl foo.pl
this
is a
test
open() is a short cut for 99% of common usage. It's just a map to
fopen(3) which is a wrapper over open(2), and was made for the
same reason. Sysopen() maps to open(2), and so easily handles any
other file access you need.
: According to the perl manual, you should do:
: $file =~ s#^\s#./$&#;
: open(FO, "< $file\0");
Hmm, now that is ugly. It even uses $&.... :-(
Which man page has this? -I'd like to submit a doc patch
if 5.005 hasn't fixed this already.
: which means some of the standard Perl libraries have bugs in
: them, like File/Compare.pm's "compare".
>snip<
: open(FROM,"<$from") or goto fail_open1;
Duh! I guess that's what happens when one gets too used
to working on real systems (insert OS flame war here). :-)
: It's a minor nit, but it means perl code you write that can take
: any filename as input must escape spaces as shown above, which to
: me is, if not unclean, then ungainly.
It would be to me too, if it was actually required.
: But remember, I'm not trying to say perl is bad or that you shouldn't
: use it. I'm only showing that there are at least two cases where
: an implementation in perl is not as "clean" (in my definition of
: clean) as the equivalent Python code.
The given "unclean" Perl algorithm wasn't needed and so invalidates
this example.
Next? ;-)
: (*Sigh*, why do I feel like I'll be flamed regardless of this
: comment?)
Because, this *is* USENET after all. :-)
--
-Zenin (zenin@archive.rhps.org) From The Blue Camel we learn:
BSD: A psychoactive drug, popular in the 80s, probably developed at UC
Berkeley or thereabouts. Similar in many ways to the prescription-only
medication called "System V", but infinitely more useful. (Or, at least,
more fun.) The full chemical name is "Berkeley Standard Distribution".
------------------------------
Date: Wed, 16 Sep 1998 20:39:44 -0400
From: Ash Heikh <ash@rem.hotmail.com>
Subject: searching a file in ranges
Message-Id: <36005A50.9B307E84@rem.hotmail.com>
i have a file of the format given at the end of this mail.
awk does a good job looking for and printing the row in which the 8th
column value is larger than, say, 10.
But I am interested in printing the date alongwith that line.
Can someone tell me a simple way to do that in perl or awk or sed. (not
c). i have little knowledge of perl.
date091498
sd6 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 0
sd28 0.0 0.0 0.0 0.3 0.0 0.0 17.2 0 0
sd29 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 0
ssd3 0.0 0.0 0.0 0.0 0.0 0.0 90.0 0 0
ssd7 0.0 0.0 0.0 0.0 0.0 0.0 80.0 0 0
date091598
ssd10 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 0
ssd11 0.0 0.0 0.0 0.0 0.0 0.0 20.0 0 0
ssd12 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 0
ssd13 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 0
------------------------------
Date: Wed, 16 Sep 1998 21:19:44 -0400
From: "Jim Weeks" <jim@siteplus.com>
Subject: shell-init: could not get current directory: getwd: cannot access parent directories
Message-Id: <6tpo3h$nj3$1@camel21.mindspring.com>
Any Ideas?
I keep finding this message in the error file after executing a script that
seems to be working fine. I can not find any errors other than this
message. I am opening several files in the course of the script and can not
seem to find the offending line. I admit that I am not all that
knowledgeable, and the reference to (getwd) doesn't mean any thing to me.
Any help would be appreciated!
Jim Weeks
jim@siteplus.com
------------------------------
Date: Thu, 17 Sep 1998 00:12:38 GMT
From: alastair@calliope.demon.co.uk (Alastair)
Subject: Re: trying to use print<<END; with CGI.pm
Message-Id: <slrn700omn.4k.alastair@calliope.demon.co.uk>
Al Smith <alanson@umich.edu> wrote:
>it's not working and i can't find any examples anywhere:
...snip
>Am i not looking hard enough?
Obviously Not.
--
Alastair
work : alastair@psoft.co.uk
home : alastair@calliope.demon.co.uk
------------------------------
Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>
Administrivia:
Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.
If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu.
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V8 Issue 3734
**************************************