#!/usr/bin/perl -w # DC20 Quals 2012 - g300 getPIN-Script use IO::Socket; # create socket $sock = new IO::Socket::INET ( PeerAddr => '140.197.217.85', PeerPort => '10435', Type => SOCK_STREAM, Proto => 'tcp') or die "Could not create socket: $!\n"; sleep(1); # send password print $sock "5fd78efc6620f6\n"; $part = 1; # field counter @field = (); # temp field array while ($line = <$sock>) { chop($line); print "-$line-\n"; # get one field line and push numbers into if ((length($line)>5) && ($line =~ m/ (\d) .* (\d) .* (\d) .* (\d) .* (\d) .* (\d)/)) { push @field, $1, $2, $3, $4, $5, $6; } # field is full? then associate field number if ($#field == 35) { if ($part == 1) { @field1 = @field; } if ($part == 2) { @field2 = @field; } if ($part == 3) { @field3 = @field; } # all four fields fetched? then begin calculation of PIN if ($part == 4) { @field4 = @field; print "CALCULATE!!\n"; # iterate by PIN pos for ($pos = 0; $pos <= 3; $pos++) { # iterate each field position for ($i = 0; $i<=35; $i++) { # check if each PIN at this position matches if ($pin1[$pos] == $field1[$i]) { if ($pin2[$pos] == $field2[$i]) { if ($pin3[$pos] == $field3[$i]) { # position matches! got correct pin number push @pin4, $field4[$i]; } } } } } # array to scalar and print answer to STDIN and server socket $pin4 = join(" ", @pin4); print "PIN IS $pin4\n"; print $sock "$pin4\n"; # reset counter and answer to be prepared for next PIN calculation $part = 1; @pin4 = (); } @field = (); } # get and save entered PIN if ($line =~ m/User entered:/) { substr($line, 0, index($line, ": ")+2) = ""; if ($part == 1) { @pin1 = split(" ", $line); } if ($part == 2) { @pin2 = split(" ", $line); } if ($part == 3) { @pin3 = split(" ", $line); } $part++; } } close($sock);