My thoughts as an enterprise Java developer.

Friday, August 28, 2009

Bill would give president emergency control of Internet | Politics and Law - CNET News

Bill would give president emergency control of Internet | Politics and Law - CNET News: "The new version would allow the president to 'declare a cybersecurity emergency' relating to 'non-governmental' computer networks and do what's necessary to respond to the threat. Other sections of the proposal include a federal certification program for 'cybersecurity professionals,' and a requirement that certain computer systems and networks in the private sector be managed by people who have been awarded that license."

Why should we expect the executive branch to have the expertise and information to know how to best use that control?

Tuesday, August 04, 2009

Defeating Character Frequency Analysis of Substitution Ciphertext

(This is a paper I wrote in the fall of 2008 for CS461: Computer Security I at UIUC. If you are interest in the code leave a comment and contact info.)

Introduction


Character frequency analysis is a common way to crack substitution ciphertext because of the uneven distribution of letters in languages. In order to defeat that analysis, the techniques considered were: synonyms, dropping letters or words, adding extra letters or words, alternate spelling (Leet, spam, etc), and Two cipher letters per plaintext letter. Most of these techniques would be applied before a standard substitution cipher encryption. To evaluate the techniques, test data was obtained from Project Gutenberg(http://www.gutenberg.org/) and consisted of the texts of Psalms (Ps), Pride and Prejudice (P&P), Alice in Wonderland (AiW), and Sherlock Holmes (SH). After applying the technique, the output character frequency was compared to the standard character frequency (http://en.wikipedia.org/wiki/Letter_frequencies and http://www.data-
compression.com/english.html
) and then the standard deviation of the proportion of the changed frequency for each letter compared to the standard character frequency. i.e. If the letter "e" occurred 10% of the time in the changed text then the proportion for "e" is .787 (.10/.12702). That gives an overall measure of how close the changed text character frequency is to the standard character frequency. A standard deviation of 0% would mean that it exactly matches the standard frequency. Initial standard deviations are: Ps: 25%, P&P: 28%, AiW: 25%, SH: 14%. For comparison, an equal distribution produces a standard deviation of 1,439%. In LetterFrequencies.zip there are programs for most of these options and for computing the standard deviation.

Synonyms


Replacing words with synonyms that have a higher standard deviation can help defeat character frequency analysis. The thesaurus used has synonyms in categories, so when a word was looked up, the first category was arbitrarily used. Within the first category, the word that had the largest standard deviation from the normal character frequency was chosen. The chosen work often didn't fit grammatically, so the results are skewed, but this is somewhat offset by only looking in the first category. To make this usable, grammar checking would have to be used. It would probably need a UI that would suggest alternatives (based on grammar rules and the standard deviation). Attacks against this technique could include creating a list of the best synonyms, creating a new standard character frequency distribution for those words, and therefore largely defeat the benefit of this technique. Final standard deviation achieved: Ps: 182%, P&P: 180%, AiW: 135%, SH: 149%. The increase in standard deviation was very significant, but not enough to make a large impact on frequency analysis.

Dropping letters or words


Randomly dropping letters or words could easily hide the meaning from the intended recipient so it would be hard to keep the meaning while still randomly dropping enough to make an impact. An attempt to always drop vowels and rare letters (a,e,i,o,u,x,q) and words (I, the, is, was, of, a, & an) made an insignificant difference (Drop Words Ps: 8%, P&P: 6%, AiW: 8%, SH: 8%; Drop Letters: Ps: 73%, P&P: 91%, AiW: 69%, SH: 70%). Also, some of each letter would need to be dropped to prevent the non-dropped letters from serving as landmarks.

Adding extra letters or words


To be effective, extra letters and words must be randomly placed. They could be chosen based on the inverse of distribution. However, additions that have a significant impact on the standard deviation may garble the message too much. Add letters results(based on inverse of distribution): P&P: 2,154%, SH: 2,795%. The result is readable but takes significantly more work to understand the message.

Alternate spelling (Leet, spam, etc)


Alternate spelling includes l33t (http://en.wikipedia.org/wiki/Leet) and spam spelling (http://en.wikipedia.org/wiki/E-mail_spam#Obfuscating_message_content) and is similar to synonyms, in that the possibility of a new new standard character frequency has to be taken into account. This technique was not implemented or programatically evaluated because it was non-obvious what to use as the standard distribution.

Two cipher letters per plaintext letter


Using two letters in the cipher text for each letter in the plaintext can be a good way to create a flat character distribution. The algorithm is to partition the 676 2-letter combinations based on the standard character frequency. i.e. if the standard frequency for a letter is 5% then it will get 5% of the 2-letter combinations (randomly selected). This doubles the size of the data, could include spaces & punctuation, and makes a much larger key. Note that some letters may get dropped because they occur less than 1/676 (0.15%) of the time. Both 1-gram and 2-gram frequency analysis produce a nearly uniform histogram (variation appears to only be caused by rounding). Two-gram results: P&P=5,117%; SH=5,013%. Therefore this technique was extremely effective with no obvious weaknesses.

Conclusion


Changing the plaintext proved problematic because of inadvertent changes to the meaning, but it did make a significant impact on standard deviation even though it probably wasn't significant enough. Applying all of the plaintext changes to a short message while using safeguards to protect the meaning would probably be effective. Two cipher letters per plaintext letter appears to be the easiest way to defeat character frequency analysis.

Friday, July 31, 2009

Sample chapter from Don't Make Me Think

Sample chapter from Don't Make Me Think: "Why are things always in the last place you look for them?
Because you stop looking when you find them.
—Children’s riddle"

Great info on usability.

Thursday, July 30, 2009

Pressure sensitive keyboard for repeat rate

Would it be helpful to have a pressure sensitive keyboard where the pressure determines the repeat rate (harder=faster, etc)? It seems that it would be especially useful for navigation keys (arrow, page up/down) and keys commonly repeated (enter, backspace, delete, space, tab). Does such a thing exist? Was it tried and how well did it work?

Wednesday, July 29, 2009

Ex-Google CIO breaks his own security rules | InSecurity Complex - CNET News

Ex-Google CIO breaks his own security rules | InSecurity Complex - CNET News: "But 'it's not security's responsibility to go out there and say 'Users want to use Gmail. Let them use it,'' Johnson added. 'If we decide to use Gmail we need to have a project and treat it in a formal way and pay money to do it right.'"

So are you going to have a project for every website that users might find useful? There is no way that you will keep up and the barrier to using useful websites will significantly hurt productivity.

Beyond the hype: Where open source actually saves you money | The Open Road - CNET News

Beyond the hype: Where open source actually saves you money | The Open Road - CNET News: "One way, as Urlocker points out on his blog, is that open source allows enterprise IT projects to succeed or fail with little risk. You know before you pay anything--if you pay anything--that open-source software is going to work, or not."

"Open source tends to offer best-of-breed solutions that aim to do a limited range of functions well, rather than to be all things to all people."

Saturday, July 25, 2009

MIT OpenCourseWare | Electrical Engineering and Computer Science | 6.854J Advanced Algorithms, Fall 2008 | Home

MIT OpenCourseWare |


Electrical Engineering and Computer Science | 6.854J Advanced Algorithms, Fall 2008 | Home
: "This is a graduate course on the design and analysis of algorithms, covering several advanced topics not studied in typical introductory courses on algorithms. It is especially designed for doctoral students interested in theoretical computer science."

Monday, June 22, 2009

Pattern Formatter for java.util.logging

Pattern Formatter for java.util.logging: "The Log Formatter will use the following formatting tokens:

* LoggerName %LOGGER%
* Level %LEVEL%
* Time %TIME%
* Message %MESSAGE%
* SourceClassName %SOURCECLASS%
* SourceMethodName %SOURCEMETHOD%
* Exception Message %EXCEPTION%"

Thursday, May 07, 2009

Save Icon

The most common save icon is a picture of a floppy disk.

But with floppy disks not being used anymore will most programs change the picture? In 1-2 decades what picture will be used for save icons?

Thursday, April 16, 2009

FBI seizures highlight law as cloud impediment | The Wisdom of Clouds - CNET News

FBI seizures highlight law as cloud impediment | The Wisdom of Clouds - CNET News: "The articles report that the FBI raided at least two Texas data centers last week, serving search and seizure warrants for computing equipment, including servers, routers, and storage. The FBI was seeking equipment that may have been involved in fraudulent business practices by a handful of small VoIP vendors.
The problem is that they didn't just grab the systems belonging to the VoIP vendors, but grabbed hundreds of servers serving a wide variety of businesses, the vast majority of which had never dealt with or even heard of the companies under investigation, according to Threat Level. Company officials interviewed complained of losing millions of dollars in lost revenue and equipment with no warning whatsoever."

"If the court upholds that servers can be seized despite no direct warrants being served on the owners of those servers (or the owners of the software and data housed on those servers), then imagine what that means for hosting your business in a cloud shared by thousands or millions of other users."

"Here is what I argue must happen:
The law must respect digital assets in the same way that it respects physical assets. This means that search and seizure rules should apply to data and software run on third party infrastructure (or wholly owned infrastructure run in third party facilities) in the same way that they protect my home and personal property if I rent an apartment in a building housing hundreds of tenants. The fact that one tenant commits a crime is not enough for the civil liberties of all of the other tenants to be null and void. I argue the same goes for digital assets "renting" space in the cloud.
The federal government should adopt a cloud computing bill of rights. (Here is a rudimentary example.) Each state should as well. Declare loud and clear that you suffer little or no loss of rights if you choose to run your business in the cloud over running it within your own facilities. Repeal or revise the laws that make it impossible for foreign businesses and governments to allow communications and data to pass within U.S. borders (including relevant elements of the Patriot Act).
It is time for our policy makers to step up and really understand the influence that the Internet and cloud computing will have on the future growth of this country. It is scary how little technical understanding most congressional and senate members have. However, that alone is not an excuse for not grasping the policy gaps that are brought about as our commerce and society rely increasingly upon Internet-based services."

Wednesday, January 28, 2009

Caching strategy

Generally Least Recently Used (LRU) is considered a good strategy for removing items from the cache. Instead it might be useful to measure the cost (i.e. time) to produce a cache item, and how many hits that item gets and then remove the item that has the lowest value of hits * cost.

A quick Google search didn't find anything like this. Comments?

Saturday, November 01, 2008

Lego Mindstorm NXT program

I temporarily had a Lego Mindstorm NXT and wrote the following program for it using LeJOS.  Enjoy:
import java.util.*;
import lejos.nxt.*;
import lejos.util.*;

public class Dingbot {
public static void main (String[] aArg) throws Exception {
new ButtonWatcherThread(new TimerListener() {
public void timedOut() {
running = !running;
}
}).start();
motorRight.smoothAcceleration(true);
motorLeft.smoothAcceleration(true);
final float circumference = 17.5f;
final int distanceBuffer = 50;
final int rotateDistance = 80;
UltrasonicSensor distSensor = new UltrasonicSensor(SensorPort.S4);
LightSensor litSensor = new LightSensor(SensorPort.S2);
litSensor.setFloodlight(true);

LCD.drawString("Hi",1,1);
int startTime = (int)System.currentTimeMillis();
boolean blinkLight = true;
Random random = new Random();
while(startTime + 60*1000 > (int)System.currentTimeMillis()) {
if(running) {
int cmDist = distSensor.getDistance();
while(running && cmDist > distanceBuffer) {
LCD.drawString("   ",1,2);
LCD.drawInt(cmDist,1,2);
int distance = cmDist - distanceBuffer;
if(distance > 5) {
distance = 3;
}
int degrees = (int)(360 * distance / circumference);
setSpeed();
motorRight.rotate(degrees, true);
motorLeft.rotate(degrees, true);
cmDist = distSensor.getDistance();
litSensor.setFloodlight(blinkLight);
blinkLight = !blinkLight;
LCD.drawInt(litSensor.readNormalizedValue(),1,4);
}
boolean turnPositive = random.nextBoolean();
while(running && cmDist <>
LCD.drawString("   ",1,2);
LCD.drawInt(cmDist,1,2);
setSpeed();
if(turnPositive) {
motorRight.rotate(180);
} else {
motorRight.rotate(-180);
}
cmDist = distSensor.getDistance();
}
} else {
try {
Thread.sleep(500);
} catch(InterruptedException ie) {
//Ignore
}
}
}
}

public static void setSpeed() {
int soundLevel = sound.readValue();
LCD.drawString("   ",1,3);
LCD.drawInt(soundLevel,1,3);
int speed = (100 - soundLevel) * 9;
motorRight.setSpeed(speed);
motorLeft.setSpeed(speed);
}
static Motor motorRight = Motor.B;
static Motor motorLeft = Motor.C;
private static SoundSensor sound = new SoundSensor(SensorPort.S1);
private static boolean running = false;
}

class ButtonWatcherThread extends Thread {
public ButtonWatcherThread(TimerListener tl) {
this.tl = tl;
this.setDaemon(true);
}
public void run() {
wasPressedLast = touchSensor.isPressed();
while(true) {
boolean isPressed = touchSensor.isPressed();
if(wasPressedLast != isPressed) {
if(isPressed) {
tl.timedOut();
}
wasPressedLast = isPressed;
}
try {
Thread.sleep(100);
} catch(InterruptedException ie) {
//Ignore
}
}
}
private TimerListener tl;
private boolean wasPressedLast;
private TouchSensor touchSensor = new TouchSensor(SensorPort.S3);
}

Friday, October 31, 2008

Thursday, October 02, 2008

Digital money

I think digital money should have these features:
  1. Hard to counterfit
  2. Hard to duplicate (and use twice)
  3. Easy to transfer to another person with minimal involvement of a 3rd party
  4. Easy to use, track, store, verify, etc
  5. Transaction fees must be very, very low.
  6. Minimal Big Brother tracking.
Here is one idea for how to accomplish that:
A user would go to a website and enter payment info and the website would send the user an image file. The file would be a picture of the amount of money that it represents (for ease of use) and would have comments in it that record the originating website, amount and any other needed info. The website would generate the image so that is unique (i.e. the bits are unique) and would store the image bits and amount in a database. The file would have to be large enough so that a brute force attempt to generate random files would be too expensive.
When the user needs to split an amount (make change), they would send it to the website and request the new amounts. The website would verify that it was valid (in their DB), send new image files to the user, and delete the record for the old file.
When the user needs to send money to another person they would just get the correct amount (using splitting or multiple files) and send those files to the other person. The other person would send them to the website to get their own files so that the old file is invalid and they have a valid file. Once the other person saw that they were valid they would complete the transaction with the first person.
Verification consists of sending to the website to get an new file. If the file was invalid the webiste would just give an error message. Anytime a user receives money from another user they must verify it (get a new file) to make sure that it is valid.
The user could cash out the file by going to the website and requesting payment.
Transaction fees would be limited to the initial payment and requesting payment.

The user could have requested multiple files with various amounts to make it easier.
If someone tries to make a copy of the file in order to use it twice only the first copy would be validated.

The user would need to remember to not make any changes to the image (i.e. rotation) because that would invalidate the file. Therefore the image formats that Windows Explorer can rotate should be avoided or the files always marked as read-only.

This idea could work for trading anything (different currencies, stocks, etc). Each website would have its own file type but websites or users could translate between the different file types.

Comments?

Wednesday, August 06, 2008

Spell check what others write

I think programs should spell and grammer check what others wrote. i.e. If I am reading a webpage it should have some way of marking bad spelling or grammer with a way to see suggested improvements. That would allow me to understand the intent better when the grammer or spelling is poor.

Do you agree that adding this feature to browers, IM clients, etc would be useful?

Monday, June 16, 2008

XSL: Preserving line feeds, tabs, and spaces in data while still wrapping text

I had data in XML that had line feeds, spaces, and tabs that I wanted to preserve (so I couldn't use

) but I also wanted the lines to wrap when the side of the screen was reached (so I couldn't use

).

After some research and help from a co-worker (Patricia Eromosele) I made the XSL template below that achieves that. An example of how to call it follows:


<p>
<xsl:call-template name="prewrap">
<xsl:with-param name="text" select="text"/>
</xsl:call-template>
</p>



<xsl:template name="prewrap">
<xsl:param name="text" select="."/>
<xsl:variable name="spaceIndex" select="string-length(substring-before($text, ' '))"/>
<xsl:variable name="tabIndex" select="string-length(substring-before($text, '&#x09;'))"/>
<xsl:variable name="lineFeedIndex" select="string-length(substring-before($text, '&#xA;'))"/>
<xsl:choose>
<xsl:when test="$spaceIndex = 0 and $tabIndex = 0 and $lineFeedIndex = 0"><!-- no special characters left -->
<xsl:value-of select="$text"/>
</xsl:when>
<xsl:when test="$spaceIndex > $tabIndex and $lineFeedIndex > $tabIndex"><!-- tab -->
<xsl:value-of select="substring-before($text, '&#x09;')"/>
<xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
<xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
<xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
<xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
<xsl:call-template name="prewrap">
<xsl:with-param name="text" select="substring-after($text,'&#x09;')"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="$spaceIndex > $lineFeedIndex and $tabIndex > $lineFeedIndex"><!-- line feed -->
<xsl:value-of select="substring-before($text, '&#xA;')"/>
<br/>
<xsl:call-template name="prewrap">
<xsl:with-param name="text" select="substring-after($text,'&#xA;')"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="$lineFeedIndex > $spaceIndex and $tabIndex > $spaceIndex"><!-- two spaces -->
<xsl:value-of select="substring-before($text, ' ')"/>
<xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
<xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
<xsl:call-template name="prewrap">
<xsl:with-param name="text" select="substring-after($text,' ')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise><!-- should never happen -->
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

Tip: Java thread dumps on linux

To get a thread dump in Java on linux run "pkill -3 java"

Ethical programming

It should be noted that no ethically-trained software engineer would ever consent to write a DestroyBaghdad procedure. Basic professional ethics would instead require him to write a DestroyCity procedure, to which Baghdad could be given as a parameter.
-- Nathaniel Borenstein
(Passed on by Reid Nimz.)

Friday, February 15, 2008

Rename multiple files

Options for renaming multiple files on Windows
  1. Windows explorer: It only renames them to xxxx (y).ext where the only thing that varies is y (an incrementing number).
  2. Various utilities available for download: I don't like to risk running some unknown program for something that seems so simple.
  3. Command line for in do command. To prepend "3-" to every directory that starts with "60-" run: for /d %i in (60-*) do ren %i 3-%i