ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Digest-Hashcash/Hashcash.pm
(Generate patch)

Comparing Digest-Hashcash/Hashcash.pm (file contents):
Revision 1.1 by root, Sat Sep 6 22:12:00 2003 UTC vs.
Revision 1.2 by root, Sun Sep 7 00:58:23 2003 UTC

21=cut 21=cut
22 22
23package Digest::Hashcash; 23package Digest::Hashcash;
24 24
25use Time::Local; 25use Time::Local;
26use Time::HiRes;
26 27
27require XSLoader; 28require XSLoader;
28 29
29no warnings; 30no warnings;
30 31
31$VERSION = 0.01; 32$VERSION = 0.02;
32 33
33XSLoader::load Digest::Hashcash, $VERSION; 34XSLoader::load Digest::Hashcash, $VERSION;
34 35
36=item $secs = estimate_time $size
37
38Estimate the average time necessary to calculate a token of the given
39size.
40
41See also C<estimate_size>.
42
43=item $size = estimate_size $time[, $min]
44
45Estimate the size that can be calculated in the given time (which is an
46upper bound). The function will not return a size less then C<min>.
47
48Estimating the time to be used can go wrong by as much as 50% (but is
49usually quite accurate), and the estimation itself can take as much as a
50second on slower (<pentium) machines, but faster machines (1Ghz P3 for
51example) usually handle it within a hundredth of a second or so.
52
53The estimation will be done only once, so you can call this fucntion as
54often as you like without incuring the overhead everytime.
55
56=cut
57
58my $rounds;
59
60sub _rounds {
61 $rounds ||= &_estimate_rounds();
62}
63
64sub estimate_time {
65 my ($size) = @_;
66 2**$size / &_rounds;
67}
68
69sub estimate_size {
70 my ($time, $min) = @_;
71 $time = (log $time * $rounds) / log 2;
72 $time < $min ? $min : int $time;
73}
74
35=item $cipher = new [param => value...] 75=item $cipher = new [param => value...]
36 76
37=over 4 77=over 4
38 78
39=item size => 20 + some 79=item size => 18
40 80
41The number of collisions, in bits. Every bit increases the time to create 81The number of collisions, in bits. Every bit increases the time to create
42the token (and thus the cash) by two. 82the token (and thus the cash) by two.
43 83
44=item uid => "" 84=item uid => ""

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines