in reply to Temporarily Obscuring a Lottery Draw
Thank you all for your wonderful suggestions. I'm going to try following Perlbotics' suggestions regarding md5ing the pairs and storing that. If that doesn't work (either people complain that this info is on my machine or someone actually bothers to try to crack it), I'll follow BrowserUK's suggestion. The local third party approach mr_mischief suggests is clearly unacceptable, as everyone here is quite fond of presents. And of course, I'm tempted to try Fletch's solution just because. I mean, damn.
For those who are interested, I've included my final source. There's support for mr_mischief's third party by storing an email address in $authority. Of course, the e-mail credentials file is for a Santa-only account and is chmodded to 600.
#!/usr/bin/perl -w use strict; use List::Util qw(shuffle); use Digest::MD5 qw(md5_hex); use Net::SMTP::TLS; # Parameters my $authority = ''; my $value = 10; my $participantsFile = 'santaList.txt'; # Name#email\n my $previousFile = 'lastYear.txt'; # sorted md5 hashes\n my $serverInfoFile = 'emailCredentials.dat'; # Declare variables with file-wide scope my (%emails, @names, %matching, @previous, @content); # Initialize data open INPUT, '<' . $participantsFile; while (<INPUT>) { chomp; my ($name,$email) = split '#'; $emails{$name} = $email; } close INPUT; open INPUT, '<' . $previousFile; while (<INPUT>) { chomp; push @previous,$_; } close INPUT; # Generate the list @names = keys(%emails); # Collect the list of all participants GENERATE: while (1) { # Picking loop @matching{@names} = shuffle(@names); # Match 'em up # No one has themselves foreach (@names) { next GENERATE if $_ eq $matching{$_}; } # Generate digests for comparison my @digest = (); foreach (@names) { push @digest, md5_hex($_, '=>', $matching{$_}); } @digest = sort @digest; # Compare against previous year's results my $index = 0; foreach (@digest) { while ($index < @previous and $_ gt $previous[$index]) {$index +++} last if $index == @previous; next GENERATE if $_ eq $previous[$index]; } #Passes - store the digests for next year open OUTPUT, '>' . $previousFile; print OUTPUT join "\n", @digest; close OUTPUT; last GENERATE; # Passes } # E-mail the results { open INPUT, '<' . $serverInfoFile; my $host = <INPUT>; chomp $host; my $port = <INPUT>; chomp $port; my $user = <INPUT>; chomp $user; my $password = <INPUT>; chomp $password; close INPUT; my $server = Net::SMTP::TLS->new( $host, Port => $port, User => $user, Password=> $password, ) or die "Can't open mail connection: $!"; # Independent auditor if ($authority) { @content = (); $content[0] = "The picks for this year\'s gifting are as follo +ws\:"; foreach (@names) { push @content, "$_ is giving to $matching{$_}"; } send_mail($server, $authority, $user, 'Secret Santa Drawing', +@content); } foreach (@names) { @content = (); $content[0] = "Dear $_\,"; $content[1] = ""; $content[2] = "Thank you for participating in this year\'s Sec +ret"; $content[3] = "Santa gift exchange\. This year\, you will be +giving"; $content[4] = "a gift to $matching{$_}\. Please remember to l +imit the"; $content[5] = "monetary value of any gift you give to \$$value +\."; $content[6] = ""; $content[7] = "Happy Holidays\,"; $content[6] = "Robo-Santa 5000"; send_mail($server, $emails{$_}, $user, 'Secret Santa Drawing', + @content); } $server->quit; } sub send_mail { my($server, $to, $from, $subject, @body) = @_; $server->mail($from); $server->to($to); $server->data(); $server->datasend("To: $to\n"); $server->datasend("From: $from\n"); $server->datasend("Subject: $subject\n"); $server->datasend("\n"); foreach (@body) { $server->datasend("$_\n"); } $server->dataend(); }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Temporarily Obscuring a Lottery Draw
by ikegami (Patriarch) on Nov 02, 2008 at 22:16 UTC | |
by kennethk (Abbot) on Nov 03, 2008 at 16:34 UTC | |
by ikegami (Patriarch) on Nov 03, 2008 at 21:21 UTC |