Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
#!/usr/bin/perl -w # # Anarion # 02-09-2001 # # FileTransfer encryptet with Blowfish :) # You need the Blowfish module from www.cpan.org # # use IO::Socket; use Crypt::Blowfish; use Getopt::Std; use strict; my %opcions; getopts('hd:lp:o:kK:',\%opcions) or ajuda(); ajuda() if $opcions{h} || (! $opcions{d} and ! $opcions{l}) || ! $opci +ons{p}; my $key = exists $opcions{k} && $opcions{k}==1 && llegeix_clau() || ex +ists $opcions{K} && length($opcions{K}) == 8 && $opcions{K} || ''; print $key ? "Using your key\n" : "No valid key introduced, skip encr +iption\n"; server() if $opcions{l}; client() if $opcions{d}; ###### # sub ajuda { die <<AJUDA; Version [1.1] by Anarion Connect to somewhere: $0 -d host -p port [-options] Inbound connects: $0 -l -p port [-options] Options: -o output Redirect the output -k Read the key from STDIN -K key use this key [8 chars] AJUDA } ###### # sub llegeix_clau { local $| = 1; local *TTY; my ($clau1,$clau2); open(TTY,"/dev/tty"); system "stty -echo </dev/tty"; print STDERR "the key must be 8 chars long\nType the key: "; chomp($clau1 = <TTY>); print STDERR "\nRe-type key: "; chomp($clau2 = <TTY>); print "\n\r"; print "Keys dont match\n" and return unless $clau1 eq $clau2; print "The password must be 8 chars long\n" and return if length($ +clau1) != 8; return $clau1; } ###### # sub server { my $socket = IO::Socket::INET->new(LocalPort => $opcions{p}, Listen => 2, Reuse => 1, Type => SOCK_STREAM, Proto => 'tcp', ) or die "Cant bind socket $opcions{p}: $!"; my ($client,$resposta); while ($client = $socket->accept()) { print "Conection from: ",$client->peerhost(),"\nAccept it? [y/ +n]"; chop($resposta = <STDIN>); last if $resposta eq 'y'; close($client); } print "\n"; open(FITXER,">$opcions{o}") || die "Sucks cant create $opcions{o}\ +n" if $opcions{o}; my $sortida = *FITXER; $sortida = *STDOUT unless $opcions{o}; my $blow = new Crypt::Blowfish $key if $key; while(<$client>) { chomp($_); $_ = pack("H*",$_); if ($key) { my @blocks = unpack("a8" x (int(length($_) / 8)+(length($_ +)%8!=0)),$_); my $text; foreach my $block (@blocks) { last unless $block; $text .= $blow->decrypt($block); } $text=~s/ *$//; print $sortida "$text\n"; next; } print $sortida "$_\n"; } exit; } ## # sub client { my $socket = IO::Socket::INET->new(PeerPort => $opcions{p}, PeerAddr => $opcions{d}, Type => SOCK_STREAM, Proto => 'tcp', ) or die "Cant connect to $opcions{d} $opcions{ +p}: $!"; my $blow = new Crypt::Blowfish $key if $key; while(1) { last unless $socket; chomp($_ = <STDIN>); last unless $_; if ($key) { my @blocks = unpack("a8" x (int(length($_) / 8)+(length($_ +)%8!=0)),$_); my $text; foreach my $block (@blocks) { $block .= " " x (8 - length($block)) if length($block) + != 8; $text .= $blow->encrypt($block); } $text= unpack("H*",$text); print $socket "$text\n"; next; } $_ = unpack("H*",$_); print $socket "$_\n"; } close($socket); exit; }

In reply to Netcat like with Blowfish by Anarion

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others drinking their drinks and smoking their pipes about the Monastery: (12)
    As of 2014-08-22 19:57 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The best computer themed movie is:











      Results (163 votes), past polls