Advertisement
musifter

AoC day 25, Perl

Dec 25th, 2020
1,936
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.71 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. use List::AllUtils qw(none first);
  7.  
  8. $| = 1;
  9.  
  10. my $SUBJECT_NUM = 7;
  11. my $MOD = 20201227;
  12.  
  13. chomp( my @keys = <> );
  14.  
  15. print "Public Keys: ", join( ',', @keys ), "\n";
  16.  
  17. my $loop = 0;
  18. my $val = $SUBJECT_NUM;
  19. while (none { $val  == $_ } @keys) {
  20.     $val = ($val * $SUBJECT_NUM) % $MOD;
  21.     $loop++;
  22.     print "Looping... $loop\r"  if ($loop % 100000 == 0);
  23. }
  24.  
  25. print "Loop size: $loop (public key $val) \n";
  26.  
  27. my $other = first { $_ != $val } @keys;
  28. print "Other public key: $other\n";
  29.  
  30. my $val2 = $other;
  31. while ($loop--) {
  32.     $val2 = ($val2 * $other) % $MOD;
  33.     print "$loop\t$val2  \r"    if ($loop % 100000 == 0);
  34. }
  35.  
  36. print "Encryption key: $val2 \n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement