REThink 2015 Day 15, Day 16, and Day 17- Super Busy

I didn’t get a chance to blog the last couple of days because a lot has been going on here with the project.

Monday Morning- We had our typical “Progress Report” session, in which we go around and share what we have accomplished, and what we need to accomplish. We then spent some time talking about cryptography. It’s super interesting how it is a cat and mouse game, where the math is essentially made more difficult once computers catch up in their processing capabilities. This worksheet was a blast to complete. and you can encode/decode a message:

Monday Afternoon- Between Kathy, me, and Google, we got my program working! It can now classify cell parts based on HSV. This will allow me to look at the 40 images that I have to be able to look at the color space of the prepared H&E slides. I also made the GUI more Drexel (Blue & Gold)

Tuesday-  I worked on classifying pictures all day. There’s not much to report. I did send the images to Mark to analyze to make sure everything was being output correctly, and received the green light.

Wednesday- We spent the morning with Bill, talking about all kinds of computer science processes. We first signed up for Bitbucket accounts, and Bill showed us how to use the service. It’s like Github or even dropbox. My repository wouldn’t upload as my image files are huge, and even though I have the academic version, it was still too big.

We then did some socket programming. Bill’s Instructions:

Part 0 – Downloading the Required Files

  1. Download and
  2. The objective of the following lesson is to give students experience in:
    1. Protocol design, implementation
    2. Modification or augmentation of protocol layers
    3. Algorithm implementation
    4. The RSA Cryptosystem
    5. Importing and using Java libraries
    6. Optionally: Key exchange algorithms, Threading, and Message signatures
    7. Optionally, if running on a wireless network or a wired hub, use Wireshark to “intercept” messages across the wire.

Part 1 – Create Eclipse Project for MiniRSA

  1. Under Eclipse – go to File -> Import, and select “Existing Projects into Workspace” as below.
  2. Unzip the project code, and in Eclipse, select “Select Root Directory” and browse to the “RSA Java with Library” directory as the root.
  3. Select the RSA Project and click Finish

Part 2 – Including the RSAMath Library jar

  1. Right click on the project and click Properties
  2. Click on the “Java Build Path” setting to import the jar, and bring up the Libraries tab across the top.
  3. Click “Add External JARs” and select the rsamath.jar file inside the “RSA Java Library” directory, unzipped as part of your archive.


Part 3 – Checking out the MiniRSA Algorithm

As discussed, students will implement (and you are given!) the RSA algorithm.  There are 5 files included in the cs4hs11.rsa package, and they are described here in the order in which you should write and run them:

  • java – this file contains the entire RSA algorithm, from start to finish, and is suitable for describing the algorithm in general terms.
  • java – this class prompts the user for primes (users can enter 2 and 3 to compute the 2nd and 3rd prime number, so they don’t have to come up with their own primes! Note that large numbers are clearly stronger, but are also slower to compute here and crack, so numbers > 10 and < 100 are generally appropriate).
  • java – this class prompts the user for a friend’s encryption key (E, C), and a string, and returns the encrypted values to share with a friend.
  • java – this class is run by a student after receiving an encrypted message from a friend, and prompts the user for the decryption key (D, C), and each encrypted value before decrypting them to the original message.
  • java – this class prompts the user for a friend’s encryption key (E, C), and brute-force determines the decryption key (D, C) associated with it. This is good for discussing how encryption is hiding in plain sight, protecting information with keys, not algorithms.

Within the RSA Java Library directory, you are given a jar file and a javadoc directory, both of which are suitable for giving to students.  The nice thing here is that they can get some practice importing external jar files and using simple interfaces as published in the JavaDoc.  If you want to trade this for more programming practice and algorithm implementation, by all means feel free to have students implement the functions inside the library.  They are:

Part 4  – Running MiniRSA

  1. To run MiniRSA, first generate a public/private key pair by running (right click on the file, and select Run As -> Java Application).
  2. Write your Public Key on the board or Google Doc, and privately save your Private Key. Here, my public key is (451, 2623) and the private key is (1531, 2623).
  3. Have a friend encrypt a message to you by running with your public key, and store the encrypted numbers into the Google Doc (or on the board).
  4. Once you have received a message, decrypt it in similar fashion by running with your private key.
  5. Now, let’s crack our friend’s key by running with the public key found in the Google Doc:


Part 5 – Encrypted Chat Application

  1. You are given, as before, the full solution to work with. However, students versions may vary widely here depending on the “protocol” that they choose with you in the classroom.  The important thing is that they:
    1. Decide on a protocol
    2. Implement a simple chat client and server based on that protocol
    3. Optionally add threads to the sending and receiving behaviors so that they can chat “in parallel” and not have to wait for a message to arrive before sending. (this can be provided for students as well so they can appreciate a more fully functional chat app!).
    4. Implement the RSA algorithm as above
    5. Generate keys and incorporate encryption into the sending and receiving of their messages
    6. Optionally pass the keys to one another at startup – but then, this would be insecure! This could create discussion about key exchange algorithms for more advanced students (i.e., perhaps they could research this and do a short presentation).
  2. As before, unzip the contents of and import this project directory into your workspace. You will find several files:
  • java – The chat server creates a server socket, listens for a friend to connect via a chat client, spawns threads to send and receive encrypted messages. It takes in 6 parameters: the port number to listen on, the friend’s public key E, the friend’s public key modulus C, your private key D, your private key modulus C, and a 1 or 0 to enable or disable verbose debugging messages.
  • java – Similarly, the chat client takes in 7 parameters, and differs only in the first, which is the IP address of the server peer to connect to. Otherwise, it also takes the port to connect to, public and private key information, and a 1 or 0 for debug messages.
  • java – This class serves double-duty: it takes in a DataStream (either in or out) and, depending on which one it was given, reads from the socket or writes to the socket. So it is a threaded chat sender OR a threaded chat receiver (the main program will create two of these).  This one already includes encryption and decryption support.
  • java – This is the key generator class from the MiniRSA package
  • java – This contains the RSAMath library functionality formerly provided as a jar package.
  1. Create a run configuration for the server by right clicking on, and selecting Run As->Run Configurations.
  2. Click the Arguments tab and provide the arguments as described above, using the public and private key information determined from the MiniRSA activity:
  3. A friend can do the same for RSAClient; give your friend your IP address and port number by running ipconfig from a command prompt (but don’t exchange private keys!):
  4. Set the debug flag to 1 to show that it really is sending encrypted traffic across the network:


Part 6 – Interception with Wireshark

This part can be tricky because most wired networks are on switches or routers, as opposed to hubs, so traffic is generally not repeated to all hosts.  Therefore, it may be hard to capture traffic from all students.  Wireless cards that support it can be configured in Promiscuous mode, and Wireshark can be set up to capture the traffic by going to Capture -> Interfaces, and clicking Start next to your interface (here, mine was Microsoft).

And filtering on tcp.port == your_port_number (for the chat application).  Mine was 12345

Note also that, if using the localhost interface, you should actually type in your local IP address and not localhost in the Chat program.  This is because Wireshark does not capture localhost traffic generally.  One can bypass this by forcing a route for local IP  traffic, by opening a command line as Administrator and entering the following Route command:

(note the corresponding route delete afterwards which should be run after the lesson).  The command only needs to be run once.  You will notice TCP traffic generated when you send or receive a message.  Here is mine (click on the packet, then expand the Data part in the middle of the screen).

Notice the last bytes are 98, 97, 10684, which are the encrypted bytes that were sent.  This can be fed to the RSACracker from earlier, along with the friend’s public key, to decrypt other messages that the friend receives.

Socket programming was pretty interesting. I spent the afternoon going through and classifying my MATLAB (or I guess, Imagescope) H&E slides.