#!/usr/bin/env perl

use strict;
use warnings;

use Net::RawIP;

# function to icmp packets out on wire
sub send()
{
    my $n = Net::RawIP->new({
        ip => { 
                saddr => '192.168.0.2',
                daddr => '192.168.0.1'
              },
        icmp => { 
                type => 8,
                data => $_[0]
              }
    });
    $n->send;
}


######
######
######
# main

# how much garbage
my $len = '4096';
# where to put key
my $half = $len / 2;

# make garbage
my $punct=`makepasswd --string='%$!@^&*()-=+[]\{}:<>?/.,~|\' --chars ${len}`;

# easily reversible md5sum (http://is.gd/cdXoQ)
my $md5='a7290d426b6a1764af6fd7fba5db214e';

# place key in garbage to prep to yenc
$punct =~ s/(.{$half})(.{$half})/$1$md5$2/;
$punct =~ s/(.{64})/$1\n/g;

# encode with yenc
my $enc = `echo -e '$punct\\c' | python -c 'import sys;import yenc;yenc.encode(sys.stdin,sys.stdout)'`;

# send icmp echo request packets with yenc encoded data
my @lines = split(/\n/,$enc);

my $data = ();
for (my $i = 0; $i <= $#lines; $i++)
{
    $data .= $lines[$i];
    if (0 == $i % 2)
    {
        &send($data);
        $data = ();
    }
}
