Wednesday, September 10, 2008

Conjugal

Cory Doctorow has a wedding ring designed by Bruce Schneier. It's a secret encoder ring, naturally. Now they're looking for an encryption algorithm that can use the ring. I hit a slow patch at work, waiting for some documents to arrive (which means it's going to be all the worse when they actually do arrive), so I spent a few minutes on one. I'm going to post the short version of the algorithm at boingboing, but here's the long version, implemented in Perl. (I deliberately avoided using Perl tricks to keep it clear.)

Update 9/10/08: you get better results if you calculate the advance a bit differently. Start with 1. If ring 2 has a dot above, add 2; if it has a dot below, add 1. If ring 3 has a dot above, add 6; if it has a dot below, add 3. I'm still experimenting with the advance, though.


#!/usr/bin/perl -w

# Calculates how many positions to advance a ring to get to the desired letter
sub calcAdvance {
my ($pos, $newPos) = @_;
my $advance = $newPos - $pos;
if ($advance < 0) {
$advance = $advance + 26;
}
return $advance;
}

# Ring1 is inner-most, Ring3 is outer-most.
#
# A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
my @ring2Dots = (9,9,0,0,3,3,9,9,0,0,3,3,9,9,0,0,3,3,9,9,0,0,3,3,9,9);
my @ring3Dots = (2,2,2,0,0,0,1,1,1,2,2,2,0,0,0,1,1,1,2,2,2,0,0,0,1,1);

#
# The Conjugal Encryption Algorithm.
#
# Initialization using the crypto key.
#
# Start by aligning all the "A"'s.
my $ring2Pos = 0;
my $ring3Pos = 0;

# Then initialize the ring.
my $key = "congratulations";
while ($key ne "") {

# 1. Get the next character of the key
my $keyChar = substr ($key, 0, 1);
$key = substr ($key, 1);

# 2. Rotate rings 2 and 3 together so the A on
# Ring 1 aligns with the key character on
# Ring 3.
my $advance = calcAdvance ($ring3Pos,
ord (lc ($keyChar)) - ord ("a"));
$ring2Pos = ($ring2Pos + $advance) % 26;
$ring3Pos = ($ring3Pos + $advance) % 26;

# 3. Calculate an advancement amount.
# a. Start with 1.
# b. Look at the Ring 2 letter next to the A of Ring 1.
# If there's a dot above, add 9. If there's a dot
# below, add 3.
# c. Look at the Ring 3 letter next to the A of Ring 1.
# If there's a dot above, add 2. If there's a dot
# below, add 1.
$advance = 1 + $ring2Dots[$ring2Pos] + $ring3Dots[$ring3Pos];

# 4. Advance Ring 3 that many letters.
$ring3Pos = ($ring3Pos + $advance) % 26;
}


# Generate some useful output
my $plaintext = "Wishing you a happy life together!";
print $plaintext, "\n";

# Skip whitespace and punctuation when encrypting.
$plaintext = lc($plaintext);
$plaintext =~ tr/a-z//cd;
print uc($plaintext), "\n";

#
# Encrypt text. Initialization vector omitted for clarity.
#
my $cyphertext = "";
while ($plaintext ne "") {

# 1. Look at the letter on Ring 3 adjacent to the A on Ring 1.
# Rotate Rings 2 and 3 together so that same letter on
# Ring 2 is adjacent to the A on Ring 1 (and some different
# letter on Ring 3 will now be adjacent.)
my $advance = calcAdvance ($ring2Pos, $ring3Pos);
$ring2Pos = ($ring2Pos + $advance) % 26;
$ring3Pos = ($ring3Pos + $advance) % 26;

# 2. Calculate an advancement amount.
# a. Start with 1.
# b. Look at the Ring 2 letter next to the A of Ring 1.
# If there's a dot above, add 9. If there's a dot
# below, add 3.
# c. Look at the Ring 3 letter next to the A of Ring 1.
# If there's a dot above, add 2. If there's a dot
# below, add 1.
$advance = 1 + $ring2Dots[$ring2Pos] + $ring3Dots[$ring3Pos];

# 3. Advance Ring 3 that many letters.
$ring3Pos = ($ring3Pos + $advance) % 26;

# 4. Get the next character of the plaintext.
my $plainChar = substr ($plaintext, 0, 1);
$plaintext = substr ($plaintext, 1);

# 5. To encrypt this letter of plaintext, find the
# plaintext on Ring 1 and write down the matching
# cyphertext on Ring 3. (To decrypt, look at
# the cyphertext on Ring 3 and write down the matching
# plaintext on Ring 1.)
my $ring3CryptoPos
= (ord ($plainChar) - ord ("a") + $ring3Pos) % 26;
$cyphertext = $cyphertext . chr ($ring3CryptoPos + ord ("A"));
}

# Print the cyphertext.
print $cyphertext, "\n";

Thursday, August 14, 2008

more on inverting the pattern

I've been thinking a bit more about inverting the pattern, moving from a blog-like pattern of lots of talking and not much listening to something with more listening and less talk, or at least more meaningful listening.

Broadcast media is not the answer. A radio or TV station is basically the same thing as a blog, still a monologue where the speaker is hoping listeners will tune in. There might be more listening, but only because there are fewer speakers.

If you look at the pattern of a typical conversation, it's a group of people with only one person talking at a time. It happens that way because if two people try to talk at once, they interfere with each other. And it's usually considered bad form for one person to monopolize the conversation. With blogs, though, there's really no limit to the number of people who can talk at once, so there's a lot more talking. But with all the talk, who has time to listen and evaluate?

So what would it mean to bring a conversation-like pattern into the Internet? One example might be Internet Relay Chat: when one person types, everyone on the channel sees it. Another example, which I like even better because it moves a little more slowly, allowing the opportunity for greater depth, is a computer bulletin board. The modern version would be a web forum. Unlike blogs, where the blog's author holds most of the conversational power, the participants in bulletin board systems or forums [1] all have roughly equal power, so there's more room for the give-and-take that makes for conversation.

[1] Apologies to the classics purists, but I just can't bring myself to write "fora".

Tuesday, August 12, 2008

inverting the pattern

Blogs are all about talking, but they're rarely about conversing. They're more like monologues within earshot of one-another, and sometimes another person will tune in and change their own monologue in response. Twitter's basically the same thing, which isn't too surprising since it's really a form of blogging.

I wonder, though, if there's a way to invert the pattern. Instead of everyone talking and hoping someone listens, is there a way you could reverse it so there's much more listening going on than talking? What would such a thing look like? And would people use it?

Tuesday, July 22, 2008

Al Gore's speech

This post was originally going to be an analysis of Al Gore's energy challenge speech and some of the criticism of it.

If you view the speech as a logical or rhetorical argument, it has its share of problems. For example, when talking about the falling price of silicon for solar cells, Gore says, "the same thing happened with computer chips--also made out of silicon. The price paid for the same performance came down by 50 percent every 18 months--year after year, and that's what's happened for 40 years in a row." This conclusion doesn't follow: the price per unit of performance for computer chip drops because transistors keep getting smaller, but making the features on a solar cell smaller will quickly run out of steam because you're fundamentally limited by the amount of sunlight per unit area. Even if you increase efficiency by 50% every 18 months, and in a few years you get darn close to 100%, you still hit the limit imposed by the sun. That's not to say that solar cells won't get cheaper, but microchips' cost per unit performance is not the right model. Also, Gore has the annoying habit of not citing his sources, even in the transcript, which makes the speech very hard to fact-check.

The criticism is worse. It opens by saying "Al Gore wants you to do as he says, not as he does" and spends fully a third of its length calling Gore a hypocrite. But that doesn't follow either: the validity of Gore's contention that we need this energy challenge, and the underlying reasoning he presents, have nothing to do with his personal energy consumption habits. It could just as easily come from, for example, T. Boone Pickens. The next third of the criticism is devoted to an argument that says, essentially, it's impossible because we're not doing it now: renewables are a tiny percentage of our current energy production, therefore it is unreasonable to expect that they could reach 100% in ten years. But at its core, this argument is a simple assertion that change is impossible, which we know by experience to be false. Finally, two thirds of the way down, the criticism brings up a scientific paper that denies human impact on global temperature change, which is at least fodder for debate. (More background on that paper here and here.)

But you know, my heart just isn't in the analysis. Deep down, the reason is that I missed the last Apollo project and want one I can be a part of. And this is a cause I can get behind. It's big, it's inspiring, it'll create some fantastic spinoff technologies, and it'll produce great results. Even on the (exceptionally remote) chance that the IPCC is wrong and the paper the criticsm cites is right, that anthropogenic global temperature change is an illusion, it's extremely hard to deny that much of U.S. foreign policy is driven by a dependence on foreign oil, that even if we tap all our domestic sources they won't meet our demand, and that shifting to domestically produced renewables would give us a ton of new flexibility in foreign policy. So, yeah, I hope this thing takes off. And if it does, I want in.

Sunday, July 13, 2008

redundancy and unexpected interdependency

A couple weeks ago, the office network went down. Not surprisingly, we couldn't print or get to any electronically filed documents. Maybe a bit more surprisingly, the phones also went out because we've moved to fancy new Cisco network-based phones, and they took voice mail--which is now e-mail-based--with them. And so did the fax machines, because when faxes come in they get scanned and e-mailed to us. The net result was that we were almost dead in the water. Fortunately, the Blackberries stayed up, so we could use cell phones and could still send e-mail through the Blackberry server.

These sorts of unexpected interdependencies are cropping up more and more often as we begin to link one network to another, and as traditional network technologies shift around. I've already written about how my (now former) cell phone's alarm clock stopped working when the phone couldn't reach the cell network. There was a radio discussion today about an issue with digital TV: many people put battery-powered analog TV sets in survival kits so they can get news if there's a natural disaster, but (1) the set-top converter boxes that we'll need to use once HDTV becomes standard require wall power to run, which would make those analog battery powered TVs useless, and (2) many radio stations no longer have a news department, acting more as satellite feeds for a central office, so your transistor radio may not be able to pull in anything useful, either. Oh yeah, and many folks are moving away from conventional land-lines at home and going to VOIP phones or cell phones exclusively.

The classic way to deal with system failure is through redundancy: if the TV network goes out, you still have radio, which can get you much of what you need, or maybe you still have telephone. And so forth. The problem is that redundancy only works where you can stop a failure in one system from propagating to other systems. That's one reason most software doesn't have a redundant design: it's very hard to predict how far the effects of a failure will propagate through software, so it's generally not cost-effective to make it redundant. As our networking capabilities become more sophisticated, we're getting to the point where it's becoming harder to figure out what effect a failure of one network will have on the other networked systems we use.

The right way to do this, from an engineering perspective, is to take these sorts of problems into account when designing the systems, and then to periodically test them to make sure we got it right. That's not going to happen, at least right now, for social and economic reasons. The second-best approach would be to invest time and money into developing the design and evaluation tools necessary to either constrain the effects of a failure, so they don't propagate to other systems, or to at least be able to predict the likely failure modes and how far they'll propagate. We might eventually do that, but it'll take time. What's most likely to happen is the same thing that happened in structural engineering a hundred years ago: we may well see a series of unexpected, unforecasted failures, and they'll likely continue until we implement one of the first two approaches above.

Sunday, July 06, 2008

switching antivirus software

For a couple years, now, I've been using AVG Free edition. And for the last month or two, they've been pressuring me to upgrade to version 8. When I install new software, I often skim the End User License Agreement. In this case, here's what I turned up in the EULA for AVG Free 8.0:

6. Miscellaneous.

. . .

b. Privacy.

i. You acknowledge that AVG Technologies collects certain information regarding the users of the Software, including certain personally identifiable information. You hereby consent to AVG Technologies' collection and use of such information, and agree that AVG Technologies' collection and use of such information will be governed by AVG Technologies' Privacy Policy, currently published at www.avg.com, as AVG Technologies may revise the same from time to time.

ii. BY PROCEEDING TO INSTALL THE TOOLBAR, YOU ACKNOWLEDGE AND ACCEPT THAT, UPON ITS INSTALLATION, THE TOOLBAR WILL MODIFY VIA THE SETTINGS OF YOUR BROWSER THE "DNS ERROR PAGE" AND "ERROR 404 PAGE". . . .
I'm not too thrilled with the idea of my antivirus software communicating personally identifiable information back to the manufacturer based on a privacy policy they can change at any time. Based on the language in this agreement, I don't see any restrictions that would prevent them from changing the privacy policy in such a way that they could return any contents of my hard drive that they chose to. I also don't really like the idea of a toolbar redirecting DNS and Error 404 pages. The intent is probably to allow them to redirect to a "we didn't find your web page, but here are several similar pages" search engine that provides revenue to AVG, but (a) they don't make that explicit in the agreement, and (b) I don't know what effect such a redirection would have on Firefox, especially in odd situations like running a search while there's no wireless network connection, something that happens fairly frequently when our wireless cuts out.

Net upshot: I'm giving Avast Free Edition a try, instead. I've been running it on a desktop machine that I use occasionally for games, but this'll be the first time on the laptop I use frequently. The only difficulty I ran into is that Avast doesn't automatically uninstall AVG, so you need to do that manually via Add/Remove Programs (off the Control Panel). Also, Avast has a spinning logo in the tool tray, which is cute (the logo spins while it's doing its thing), but I find the movement distracting. However, the EULA was clean. Now we'll see how the program works.

Saturday, June 21, 2008

Off-Shore Oil Drilling

I've been sick for the last few days, which has left me with the dangerous combination of being grumpy and having some time on my hands. Which brings me to the topic at hand.

President Bush has called for drilling in the outer continental shelf. Specifically, he has said the following:
In the short run, the American economy will continue to rely largely on oil. And that means we need to increase supply, especially here at home. So my administration has repeatedly called on Congress to expand domestic oil production. Unfortunately, Democrats on Capitol Hill have rejected virtually every proposal -- and now Americans are paying the price at the pump for this obstruction. Congress must face a hard reality: Unless Members are willing to accept gas prices at today's painful levels -- or even higher -- our nation must produce more oil. And we must start now. . . .

First, we should expand American oil production by increasing access to the Outer Continental Shelf, or OCS. Experts believe that the OCS could produce about 18 billion barrels of oil. That would be enough to match America's current oil production for almost ten years.
What's interesting about this statement is that the Department of Energy ran a study on drilling in the OCS just last year. The study looked at the current restrictions, which expire in 2012, and mapped out the cases where drilling is allowed and where the restrictions are renewed and no drilling takes place. It found that
access to the Pacific, Atlantic, and eastern Gulf regions would not have a significant impact on domestic crude oil and natural gas production or prices before 2030. Leasing would begin no sooner than 2012, and production would not be expected to start before 2017.
So if we suppose that Congress ends the restrictions in 2008, a good first guess is that'd accelerate the timeline by about 4 years across the board: no production sooner than 2013 and no significiant impact on prices before 2026.

The reason there's no significant impact on prices is that OCS drilling would increase domestic oil production by about 7%, but oil prices are set on an international basis. In other words, the amount of increased production domestically wouldn't be enough to have a significant impact on global oil supply. Let's assume that oil would increase supply and therefore lower prices in the U.S.. In that case, the oil companies would have the choice of selling at a lower price in the U.S. market or at a higher price to the international market. Past behavior suggests that the executives directing those companies would feel constrained by a fiduciary duty to their shareholders and would therefore sell on the international market. As a result, the domestic prices would rise to meet the international prices. Now, we could impose laws that prevent the oil companies from selling that crude overseas, which might artifically drive down domestic prices, but those sorts of trade restrictions seem out of character for Mr. Bush's administration. So the most likely result is that a goodly sized chunk of any oil drilled here will feed China's demand for it.

Earlier in the speech, Mr. Bush said, "In the long run, the solution is to reduce demand for oil by promoting alternative energy technologies." It is not clear what time frame "the long run" represents, but there are already interesting developments on the alternative energy horizon, particularly in storage of electricity. For example, Zenn Motor Company and EEstor have announced plans to ship an electric car in late 2009 that will go 80 MPH and have a range of 250 miles and that a properly equipped charger could recharge in a few minutes. Similarly, A123 Systems is currently selling a new lithium ion battery technology with dramatically better energy density. (You can currently buy their stuff in certain lines of Dewalt cordless power tools while they work on the long battery life necessary for plug-in hybrids. They are also currently selling plug-in conversions for the Toyota Prius, though at $10K they're currently a little pricey for my budget.) It's also possible--today--to produce biodiesel from algae (rather than, say, corn), something you don't need arable land to do. (Hmm. I wonder how much land you'd have to devote to algae production to remove a billion tons of carbon dioxide per year from the atmosphere, since bamboo ain't gonna cut it.)

In the meantime, higher fuel prices are having an impact on demand. Amtrak ridership continues to set records, and high gas prices are sending it way up. And Ford is scaling back production for gas guzzlers due to decreasing demand.

Bottom line? Maybe drilling the OCS is not an effective answer either to Mr. Bush's short term goal of increasing supply (beyond insignificant levels) or to his long term goal of reducing dependence on foreign oil.