Dan LeCocq

Autokey

On the recommendation of my friend Dan, I’m going to try to do some of these programming puzzles from time to time. I’m also going to try work these problems using Perl. Today’s assignment is to make a simple Autokey Cipher, which I accomplished over my lunch break.

use List::Util qw/sum/;

if ($#ARGV != 1 ) {
	print "usage: autokey.pl plainText key\n";
	exit;
}

$plainText = uc $ARGV[0];
$keyBase = uc $ARGV[1];

$key = $keyBase.$plainText;

print $key;

#$plainText	= "ACOLLECTIONOFETUDES";
#$key		= "PRAXISACOLLECTIONOF";
$cipherText	= "";

sub encipher{
	my($thisPlainText, $thisKey) = @_;

	#Clear Cipher'd text
	$thisCipherText = "";

	#Clear i
	$i=0;

	@arrayPlainText = split //, $thisPlainText;
	@arrayKey = split //, $thisKey;

	for($i = 0;  $i < scalar @arrayPlainText; $i++){
		if(@h{@arrayPlainText[$i]} + @h{@arrayKey[$i]} > 27){
			$thisCipherText .= @k[@h{@arrayPlainText[$i]} + @h{@arrayKey[$i]} - 27];
			#print @h{@arrayPlainText[$i]} + @h{@arrayKey[$i]} - 26 . "\n";
			#print @k[@h{@arrayPlainText[$i]} + @h{@arrayKey[$i]} - 26] . "\n";
		}
		else{
			$thisCipherText .= @k[@h{@arrayPlainText[$i]} + @h{@arrayKey[$i]} - 1];
			#print @h{@arrayPlainText[$i]} + @h{@arrayKey[$i]} . "\n";
			#print @k[@h{@arrayPlainText[$i]} + @h{@arrayKey[$i]}] . "\n";
		}

	}

	return $thisCipherText;

}

sub decipher{
	my($thisCipherText, $thisKey) = @_;

	@arrayCipherText = split //, $thisCipherText;
	@arrayKey = split //, $thisKey;

	for($i = 0;  $i < scalar @arrayCipherText; $i++){
		if(@h{@arrayCipherText[$i]} - @h{@arrayKey[$i]} < 0){
			$thisPlainText .= @k[@h{@arrayCipherText[$i]} - @h{@arrayKey[$i]} + 27];
		}
		else{
			$thisPlainText .= @k[@h{@arrayCipherText[$i]} - @h{@arrayKey[$i]} + 1];
		}
	}
	return $thisPlainText;
}

@h{'A' .. 'Z'} = (1 .. 26);
@k[1 .. 26] = ('A' .. 'Z');

$cipherText = &encipher($plainText, $key);

$decipherText = &decipher($cipherText, $key);

print " Plain text is: " . $plainText . "\n";
print "Cipher text is: " . $cipherText . "\n";
print "Decipher text is: " . $decipherText . "\n";

0

Everyone I know is Studying Abroad!

Not everyone. But a lot.

Jeff Staples is in El Salvador. Charlie Wyman is in Ecuador. Amelie Mabbutt and Hannah Bellinger are in Spain (although not with the same group…as far as I know). Julia Masnik and David Clausen are in London (together). Jessen Myburgh is in Greece. Alison White is in New Zealand. Katherine Staples is at St. Andrew’s in Scotland. Katie Shaiman is in Edinburgh, Scotland. Matthew Knowles was in France. Amy Dubetz is in Budapest. Amy Beck is in Buenos Aires. Lindsay Hansberry is in Europe.

There could be others, but I’m done looking through Facebook, for now, trying to figure out where everyone is. The point still stands though: A crap ton of people I know are not in the United States (or Canada or Mexico) right now.

Update:
Mesa Schumacher is in Peru. Kelly Nolan is Florence.

Next school year, Brittany Linton is going to Japan and Devan O is going to London.

Update II:
Lauren Rubinfeld is in Sydney, Australia.

Update III:
Dan Lecocq is in Japan!

0

Start Spreadin’ the News; I’m Leaving Today; I Want to be a Part of It: Morgan Hall, Morgan Hall…

  • Mines

So some good news! I put a request in at the end of last semester to be transfered to the Traditionals (which are a lot closer to everything school related then RH@MP are) and it went through! I’m now in Morgan Hall with Dan LeCocq (that would be lay-coke, not something else) who I met here at Mines last semester. He’s a pretty cool dude. Anyways, you can send all your mail to my new address:

Andrew Ferguson
Morgan Hall, 226
Golden, CO
80401

0