Wednesday, February 8, 2012

TEncryption Hash Algorithm Part 2

In 2009, I made a post about turning a 4-bit hash algorithm into an 8-bit hash algorithm.

My idea was:
"My Password" --> 1100 --> {"11", "00"} --> {0100, 1011} --> 01001011


However, after reading it over, I realized that there was a gaping flaw. The probability of a collision wouldn't change!


Let's say "Password a" and "Password b" both hash to a 4-bit value of 0101. They would both hash to the same 8-bit value in my implementation. This is a major issue, because in theory, an 8-bit hash algorithm should have significantly less collisions (2^4 / 2^8 = 1/16 less chance of a collision).


So how to avoid this issue? Simple. Don't use the 4-bit hash as the basis for the 8-bit hash. Rather, use permutations of the password as the basis for the 8-bit hash. This can include reversing the password, truncating the password, or rearranging the password. This will, in theory, decrease the number of collisions.  


How about an example?

Previous implementation with collision:


"Password a" --> 1110 --> {"11", "10"} --> {1100, 1011} --> 11001011
"Password b" --> 1110 --> {"11", "10"} --> {1100, 1011} --> 11001011


New implementation with the same possible collision:


"Password a" --> {"Password a", "a drowssaP"} --> {1110,0110} --> 11100110
"Password b" --> {"Password b", "b drowssaP"} --> {1110,1000} --> 11101000


The point is just because one permutation of a password results in a collision with another password, with a good hash function, there is no indication that another permutation will also result in a collision.


Still, though, concatenation means that precomputing hashes of unsalted, known, commonly used passwords will help you figure out half the resulting hash is problematic. In the above example, the first four bits are 1110 in both passwords because of the collision. So to overcome that issue, you can salt the passwords with the username, or file name, or whatever, which should really be done anyway.


New implementation with salting


"Password a" --> {"Username, Password a", "Username, a drowssaP"} --> {1111,0110} --11100110
"Password b" --> {"Username, Password b", "Username, b drowssaP"} --> {0110,1000} -->01101000


New implementation with salting
(assuming "Username, Password ..." results in collision)

"Password a" --> {"Username, Password a", "Username, a drowssaP"} --> {0110,0110} --> 11100110
"Password b" --> {"Username, Password b", "Username, b drowssaP"} --> {0110,1000} --> 11101000

The only advantage of this is that an attacker could have precomputed that "Password a" hashes to 1110 if "Password a" is a commonly used password, but precomputing wouldn't help when salting.
Another "attack" on this idea is the fact that there might not actually be 2^8 unique hashes. This is because some 8-bit hashes might be impossible to construct from existing 4-bit hashes, and hence an attacker can significantly limit the search space if implausible hashes were to be precomputed. This, however, would be very difficult to do and would take a bit more brain power to figure out than I have available right now, although I recognize the theoretic possibility.

Tuesday, January 17, 2012

A Day In The Life Of...

Here's an interesting way of thinking about life and perhaps putting it in perspective.  This may be motivational or demotivational to you; I'm not sure.

So let us say that you will live to 80 years old, which is reasonable in America.  Assume that your life was compressed into a single day.  Here is what it would look like.


Hour Age
6am - 7am 0 - 5 years old You just wake up. You're still a bit groggy, and are getting used to your surroundings.
7am - 9am 6 - 15 years old You are up and exploring the world around you. Going through some trials and having some fun.
9am - 11am 16 - 25 years old You venture outside, go to some parties, and hang out with your friends
11am - noon 26 - 30 years old You first arrive at work, and try to prove that you belong to be there
noon - 7pm 31 - 65 years old Your most productive hours at your job, and the time you really establish your place.
7pm - 8pm 66 - 70 years old You start to leave and retire for the evening
8pm - 10pm 71 - 80 years old This is your time to do as you please. Have a few drinks before bed, and enjoy yourself.
At 24 years old, It's only around 10:50 am for me; I have a long day ahead of me and must get to work!

Friday, January 6, 2012

Craftsmanship

Since finishing my classes 2 semesters ago, most of my graduate school time has been split between writing papers and writing code.  I must say I enjoy writing code more, but the papers have their purposes.

I have spent a good deal of time learning about how professionals write "good" code.  I put that word in quotes because good isn't an objective measure, and is different for each project.

But I have come to see a beauty in the algorithms, libraries, protocols, and such.  When I see a well designed project on github, or learn about how a large company uses version control to automatically distribute releases, or delve into the intricacies of the efficient and stable ZFS filesystem, I can't help but see the beauty in the system.

All the pieces have been so well designed, meant to perfectly fit together.  The internal structure of the gas tank doesn't need to be visible to the engine, and the internal structure of the engine doesn't need to be visible to the driver.  But when a car aficionado opens the hood of a well designed piece of machinery, he sees how beautifully designed every single piece has been, carefully fit together with its neighbor.

Then you take a step back, and realize that many of the pieces are actually used in other models.  So you take another step back and see the beauty of the manufacturing process efficiency.  Each piece has been designed minimize the ugly overhead of redesigning things for each new model, although this is sometimes necessary.  I saw a commercial for a new Lexus car, in which they touted making a fuel optimizer system which can input any type of fuel, "even ones that haven't been invented yet."  A simple improvement to a base system (such as a  nut or bolt) can have a ripple effect of betterment for far reaching systems.

I am no car aficionado, but that's the type of beauty I see in a piece of software.  And that's the type of craftsmanship I strive for in my own projects, research or otherwise.

Thursday, January 5, 2012

Food Cost Basis

My good friends Joe and Clair, with whom I spend New Years Eve 2011, have decided that I need to write more blog posts, and even went so far as to suggest that it should be my new years resolution.  So this is my first one of 2012.

As I think about the price of groceries, and food in general, I intuitively would look at the "$ / pound" label in the supermarket as my normalized basis for how much things actually cost.  But that doesn't consider the nutritional content, as well as the amount of sustenance (calories) you actually get for that $.

Let's consider Kraft's 4% Cottage Cheese.  Shoprite had this for $1.89 / container this week.  The nutritional information lists 120 calories per 1/6 container.  That comes to 720 calories / $1.89 or 380 calories / $.  If you were on a 2000 calorie diet per day, it would cost you $5.25 to eat only cottage cheese that day.

If we look at a Subway Spicy Italian Sub, the footlong sub costs $5, and contains 960 calories.  So that would cost you $10.40 per day, or 192 calories per $.

Just for fun, let's consider vodka.  A handle is 1.5 liter, and contains 50 oz.  In 80 proof vodka, 1 fluid oz is 64 calories.  This means that vodka gives you 162 calories per dollar.

So this is just me ranbling on about random costs of food, and a list of some others I calculated can be found here, sorted by Calories / $.  Turns out rice is the cheapest; who would have guessed.  Also I completely ignored nutritional value in all of this analysis.  I should really consider macronutrient composition of various foods and how much nutrition you get per dollar, not just how much energy.  Maybe another time.

Tuesday, November 8, 2011

Induced Evolution

I had an idea briefly about evolution and curing diseases.

Let's say we want to cure HIV.  You could take some bacteria, or something that can get infected by HIV, and grow many cultures.  Then, you could infect that culture with the disease.  Artificially determine and kill off any bacteria which get infected.  Repeat until all you have left are HIV-resistant bacteria.  From these remaining, you could see what caused them to be resistant, or somehow develop a drug mimicking these properties.

We can artificially induce natural selection by (somehow) manually killing off cells which are infected.  The bacteria would adapt to this environment, and essentially "learn" HIV resistance.

This assumes the following:

  1. We can actually kill off only the infected cells without letting them reproduce.
  2. We can use the resistant cells to create a drug or some sort of cure.
  3. The organism you use can possibly, through some mutation, become resistant to the disease.  Since evolution can take a long time, perhaps something like radiation can be used to speed up the rate of mutation, and further the process along a bit.

Wednesday, October 26, 2011

Obama's Student Loan Plan: The Numbers

Obama recently touted his new student loan consolidation plan.  This is an issue which hits very close to home since I will have a lot of student loan debt when I graduate.

The gist is if you consolidate your government loans, then you save 0.5% on the consolidated rate.

Great!  But consolidating your loans means that you lose one very important thing: the ability to pay off the highest interest loans first.

So let's see how the numbers pan out.  We will assume that a person has 4 $12,000 loans (total of $48,000), with interest rates ranging from 5% to 8% will put $1,000 per month into the loans.

So I compared paying off the highest interest loans first, to Obama's consolidation plan.

The results: you end up paying almost the same amount at the end, and actually save $200 by not consolidating under Obama's plan.  Note that at the end of year 4, only 1 loan remained, I just had the person pay a constant amount per month for 12 months.  In actuality, the person would most likely put that $1,000 per month into the last loan, paying it off faster,and making the difference more pronounced.

Also note that when consolidating your loans, the first few years actually leave you with less remaining balance, since you aren't paying off high interest loans those first few years.  However, once you hit around the halfway mark (year 3) paying off the high interest loans actually pans out ahead.

Tuesday, September 13, 2011

Ph.D. - 90% Hard Work, 10% Intelligence

As I continue towards completing my Ph.D., there is one truth I've learned about a doctoral program.  That truth is that completing a Ph.D. is 90% hard work, and 10% intelligence.  When most people hear that somebody has completed his or her Ph.D., their first thought is, "wow, that person must be smart."  I want to dispel that myth right now.

Not that almost all Ph.D.'s I've met aren't very smart men and women, but that is not their defining trait.  Their defining trait is the ability, willfulness, desire, and dedication to work hard.  I'm sure this is also true in other professions and degrees, but it is not uncommon to work 7-day 80-90 hour+ weeks.  And that work includes difficult, as well as menial, work, with looming deadlines.

I strongly believe that if the (average?) American got accepted into a Ph.D. program, and put in the requisite time to read and implement everything they could regarding their chosen field for several years running, that person would undoubtedly be able to complete a doctoral program.  Intelligence and creativity are tools to help make completing a Ph.D. easier, but they aren't the main tools at one's disposal.  Given, one must have some baseline intelligence to understand everything one learns about his or her field, but that baseline intelligence is something almost everybody has.

So when I meet somebody and I found out they have a Ph.D., my first thought isn't, "wow, you must be smart", but rather, "wow, you sure know how to work hard."