Fighting with computers

Computers are not always friendly.

Wednesday, September 28, 2011

A bit more RSA

I really don't like when I do not understand anyone's code, so it takes me a bit of effort till I do my own homework to create my own version of things I can understand. Being a teacher, I always find troubling not to be able to explain things to my students, so I used some time to create my very own RSA implementation. I've found a very good reference text here.

My perl program takes three parameters data, encryption (or decryption) exponent and module and it returns the encrypted (or decrypted) version. As it uses BigInt library it should be happy dealing with any of your big numbers. You can find a Java implementation in the above mentioned text too.

use Math::BigInt;
     {print "Usage: exp, module\n"; exit 2;}
$a = Math::BigInt->new($ARGV[0]);
$b = Math::BigInt->new($ARGV[1]);
$c = Math::BigInt->new($ARGV[2]);
print "out=".($dec = $a->bmodpow($b,$c))."\n";
Contrary to what may look, bmodpow has been implemented to be computationally efficient using repeated squaring technique.
I have created an RSA keypair before choosing public exponent to be 3. The numbers seem to come out of thin air but I created them with a software tool mentioned in the previous RSA post. The plaintext 1234567890 (as a number and not as string) was selected as it was easy to type.
$ perl 1234567890 3 0x102421060aad49ec2521203b28
cyphertext = 1881676371789154860897069000

$ perl 1881676371789154860897069000 0xac2c0aeb1
80c9a2cec1bd7cff55566a6b 0x102421060aad49ec2521203b28ffdc
cyphertext = 1234567890

Update: I've found that Crypt::OpenSSL::Bignum is more than a thousand times faster doing the modular exponentiation of RSA. So avoid the BigInt approach if speed matters to you.

Wednesday, September 14, 2011

Playing with RSA

A recent assignment required me to dust off my knowledge of RSA (public-key encryption algorithm). While it is something I do teach every year, I usually do not have to fiddle with the code. So when I was needing a pair of keys (public+private) for some test I needed to look around for some  key-generation code.

Once I've got my pair of keys I was surprised with this implementation of RSA encryption in perl:

#!/bin/perl -sp0777i<X+d*lMLa^*lN%0]dsXx++lMlN/dsM0<j]dsj
$/=unpack('H*',$_);$_=`echo 16dio\U$k"SK$/SM$n\EsN0p[lN*1
However, the fastest way to get you working is using OpenSSL's genrsa command.

Tuesday, September 06, 2011

Remote Desktop is gone

Last year I bought a small notebook to keep me updated of what was available in Windows 7. Being a small computer, using it for a long session and, in particular the mouse pad, is not very pleasant. So while I am not on the go, I rather would prefer to access this computer remotely to use my desktop's bigger screen and more comfortable mouse.

I was shocked when I learned that Microsoft had "streamlined" some versions of Windows 7 so some features were missing for some of them. I later learned that Windows 7 Home Premium does not include the Remote Desktop server that was common in Windows XP.

I occasionally use remote control tools like TeamViewer with great success (or other variants of VNC) but the main problem is they do not work as smoothly as Remote Desktop Protocol (RDP) nor they allow you to resize the desktop area at log-on time.

One colleague of mine mentioned, while I was complaining about the missing Remote Desktop on my notebook, that there was a hack to get back Remote Desktop. I tried it, and it worked like a charm. Not only you can get Remote Desktop service back, but it is possible to get RDP concurrent sessions too.