Friday, May 27, 2016

Array Operations

This example is a good start to have a basic discussion on data structures and algorithm design.  Understanding array operations and its limitations must be established first in order to understand other concepts in data structures.

public class ArrayOperations{

private static final int SIZE=10,ROW=2,COLUMN=3;
private static String array1[][]={{"00 ","01 ","02 "},{"10 ","11 ","12 "}};
private static String array2[]=new String[SIZE];
private static int next=0;

public static void main(String[] args){

private static void fill(){
    for(int i=0;i<SIZE;i++){
        array2[i]=new String("Student"+(i+1));

private static void delete(String key){   //slow O(n) due to sequential search
    int i=0;
    for(int j=i;j<next-1;j++){

private static void majorOrder(char order){       //slow O(n^2) due to sequential search
    int total=0;
        for(int i=0;i<ROW;i++){
            for(int j=0;j<COLUMN;j++){
               if(array1[i][j].equals("02 ")) 
                    System.out.println("It took "+total+" operations to find it");
    else if(order=='r'){
        for(int j=0;j<COLUMN;j++){
            for(int i=0;i<ROW;i++){
               if(array1[i][j].equals("02 ")) 
                    System.out.println("It took "+total+" operations to find it");
        System.out.println("Wrong major order type, only \'r\' or \'c\' are allowed");

private static void insert(String str){
    array2[next++]=new String(str);

private static String fetch(String key){  //slow O(n) due to sequential search
    int i=0;
    return new String(array2[i]); //return deepcopy object

private static void update(char oper, String str){

    else if(oper=='d'){
        System.out.println("Wrong operation was specified, use \'i\' or \'d\' for insert or delete operation");

Tuesday, May 24, 2016

Java LinkedList

There is two different ways to get the elements of a LinkedList.  Use the ListIterator method if you just need to process the elements in a sequential order.  If you need to address a specific element, it is much better to address the specific element in the list instead of getting an element and testing its field to see if you have reached the proper item.  Performance wise it will be O(n) vs. O(1) and we all know that O(1) would be a much more desirable performance goal. 

import java.util.LinkedList;
import java.util.ListIterator;
public class DebugLinkedListIterator {
public static void main(String[] args) {
        LinkedList<String> linkedList = new LinkedList<String>();
        System.out.println("ListIterator Way: ");
        ListIterator<String> listIterator = linkedList.listIterator();
        while (listIterator.hasNext()) {
        System.out.println("Loop Way: ");
        for (int i = 0; i < linkedList.size(); i++) {

For someone dealing with concept for the first time, the best way to learn is to look at a single node in the debugger and trace the value changes.  This example should help with the process.

import java.util.LinkedList;
import java.util.ListIterator;

public class DebugLinkedListIterator {
public static void main(String[] args) {

        LinkedList<String> linkedList = new LinkedList<String>();

        System.out.println("ListIterator Way: ");
        ListIterator<String> listIterator = linkedList.listIterator();

        System.out.println("Loop Way: ");

 This screen shot is a direct copy of the running debugger, so you can see where the numbers came from in the image above.

Saturday, October 31, 2015

DiceWare in Java

Java Implementation of the same algorithm you can also see here as a C++ solution.  The input file can be used from any dictionary as long as it is in the format of "index word"  tab delimited file, where the index is a 5 digit value in the range of [1-6] for each digit.

import*;         // Needed for the File and IOException
import java.util.Random;
 * This application was designed after an elev year old girl who appeared in the news starting her        * business  generating passwords for $2.
* Dictionary used in this example was generated from -
 * @author Zoltan Szabo
 * @version 1.0.0

public class DiceWare
public static void main(String[] args)throws IOException,InterruptedException{
    // Open the file.
      File file = new File("t:\\dict.txt");
      RandomAccessFile inputFile = new RandomAccessFile(file,"r");

    int index,value;
    final int NUM_WORDS = 6, DIE_SIDES=6;
    String temp="",word="",password="";
    Random rand=new Random();
    //generate random ASCII special character to add to the end of the password
    char addChar = (char)(rand.nextInt(15) + 33); 
    String[] myTuples=null;
    for (int i = 0; i < NUM_WORDS; i++){
            value = (rand.nextInt(DIE_SIDES)+1)*(int)Math.pow(10, 4)
                  + (rand.nextInt(DIE_SIDES)+ 1)*(int)Math.pow(10, 3)
                  + (rand.nextInt(DIE_SIDES)+ 1)*(int)Math.pow(10, 2)
                  + (rand.nextInt(DIE_SIDES)+ 1)*(int)Math.pow(10, 1)
                  + (rand.nextInt(DIE_SIDES)) + 1;
            if(temp!=null) myTuples=temp.split("\t");
            index = new Integer(myTuples[0]).intValue();
            if(index!=-1)word = myTuples[1];
            if (index == value){
                break;                 //stop looking if the generated value is found
            }//end of if value found
        } while (word!= null);//end of while reading the file;    //reset the file to its beginning for the new search
        if (i == 4){password += addChar; break;}
        password += '/';
        Thread.sleep(1000);                         //needs to sleep for a second to catch up with file operations
    }//end of for loop of generating 5 random words

    System.out.println("Your generated password is: " +password );

Thursday, October 29, 2015

11 Year Old's Algorithm in C++

Why would you roll dice and do this simple task manually?  Just write a code to do it for you if you'd like to use this algorithm.

//Version: 1.0.0
//Description: 11-year-old sets up cryptographically secure password business -
//To begin, a dice is rolled five times, with each numbered result documented.This then leaves you with a code, such as 12345. This result is already categorized in a dictionary, next to which is a word(which is ‘apathy’ in this instance).
//DiceYou then repeat this process six times and then band all the words together.You now have at your disposal an entirely bespoke and very long password that even the most powerful of computers will struggle to crack.
//Add a random character at the end and you’ve got an even stronger password, such as : apathy / sew / fungal / title / larch / maul / %.

//Required libraries
#include<iostream>      //cin, cout, endl
//#include<conio.h>       //_getch() that replaced the old getch()
#include<string>        //string
#include<fstream>       //ifstream
#include<Windows.h>     //Sleep(), srand(), rand()
#include<time.h>        //time()
#include<cmath>         //pow()

//Namespace specified to avoid using std:: with cin, cout, endl, ...
using namespace std;

int main(int argc, char* argv[]){
    ifstream inFile;[1]);
    int index,value;
    const int NUM_WORDS = 6, DIE_SIDES=6;
    string word,password;
    char addChar = (rand() % 15) + 33;   //generate random ASCI special character to add to the end of the password

    if (!inFile){
        cout << "Input file is missing." << endl;
        return 1;
    for (int i = 0; i < NUM_WORDS; i++){
            value = ((rand() % DIE_SIDES) + 1)*pow(10, 4)
                + ((rand() % DIE_SIDES) + 1)*pow(10, 3)
                + ((rand() % DIE_SIDES) + 1)*pow(10, 2)
                + ((rand() % DIE_SIDES) + 1)*pow(10, 1)
                + ((rand() % DIE_SIDES) + 1);
            inFile >> index >> word;
            if (index == value){
                break;                 //stop looking if the generated value is found
            }//end of if value found
        } while (inFile);//end of while reading the file
        inFile.seekg(0, ios::beg);    //reset the file to its beginning for the new search
        if (i == 5){password += addChar; break;}
        password += '/';
        Sleep(1000);                                //needs to sleep for a second to catch up with file operations
    }//end of for loop of generating 5 random words

    cout << "Your generated password is: " << password << endl;
    system("pause");           //Let the user determine when the application terminates
    return 0;                 //return integer data type to OS to indicate errorlevel

Sunday, October 4, 2015

Java, C++, and Python from USB

I need you guys to download the following large file that includes Eclipse configured with Java, C++, Python. Download it, extract it to your USB drive, label your USB as ECLIPSEIDE, under Eclipse folder double-click "run-eclipse.bat" and let me know if you can compile the "Hello World" application for all three languages. I will make a video as well to some of you to follow. This will make every student's life much easier in programming classes. 

version: 2.0.1    10/7/2015

 A quick introduction to how to use the thumb drive tools: I'll create one if requested

Before you do all this, make sure you select a fast thumb drive.  Selecting the best performing thumb drive will require for you to do a little research, but you should benefit from the process and develop your scientific methodology.

First, you should research the technology specifications for the USB technology.

USB 1.x
Released in January 1996, USB 1.0 specified data rates of 1.5 Mbit/s (Low Bandwidth or Low Speed) and 12 Mbit/s (Full Bandwidth or Full Speed). 
USB 2.0
Released in April 2000, adding a higher maximum signaling rate of 480 Mbit/s (High Speed or High Bandwidth), in addition to the USB 1.x Full Speed signaling rate of 12 Mbit/s. Due to bus access constraints, the effective throughput of the High Speed signaling rate is limited to 280 Mbit/s or 35 MB/s.
USB 3.0
USB 3.0 specification was released on 12 November 2008. USB 3.0 defines a new SuperSpeed transfer mode, with associated new backwards-compatible plugs, receptacles, and cables. SuperSpeed plugs and receptacles are identified with the logo, and, also, blue inserts in standard format receptacles.
The new SuperSpeed mode provides a data signaling rate of 5.0 Gbit/s. The payload throughput is 4 Gbit/s (due to the overhead incurred by 8b/10b encoding), and the specification considers it reasonable to achieve around 3.2 Gbit/s (0.4 GB/s or 400 MB/s), which should increase with future hardware advances. Communication is full-duplex in SuperSpeed transfer mode; earlier modes are half-duplex, arbitrated by the host.

USB 3.1

A January 2013 press release from the USB group revealed plans to update USB 3.0 to 10 Gbit/s. The group ended up creating a new USB specification, USB 3.1, which was released on 31 July 2013, replacing USB 3.0 standard. USB 3.1 specification takes over existing USB 3.0's SuperSpeed USB transfer rate, newly also referred to as USB 3.1 Gen 1, and introduces a faster transfer rate called SuperSpeed USB 10 Gbps, also referred to as USB 3.1 Gen 2, putting it on par with a single first-generation Thunderbolt channel. The new mode's logo features a caption stylized as SUPERSPEED+. The USB 3.1 standard increases the data signaling rate to 10 Gbit/s, double that of SuperSpeed USB, and reduces line encoding overhead to just 3% by changing the encoding scheme to 128b/132b. The first USB 3.1 implementation demonstrated transfer speeds of 7.2 Gbit/s.
The USB 3.1 standard is backward compatible with USB 3.0 and USB 2.0.
Source: “USB”, Accessed: 5/5/2016, 

Next, pull out the information from the text in a simplified format to serve as a reference.
Signaling rate
Transfer Rate
Effective Rate
USB 1.x
Low Bandwidth or Low Speed
1.5 Mbit/s

Full Bandwidth or Full Speed
12 Mbit/s

USB 2.0
High Speed or High Bandwidth
480 Mbit/s
280 Mbit/s or 35 MB/s
USB 3.0
SuperSpeed USB
5.0 Gbit/s
4 Gbit/s, 3.2 Gbit/s (0.4 GB/s or 400 MB/s),
USB 3.1 Gen 1
Thunderbolt channel

USB 3.1 Gen 2
SuperSpeed+ USB 
10 Gbps
7.2 Gbit/s

So, what does a USB2 vs a USB3 device look like when it is inserted into computer and what if I insert a faster device into a slower port?  Do not be afraid to as questions and explore the solutions.

Make sure you understand the ports and the different labels on your system. As you can see, in the image below, I have 2 x USB3 ports on top indicated by the SS ( SuperSpeed ) and 2 x USB2 ports below.  It is very easy to not pay attention and plug your devices into the slower ports when they are so close to each other.
Now you are ready to test your devices by creating a table to hold your measurements. ( Note: If it is easy to find the manufacturer and model of the device, go to the manufacturer website and pull the published data transfer rates for each of the device to test the documentation's reliability. )

Then, you can start testing and documenting your device speeds.
USB3 Transcend 4GB - in USB 3 port

USB3 Transcend 4GB - in USB 2 port
USB2 Transcend 2GB - in USB3 port
USB2 Transcend 2GB - in USB2 port
USB2 Richland 54MB - USB 3
USB2 Richland 54MB - USB 2
Hard drive

Draw your conclusions and decide which device to use to hold your IDE environment.  ( Note: Notice how much slower the hard drive performs in reading than a thumb drive and how much faster a hard drive is when writing data. )

Sunday, May 10, 2015

Mouse Jiggler

In some cases, you might want to keep the computer from going to sleep, hibernate, log off, turn the screen saver on.  In a digital forensics case, you would need to keep the computer alive while transporting the device to the lab or a safer environment while the system would stay in a state that will not require re-login when the password is not known.

Thus, the easiest way would be to simulate user activity to keep the system "thinking" that the user is still using the system while in transit.

Instead of creating a separate GUI, I decided to just launch notepad from the system and move the mouse while notepad is open.  If notepad is closed, the program exists.   This is an AutoIt script if you want to see it work.  Of course, you can set any executable besides notepad, but make sure you chose a small footprint file like calc.exe.

Dim $offset=50


if $checkWin = 0 then
     ShellExecute ( "C:\Windows\notepad.exe" )
     $title = WinGetTitle("")
     WinSetOnTop($title, "", 1)


while 1 and $checkWin
if $checkWin = 1 then

   MouseMove ( @DesktopWidth/2,(@DesktopHeight/2) + $offset, 10 )
  if $offset == -50  then

Saturday, May 9, 2015

GPT Partition Table Structure

GPT was designed to slowly replace the limited MBR structure.  for backward compatibility, the old MBR structure is still maintained.

The boot code is the first 446 bytes that still includes the drive serial number for backward compatibility, but it is not used with GPT partitions when mounting it in Windows.

Each one of the 16 byte partition entries will have the structure:
  Boot indicator - 1 byte
  Start head - 1 byte
  Start sector/cylinder - 2 bytes

  Partition type - 1 byte
  End head - 1 byte
  End sector/cylinder- 2 bytes
  Sectors preceding partition - 4 bytes
  Sectors in partition - 4 bytes

Following the MBR's master partition entries, the standard 0x55AA is set.

0x200 - >SIGNATURE 8 characters ( "EFI PART" )

  Revision   ( 00 00 01 00 = 1.0 )
  Headersize ( 92 bytes )
  CRC32 of header ( set this field's values to all zeros to validate the value )
  Current LBA                   ( first should be 01 00 00 00 00 00 00 00 )
  Backup LBA                    //location of the other head copy
  First usable LBA              //primary partition table last LBA+1 ( should be 22 00 00 00 00 00 00 00 )
  Last usable LBA              //secondary partition table first LBA-1
  Disk GUID 16 byte values
  Partition entries ( what will be visible in disk manager )
  Number of partitions ( 128 )
  Size of partitionEntry  ( 128 )
  CRC32 of partition array (128*128 bytes should be selected to verify)
                                                        // ensures no modifications if not used
  420 bytes reserved    //must be zeros

0x400 -> Each partition entries will have the same structure
  Partition type GUID 16 hex values    //
                                         //first one should be EFI System partition C12A7328-F81F-11D2-BA4B-00A0C93EC93B
  Partition GUID 16 hex values   ( see image below )
  Partition start LBA
  Partition end LBA
  Partition property   //
  Partition name up to 36 characters

The image below shows the GPT partition table entry and as it is used by the operating system to mount the partition ( HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices ).