Coding Challenge #2! (115)

1 Name: Yaranaika Daddy!K./5Izeg0I 05/01/08(Sat)11:21 ID:Heaven This thread was merged from the former /code/ board. You can view the archive here.

Alright people who know how to tell there computer what to do and how to get there... I bring you a challenge from the interweb.

THE 4K CODE CHALLENGE

Objective: To create the most productive/useful code that as source code is no larger than 4 kilobytes (4096 bytes). There is no restrictions as to what your code does, or what language it is used in.

Rules:

  • The code must be yours, and you must be willing to give your code out to the public domain.
  • You must state EXACTLY what your code does. If it is malicious you must state what it does/exploit.
  • There is no restriction on what language, however markup languages are not allowed. Javascript/VBScript are, and any HTML required to perform the task is not counted towards the byte tally however objects calling to Javascript/VBScript do.
  • Common standard libraries (.h files, javabeans, perl modules etc) are allowed and dont count towards the byte tally.
  • You can use as many seperate files in your source code as you wish.
  • If you code requires to be compiled to run, it must be able to compile without a problem. For C and other languages that require a makefile, these will not go towards the byte tally.
  • Any other data in the form of databases, information etc that isn't a part of the code also does not count towards the byte tally.
  • If your program requires parameters to begin, you must state what they do.

Gentlemen, START YOUR TEXTEDITORS

89 Name: #!/usr/bin/anonymous : 2006-07-04 18:21 ID:pDZW8xx/

I've been learning Perl recently, and I made this small program to encrypt/decrypt text and files using one-time pads (more on one-time pads here, if there's interest: http://en.wikipedia.org/wiki/One-time_pad)

Don't expect this code to be very good, but I would love any constructive criticisim (or destructive, whatever)

#!/usr/bin/perl -w
use strict;

=pod
-g output-file num: generates keytext file of length num. makes file of length 1024
if num is omitted.

-e file-to-encrypt output-file a-keyfile : encrypts file-to-encrypt with a-keyfile. if
a-keyfile is omitted, script uses file 'keyfile'.

-d file-to-decrypt output-file a-keyfile : decrypts file-to-decrypt with a-keyfile. if
a-keyfile is omitted, script uses file 'keyfile'.
=cut

if (not @ARGV)
{
print "try supplying some arguments : )\nview the source for a guide.\n";
exit(0);
}

sub rand_char{
return chr(rand 255);
}

sub crypt($$$){
my($arg,$letter,$keyletter)=@_;
return
($arg eq "-e" )?chr(($letter+$keyletter)%255):
($arg eq "-d" )?chr(($letter-$keyletter)%255):
undef;
}
if($ARGV[0] eq '-ga' || $ARGV[0] eq '-g')
{
my $keytext='';
my $length=($ARGV[2])?$ARGV[2]:1024;
$keytext.=rand_char while $length--;
open KEYFILE, ">$ARGV[1]" or die "couldn't open $ARGV[1] for output: $!";
print KEYFILE $keytext;
}

90 Name: #!/usr/bin/anonymous : 2006-07-04 18:21 ID:pDZW8xx/

wow, I already fucked that up. here's the bottom half of the code

if($ARGV[0] eq '-e'||$ARGV[0] eq '-ea'||$ARGV[0] eq '-d'||$ARGV[0] eq '-da')
{
open INPUT, "<$ARGV[1]" or die "couldn't open $ARGV[1] for input: $!";
open OUTPUT, ">$ARGV[2]" or die "couldn't open $ARGV[2] for output: $!";
open KEY, ($ARGV[3])?"<$ARGV[3]":"<keyfile";
my @input=split //, join("\n", <INPUT>);
my @key=split //, <KEY>;
foreach (@input)
{
my $letter=ord($_);
my $keyletter=ord(shift @key);
print OUTPUT &crypt($ARGV[0],$letter,$keyletter);
}
close INPUT;
close OUTPUT;
close KEY;
}
Name: Link:
Leave these fields empty (spam trap):
More options...
Verification: