Jump to content


Check out our Community Blogs

TALucas

Member Since 02 Dec 2008
Offline Last Active Oct 31 2018 05:24 AM
-----

#641200 How do you draw a simple death star in a space background?

Posted by TALucas on 08 October 2012 - 02:29 PM


I'm currently working on a map for the EVE universe where I load all of the star location data and draw them to a window. I wont give you the details, but I'll get you pointed in the right direction.


Can you elaborate on this?


Ya, it's one of those side projects that seems to never get done. I've played EVE off and on for a couple years, and had downloaded their star data (EVE data dump), and have been working on a java map where you can load the universe, solar systems, and store info about the systems. You can even add your own fleets and POSes. I plan to have the final version web enabled so that groups can plan fleet moves in real time.

However, I'm currently not playing EVE...I've let my account lapse. I'm currently playing WOW. So the map is on hold again. :-) Below are a few of the screen shots.

This is the EVE universe.

Posted Image

You can right click on a star in the Universe map and get to the solar system map. Below, the blue markers are friendly fleets, and the red are enemy.

Posted Image
  • 1


#639388 what topic to choose in computer science

Posted by TALucas on 21 September 2012 - 05:03 AM

To be honest, either path would open up a host of similar jobs. Most companies looking for IT professionals hire individuals with a general skillset, and then train them to fill their needs. For example, I learned java in university and my first job was in COBOL, and now I program in .NET for the same company.

My Computer Science degree told them I had the capacity to learn IT STUFF....from there, they molded my talents to benefit the company.

When choosing a career path...always choose what you enjoy.
  • 1


#637291 Which Is Your Favorite Movie?

Posted by TALucas on 30 August 2012 - 06:41 AM

Empire Strikes Back
Return of the King
The Matrix
  • 1


#585060 java I/O BINARY FILES

Posted by TALucas on 24 December 2010 - 08:29 PM

I've created a very similar program that will encrypt any type of file.... check out my tutorial here on the forums. My program opens the files in binary mode, then rewrites them. It could be modified to copy a file.

http://forum.codecal...encryption.html Tutorial
  • 1


#438042 Encryption

Posted by TALucas on 01 March 2009 - 07:41 PM

Well.....I went ahead and created a GUI for the Encrypt program, and also created an executable JAR file too.

Attached Files


  • 1


#437845 Encryption

Posted by TALucas on 28 February 2009 - 08:25 PM

I’ve been exposed to programming most of my life. My first computer was a Commodore 16 with no hard drive and a whopping 16 kilobytes of RAM…boy how things have changed. I gained a real interest in programming about 15 years ago, about the same time Visual Basic 3 was released. I remember stumbling across a program that could encrypt files. I studied how it worked, played around with it a bit, but finally set it aside and forgot about it. A few years ago while studying Java in college; I decided to recreate it from memory. It’s a very basic version, and perhaps one of these days I’ll wrap a nice GUI around it, but for now it is what it is.

The main purpose of this tutorial is to demonstrate how encryption works, but I’ll also touch on other topics like binary file I-O, random number generation, and logical operators. Here's the full source:
/*  Author		TA Lucas
    Purpose		to password encrypt any file
    Program		encrypt.java
*/

// included files
import java.io.*;
import java.util.Random;

public class encrypt
{
	//seed random number
	private static Random generator = new Random(5);
	
	public static void main(String[]args) throws Exception
	{
		InputStreamReader keyReader = new InputStreamReader(System.in);
		BufferedReader keyInput = new BufferedReader(keyReader);
		
		//Get the full path and filename for input file
		System.out.print("Input filename: ");
		String inputFilePath = keyInput.readLine();;
		File inFile = new File(inputFilePath);
		
		if (inFile.exists()){
			FileInputStream reader = new FileInputStream(inFile);
			
			// variables
			String passWord = "";
			int passWordLength = 0;
			String EncryptedFilePath = ""; 
			int originalByte = 0;
			int encryptedByte = 0;
			int mask = 0;
			int counter = 0;			
		
		
		    //Get the full path and filename for output file
			System.out.print("Output filename: ");
			EncryptedFilePath = keyInput.readLine();
			FileOutputStream writer = new FileOutputStream(EncryptedFilePath);

		
			// prompt user for password
			System.out.print("Please enter a password: ");
			passWord = keyInput.readLine();
			passWordLength = passWord.length();


			// loop through each byte of the input file
			for (int i = 0; i<inFile.length(); i++)
			{
				originalByte = reader.read();          // read original byte
		 		mask = loopNum((int)passWord.charAt(counter)); // generate mask by password
		 		encryptedByte = mask ^ originalByte;	// encrypt byte with mask
				writer.write(encryptedByte);			// write encrypted byte
				
				// after password is looped it is reset and done again.
				counter++;
				if(counter >= passWordLength)
				{
					counter=0;
				}
				
			}
			writer.close();	
		}
		else
		{
			System.out.println("Source file was not found.");
		}	
	}// end main
	

	//////////////////////////////////////////////////////////////////////
	// accepts nothing		just generates numbers loops				//
	// returns nothing		for mask									//
	//////////////////////////////////////////////////////////////////////
	public static int loopNum(int loopEnd)
	{
		for (int i = 0; i<= loopEnd; i++)
		{
			 generator.nextInt(256);
		}
		return generator.nextInt(256);
	}// end loopNum
}// end class

Below I'll take a look at the various parts of this program.
/*  Author		TA Lucas
    Purpose		to password encrypt any file
    Program		encrypt.java
*/

// included files
import java.io.*;
import java.util.Random;

I always start my code with a comment header that gives just a brief description of what the file does. Take the time to document your code properly...it will save you time later, and its a good habit to develop. I also included the io and random classes.

public class encrypt
{
	//seed random number
	private static Random generator = new Random(5);
I've used the random class to create a random number. Java uses an algorithm to create its random numbers. The way it works, a number is passed to the constructor, and based off of that number Java will produce a set of numbers. If you use the same seed, it will always produce the exact set of numbers. If I seed it with 5 and then create 100,000 numbers then the next time I execute the program...if I've left the code the same then it will produce those same 100,000 numbers in the exact same order.

If you don't give the constructor a value, then it will use the system time as a seed....which will give you an almost random value. However for our purposes, we want it to generate the exact set every time.

public static void main(String[]args) throws Exception
	{
		InputStreamReader keyReader = new InputStreamReader(System.in);
		BufferedReader keyInput = new BufferedReader(keyReader);
		
		//Get the full path and filename for input file
		System.out.print("Input filename: ");
		String inputFilePath = keyInput.readLine();;
		File inFile = new File(inputFilePath);
		
		if (inFile.exists()){
			FileInputStream reader = new FileInputStream(inFile);
			
			// variables
			String passWord = "";
			int passWordLength = 0;
			String EncryptedFilePath = ""; 
			int originalByte = 0;
			int encryptedByte = 0;
			int mask = 0;
			int counter = 0;

I won't spend a lot of time on this section, but there are a couple things that need a bit of explaining. The InputStreamReader and BufferedReader are used to read in keyboard input....our filename (need to include path).

I chose to use the FileInputStream because it opens the file in binary format. This is important because you'll need to do some bit operations a bit (no pun intended) later.

//Get the full path and filename for output file
			System.out.print("Output filename: ");
			EncryptedFilePath = keyInput.readLine();
			FileOutputStream writer = new FileOutputStream(EncryptedFilePath);

		
			// prompt user for password
			System.out.print("Please enter a password: ");
			passWord = keyInput.readLine();
			passWordLength = passWord.length();

In this part we open the output file in binary also, and then prompt for a password that is used to encrypt the file.

// loop through each byte of the input file
			for (int i = 0; i<inFile.length(); i++)
			{
				originalByte = reader.read();          // read original byte
		 		mask = loopNum((int)passWord.charAt(counter)); // generate mask by password
		 		encryptedByte = mask ^ originalByte;	// encrypt byte with mask
				writer.write(encryptedByte);			// write encrypted byte
				
				// after password is looped it is reset and done again.
				counter++;
				if(counter >= passWordLength)
				{
					counter=0;
				}
				
			}

This bit of code is the core of the program. The loop will read a byte from the input file create an encrypted byte based upon the password, and then write that byte to the output file....and continue through the entire file.

originalByte = reader.read();
This line will read in a byte of data from the input file. A byte is 8 bits, and the first read may look something like this: {01101001 010010101 10100001}

mask = loopNum((int)passWord.charAt(counter));
To make it simple the mask is a random number from 0 - 255. This line of code calls the loopNum function which returns an integer within that range, but it uses a character of the password to determine which random number it returns. The counter is an integer used to loop through each letter of the password.

Let's say our password is apple, and we are on the first itteration of the loop. It has already read in byte: 01101001, and is now calling the loopNum function with the value (int)passWord.charAt(counter)). The first character of the password is a lower case 'a', and if you cast it to an integer you get the number 97...so basically we pass 97 to the loopNum function. LoopNum will then generate 97 random numbers, toss them to the side, and then return the 98th, which will be an integer between 0 and 255, and that will be our mask.

There are 256 possible number between 0 - 255, and that is important because that is also the largest number possible with a byte. The binary number 11111111 is equal to the decimal number 255. So the number returned is always the size of one byte....our mask is a random number the size of a byte.

Now lets say that loopNum returned the number decimal number 133 which is the binary number 10000101. So now we have:

01101001 - original byte
10000101 - mask

encryptedByte = mask ^ originalByte;
This line will create the encrypted byte by using the XOR operator. The Exclusive or will compare bit for bit...so you remember those truth tables, well here's the one for Xor: 1 Xor 1 = 0, 1 Xor 0 = 1, 0 Xor 1 = 1, and 0 Xor 0 = 0.

01101001 - original byte
10000101 - mask
____________________________XOR
11101100 - encrypted byte

So how does this work? Well...when you run the encrypted file back through the same program, it will read in the encrypted byte, and when Xor'd with the same mask, it will produce the original byte. So the fact that the Xor acts like a switch that will flip the bits back to the original, and that java will produce the exact random numbers each time is what makes this possible. Check it out:

11101100 - encrypted byte
10000101 - mask
____________________________XOR
01101001 - original byte


Have fun, and let me know what you think...take the code and play with it a bit. like i said, this program is pretty simple, and does not have a lot of error checking built in. For my testing, I usually encrypt a file on the C drive so I don't have to worry about file paths. Something like c:\inputfile.txt c:\outputfile.txt.
  • 2


#416011 Creating an Executable Jar File

Posted by TALucas on 14 December 2008 - 07:35 PM

This is my first attempt at a tutorial here at CC, so if it's out of place, or I'm out of place, just let me know...;)

A Java Archive file (Jar) is a compressed file based on the ZIP format. Jar files can contain many files and folders, but most often hold Java .class files. This format helps keep all the files in one place, and reduce the overall size of a project. Another very useful function of Jar files is that some of them can be executed. The purpose of this tutorial is to explain how to create an executable Jar file.

First I’ll make the assumption that you have downloaded and installed the Java SE Development Kit (JDK), and have also set up the PATH and CLASSPATH environment variables. If you can run and compile .java programs from the command line, then you’re set to go.

First thing you need is a Java source file. A simple program that just gets and sends data to the command prompt will work as long as you run it from the command-line, but you will not be able to see any output if you just double click on the Jar file. So, in this tutorial I will use an example that creates a window using JFrame.

Step 1. Create a folder called test and put your Java source file in it. For my example I’ve created a simple clock application that just counts the number of days since something has happened…the number of days since you’ve quit a bad habit, the number of days your website has been up, for me it’s the number of days since I joined Code Call…13 days at the writing of this tutorial.

Posted Image

You can use the Clock.java example if you like or substitute one of your own. Go ahead and compile the source. You should now have a test folder that contains the source file, and two class files.

Posted Image

Step 2. Create a manifest file…I’ll call mine Clock.MF. A manifest is basically a file that contains information about the files packaged inside the Jar file. You can create yours using a text editor, just give it a .MF extension. Here’s what needs to go in this manifest file:

Manifest-Version: 1.0
Main-Class: Clock
Created-By: 1.2 (Sun Microsystems Inc.)

The first line tells us that this file conforms to 1.0 of the manifest specification. The second line tells which class inside the Jar file contains the “main” function. And the last line defines the version and the vendor of the java implementation on top of which this manifest file is generated.

Step 3. Create the Jar file using the jar command. In the example below (jar) is the name of the executable you call to create the Jar file. The jar command has a number of options…I used four of them (c –create the jar file, v –generates verbose output to the screen during file creation, f –specifies the file to be created, and m –indicates the manifest file to be used) After the options parameter comes the name of the jar file to be created (clock.jar), followed by the name of the manifest file to use (Clock.MF). The (*) wild card indicates to include all files in that directory. If you wanted you could use *.class to only include class files. Here's the command:

jar cvfm Clock.jar Clock.MF *

Your test folder should now contain five files…one of them being the new clock.jar file. You should be able to double click on the clock.jar, and it will execute. You can also execute this code from the command line by typing (java -jar clock.jar).

Posted Image

Attached Files


  • 2


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download