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 java.io.*;         // 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.  http://www.welivesecurity.com/2015/10/29/11-year-old-sets-cryptographically-secure-password-business/
* Dictionary used in this example was generated from - http://world.std.com/~reinhold/diceware.wordlist.asc
 *
 * @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++){
        do{
            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;
            temp=inputFile.readLine();
            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
        inputFile.seek(0);    //reset the file to its beginning for the new search
        password+=word;
        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 );
    inputFile.close();
}
}

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.

http://www.welivesecurity.com/2015/10/29/11-year-old-sets-cryptographically-secure-password-business/

//Version: 1.0.0
//Description: 11-year-old sets up cryptographically secure password business - http://www.welivesecurity.com/2015/10/29/11-year-old-sets-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;
    inFile.open(argv[1]);
    int index,value;
    const int NUM_WORDS = 6, DIE_SIDES=6;
    string word,password;
    srand(time(NULL));
    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++){
        do{
            srand(time(NULL));
            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.clear();
        inFile.seekg(0, ios::beg);    //reset the file to its beginning for the new search
        password.append(word);
        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;
    inFile.close();
    system("pause");           //Let the user determine when the application terminates
   //_getch();
    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
https://drive.google.com/file/d/0ByrtM1fcMgt6bUs0SXFyVXVWU2M/view?usp=sharing

 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, https://en.wikipedia.org/wiki/USB 

Next, pull out the information from the text in a simplified format to serve as a reference.
Technology
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 PQI 1GB - USB 3
USB2 PQI 1GB - USB 2
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. )