Monthly Archives: June 2008

RSA Encryption, Part 1

5
Filed under Uncategorized

I’m always really surprised, disappointed, and a bit gassy over how despised anything involving even the simplest of Mathematics is by most Computer Scientists; the mere mention of the word “derivative” is enough to invoke a cringe of repressed childhood-pain from all but the strongest-willed of programmers. However, even if a ‘matrix’ is nothing more to you than a bootleg DVD you torrented when you were 16, you can still enjoy the limitless pleasure provided by a basic understanding of modern mathematics. In fact, after a few simple preliminaries in modular arithmatic (don’t worry – it’s not nearly as scary as it sounds), the algorithm for RSA encryption is actually incredibly simple – so buckle your seatbelt and put on your thinking cap for today’s magical adventure into the strange and wondrous world of mathematics.

1. Modular Arithmetic
If you are still reading this, then either you were misdirected here by the malevolent Internet traffik demon (which means my monetary bribes are working), or you sincerely want to learn how RSA encryption works, in which case I hope our almighty five-legged overlord takes mercy on your soul as it burns in the deepest pits of hell.

Most programmers are familiar with the syntax
18 mod 5
In case you are not, mod (which stands for modulus) simply gives back the remainder from dividing the left number by the right. Since the remainder of 18/5 is 3, this means
18 mod 5 = 3

In mathematics, the syntax is a bit different. Rather than saying “the modulus of 18 by 5 is equal to some number (ie. 3)”, we say “18 is congruent to some number mod 5." It is just as correct to say “3 is congruent to 18 mod 5″ as it is to say “18 is congruent to 3 mod 5.”
We would write this latter statement as 18 ≡ 3 (mod 5).

This notation allows us to do some very cool symbol-pushing (all of which, I assure you, is completely valid). For instance, it can be shown that the properties of most normal integer operations – addition, subtraction, multiplication, exponentiation – carry over to modular arithmetic, so that, for example,
xa * xb ≡ x(a+b) (mod n)
It is also rather obvious (and, of course, can be proved) that when adding, subtracting, or multiplying, you can replace one number with another it is congruent to; so, for instance, since 18 ≡ 3 (mod 5),
182 ≡ 32 ≡ 9 ≡ 4 (mod 5)

When working with negative numbers mod n, we find congruencies by simply adding n repeatedly until we get a positive number. For example,
-21 ≡ -1 ≡ 19 (mod 20)
This gives us a new trick to put in our bag for determining (without a calculator) some large numbers mod n:
1910 ≡ (-1)10 ≡ -1 ≡ 19 (mod 20)

Cool!

In modular arithmetic, we are usually concerned with only integers; this means that numbers don’t have fractional inverses the way they do in regular arithmetic. That is, there is no number you can multiply 5 by (mod 10) to get 1, since we’re not considering 1/5 a number. Nonetheless, there are certain cases in which numbers in modular arithmetic still have inverses! For instance, notice that 7 * 3 ≡ 21 ≡ 1 (mod 10), so 7 and 3 are inverses (mod 10).

For a final example to show just how powerful modular arithmetic is, let’s calculate the last decimal digit of, say, 3403. Notice that “the last decimal digit” is the same as “its value (mod 10).” Hence, we’re looking to reduce
3403 (mod 10).
The solution is actually quite simple. First, we realize that
34 ≡ 81 ≡ 1 (mod 10)
Then, since 3403 = (34)100 * 33,
3403 ≡ (34)100 * 33 ≡ (1)100 * 33 ≡ 27 ≡ 7 (mod 10)
Thus, in less than a minute, we just determined that the last digit of 3403 is 7, without a calculator!

Go on to part 2…

A number has a unique inverse (mod n) if and only if it is relatively prime to n. The concept of “relatively prime” will be briefly discussed in the next post.

That New Car Smell

5
Filed under Uncategorized

My friend Nephtali (yes, like the Egyption queen) recently turned 30, so to celebrate, he bought himself a car for when he gets his license:


Ain’t she a beauty? (click to enlarge)

However, there’s something you should know about Nephtali: he likes to customize everything. That was his car a week ago. Here’s his car today:


Ain’t she a beauty? (click to enlarge)

He sent me those pictures and I thought they were interesting, so I just thought I’d share.

signing up for a user account

1
Filed under Uncategorized

  this is a minor post, not even worthy of capital letters.

  though i can’t imagine why, a number of you were asking how to sign up for a username to keep others from using it, since anyone can type in whatever name they want. if it’s really that important, you can sign up for an account here. since i am not keeping a link to this page on the site, you’ll have to visit it any time you want to log in.

  full-fledged users get the following amazing benefits all in one extremely affordable package:

  • don’t have to put up with having not verified next to your name
  • can skip the captcha (funny-looking image at the bottom of the page)
  • all of your actions within the site are recorded and logged for my own amusement

  this is a limited-time offer, so don’t miss out – sign-up now!

Really Simple, Stupid

1
Filed under Uncategorized

  Hello, my name is Raja, and I have a problem.
    Hi Raja.
  Thank you. For the past year, I have been struggling with an addiction – a disease – which has been ruining my life at every turn. I lost my job, my wife, and my prized gumball collection because I kept telling myself I didn’t have a problem. Also my dog died. I used to insist that I could quit anytime I wanted, and would sometimes give it up for brief periods; however, my hiatus would inevitably be cut short, and I would always end up being drawn back to it, unable to free myself from its wicked, tyrannical grasp. And now Sparky is dead.
  My name is Raja. And I am addicted to RSS Feeds.
    *Applause, hugging, and crying*

  Though I’m sure most of you are already aware, for those of you who aren’t, an RSS feed is a thing that enables you to check for updates from all your favorite sites (that support it) in one place. RSS feeds are viewed through an RSS reader – I like Google Reader:


What Google Reader looks like after neglecting my feeds for a day (click to englarge)

  There are lots of different RSS readers out there, some of which even download your feeds and allow you to read them offline – even Internet Explorer 7 has its own (crappy) RSS reader! You can find tons of them by simply googling RSS reader

  Once you have a reader picked out, adding a feed to it is easy. For instance, to subscribe to a feed using Google Reader, simply hit Add Subscription and paste the link to the feed. Links to feeds can usually be recognized by one of the following images on a webpage:

  In addition, some pages also hide a link to the RSS feed in the source-code. For some reason, Internet Explorer does not support these types of links; however, in Firefox, the link is given directly in the address bar:

Once you have feeds from all your favorite sites, they are updated automatically in the reader – all you need to do is come back to check on them every once in a while.


An example of what a feed looks like

That’s all there is to it – now you too can share the the joys of this terrible, debilitating affliction. Here are some feeds to start you out: