Tuesday, November 15, 2016

End to end encryption

WhatsApp recently added end-to-end encryption to its app, for increased security. But, what exactly is it? Let's take a very simple example to see how it works. Consider two users, Alice and Bob.
Assume Alice wants to send Bob a message, which is 24.

Alice and Bob both generate a pair of "keys"; for simplicity and explanation in this example, we'll consider keys as arithmetic operations.

So the two keys that they generate are called public and private keys; public keys are visible to everyone, while only the user knows his private key.

These work in pairs, so something encrypted with a user's public key can be decrypted with his private key, and vice-versa.

So let's say Alice's "keys" (or arithmetic operations in this example) are as follows: her public "key" is "*2" or multiply by 2 operation. Therefore, her private "key" will be "/2" or the divide by 2 operation. In real life, deciphering the private key from the public one isn't easy.

For Bob, let's assume his private "key" to be "*3" and his public "key" to be "/3".
Now, Alice wants to send the message "24" to Bob. What she does is she encrypts it with her private key and his public key, so that Bob can decrypt it with her public key and his private key. The public keys are stored in a global directory, so anyone can access them.
So, Alice encrypts 24 with her private key; so, 24 becomes 12, and then she further encrypts this with his public key; so, 12 becomes 4.

Bob, on receiving the message, first decrypts it with her public key; so, becomes 8. Then, he decrypts that with his private key. So 8 becomes 24, which was the original message.

Hope that was a good explanation. Leave your thoughts in the comments!

Machine Learning Project

Hey guys! I have a couple of interesting Machine Learning ideas that I thought of quite a while ago, and I'm happy to say I'm implementing one of those as my ML class project. As you know, Machine Learning involves giving the computer some data which it can use to 'learn' a model. This model can then be used for a variety of applications. The most interesting one I heard of from my professor is texture stitching.

Texture stitching involves taking the same thumbnail and repeating it over and over to form a nice, large texture. You may have seen the abstract wallpapers here and there, like the brick wall. Apparently that's not a picture of a whole wall, but rather a small piece repeated several times. The ML model learns the image and tries to stitch in a way where that fact is not obvious. And we have seen the results, they're quite breathtaking.

Anyway, back to my project ideas. So I have two, one which I call Y U No Reply, and another which I call Spirited.

Y U No Reply: In this one, the user downloads a Chrome extension, which tracks their email activity. This data is uploaded to a server, where a model is trained for every specific user. Now on the user side, say someone I want to email has downloaded the extension. I want to find out when the best time to email them is, to get a quick response. So in addition to the Chrome extension, there will be a web app which can display information about user email patterns. So I enter their email ID into the web app, and it gives me a bunch of statistics, including when the best time to email them is and if I email them right now, how much time they will take to reply.

Spirited: This is one I started developing in a hackathon, and am now refining and improving as my class project. This is a browser/Chrome extension that guesses your mood based on the websites you're browsing and how quickly you're switching/closing/opening tabs. This uses the circumplex mood model, where you can plot the user's mood as a point on the Pleasure-Activity axes. For example, high pleasure and low activity means calm and relaxed. High activity and low pleasure means stress, which might mean the user is under a deadline. So based on the mood, we train a model which predicts the user mood at different times of the day. Based on when they open the browser, the model will make a prediction for, say, the next hour, and create a playlist from the user's library that will supplement the mood.
For example, for a calm mood, the model would play slow songs, while for an under-the-deadline situation it would play an upbeat song (assuming the user wants to be listening to music under pressure), which is proven to increase productivity.

So as you can see, the applications of ML are endless. It is an emerging field and is capturing the attention of researchers everywhere. I find it fascinating because of what all you can do with it.

Sunday, November 13, 2016

Ricoh Theta S

I have begun (unofficially) working on my thesis, and got a chance to tinker around with a piece of technology I had never heard of before: a 360 degree camera, or 360 camera for short. The one I am using is the Ricoh Theta S, which is a sleek, upright camera. It has two 180 degree lenses on its two opposite sides. These two capture two separate 180 degree images, and the driver that we install on the computer stitches them into one, large, panoramic, 360 degree image. The clarity on this image is better than I expected: I could examine a spot on my desk where someone had spilled something.


If you observe carefully, you'll see two distinct stitch lines; that's where the driver (Theta UVC Blender) comes into play. Note: On the far right, you can see the white spot I was talking about.

Now this has exciting applications. What I am using it right now for is Virtual Reality, or VR for short. This image looks stunning in a VR headset. There were some problems getting a stream set up from the Ricoh Theta S to a Google Cardboard (inexpensive yet high quality VR headset). I set up a server on my DigitalOcean droplet. On that I configured nginx (pronounced engine x) to use as an RTMP (Real Time Messaging Protocol) streaming service. But the problem with this was the lag. To put things in perspective, when I waved at the camera, it took 6 seconds for the viewer to see that I was waving. This would not work. The project I am working on requires the stream to be real time (Obviously, there will be some lag, but it needs to be reduced to a negligible value).

Finally, after days of research, I stumbled upon HugVR, a neat little website that lets you stream live from 360 cameras. To view this in VR, all I did was open the browser on the phone (the one used in the Cardboard), select the Google Cardboard view (this website has an option, just like YouTube), and view my stream in real time. The best part was the fact that the image was navigable. Earlier, when I set up the server myself, the image was a wide panorama, which was a little overwhelming. In the latter example, however, It is limited to 135 degrees (I think), and to view other parts of the image you have to turn your head, just like you would have to in real life.

To conclude this article, the combination of the Ricoh Theta S , the Google Cardboard, and HugVR works like a charm. I'm definitely going to be using this in my project and will explore more in the future.

Thursday, April 3, 2014

Testing

There is a common misconception that testing should not be done by developers and it is somehow demeaning. Au contraire, it is equally (if not more) awesome as development. In testing you get to think of ways you can break your colleagues' software/website and are actually paid to try. And if you succeed, you're not reprimanded, but congratulated!
Testing done by a programmer has several advantages:

  • The tester will know how the developer thinks, so it will be easier for him to find discrepancies.
  • Being a developer himself, he will be able to suggest solutions that are actually feasible.
  • He can design test scripts for automated testing so he doesn't necessarily have to do it himself. Automated testing would also allow him to run thousands of test cases.
Let's go to the types of testing. It is classified mainly into the following types:
  1. White box (Glass box) testing and Black box testing
  2. Alpha testing and Beta testing
White box testing
It is also known as Glass box testing. This is done mainly by programmers in the early stages of development. This testing requires the tester to understand the internal working of the program: the control flow, backend, complexity etc. Hence it is called white/glass box testing, because the tester has to look into the metaphorical box.

Black box testing
This can be done by non programmers and is mostly done at the near-completion stages of development. As opposed to white box, the tester does not need to know the internal working. He just has to compare the desired output with the obtained output for a given range of input values.

Alpha testing
This testing is done by the developers all through development. This term is mostly heard in term of apps and software. Before the release, the developers test whether it is in fine working condition and does not unexpectedly crash or have bugs.

Beta testing
Everyone has heard this term. Developers release the beta version online so that people the world over can use it and report any bugs if they occur. They may point out some things that the developers might have missed. Also, even if there are no bugs, the developers may gain valuable inputs pertaining to how to make it more efficient, how to improve the user experience etc.

So, in conclusion, designing smart ways of testing a product is also a challenge. Plus, it's fun and you get paid for nullifying your colleagues' work.
Cheers!

Why does a second compilation always take lesser time?

This question comes to the mind of every programmer and is often asked in interviews. The answer is simple.
Consider a C program. You have several functions, classes, structures etc., or modules for short. During the first compilation, each module is parsed and tokenized. This takes a longer time. After this if changes are made in any module, it is recognized by the compiler. In the next compilation, only the ones that have been changed are parsed.
Hence subsequent compilations always take lesser time than the first due only to the reduced volume of code that needs to be compiled.
Cheers!

Wednesday, April 2, 2014

Open Source Database Engines - MySQL

Okay, now we come to our and the world's favorite DBE: MySQL. It is a massively powerful and Open Source DBE. It powers giants like Facebook (remember, in 'The Social Network', Jesse Eisenberg says 'I need a dedicated Linux box running Apache with a MySQL backend'?).

The source code is available under the GNU General Public Licence, as well as under several proprietary agreements. It is a popular choice to be used in LAMP based web design.

LAMP stands for Linux, Apache, MySQL, Perl/PHP/Python. Popular examples of applications that use MySQL databases are:

  • TYPO3
  • MODx
  • Joomla
  • Wordpress
  • phpBB
  • MyBB
  • Drupal

Websites that use MySQL include:
  • Google
  • Wikipedia
  • Flickr
  • Facebook
  • Twitter
  • Youtube

MySQL Workbench is a free integrated environment that allows users to graphically alter and work on their databases. As opposed to SQLite, it is native to a machine, and its data cannot be directly copied to another database. On the other hand, it allows customized queries which results in faster searches and more effective operation.
That's a bird's eye view of MySQL folks!
Cheers!

Tuesday, April 1, 2014

Open Source Database Engines - SQLite

Like Open Source software, Open Source database engines (DBE's) are taking the IT industry by storm, for two reasons: first, because they are free, of course, and second, because they are much more powerful as opposed to traditional, paid DBMS's. The three most famous Open Source DBE's are SQLite, MongoDB and of course, everyone's favorite, MySQL. Let's discuss each one in detail.

SQLite
Contrary to popular belief, it's not pronounced S-Q-L-Lite, but rather S-Q-Lite. It supports up to 2^64 rows (wow!). It is great mainly for three reasons:

  • Connecting to an SQLite database creates a .db file, which can easily be transported from one place to another using a flash drive or e-mail (it's size is freakishly small). So you can have multiple copies of the same database on multiple systems.
  • It is a great starting point for people new to databases and their connectivity to software, websites etc.
  • It provides an easy and lightweight testing mechanism. What I mean to say is that you can easily test your website/software's database connectivity and other operations with this engine and then move to bigger and better engines like MySQL.

However, it falls short in the following aspects:
  • It supports up to 2^64 rows for all tables in total. So, for a large website like Facebook, where there are millions of users, each with hundreds of photos, it will fall laughably short.
  • It is not as efficient as MySQL in terms of query resolution when there are a large number of tables and entries.
  • It does not support joins.

So, in conclusion, SQLite: great for beginners and testers, but not so for advanced programmers and projects.
Cheers!