Wednesday, 20 November 2013

Nickispy

Nickispy is a family of Trojan horse viruses that targets smartphones powered by the Android operating system.  The most recent strain of Nickispy, Nickispy.C, masquerades as the Google+ (Google Plus) service in an attempt to dupe Android OS users into installing the malware.  Nickispy.C attempts to trick users into installing a third-party app called Google++ (notice the use of two "plus" signs rather than one), and it even uses the same icon as the real Google+ service. 
Users installing Google++ provide Nickispy with complete access to their smartphone's text messages and call logs, and the malware can even record phone calls as well as GPS position history.   Nickispy can additionally secretly answer calls on its own and send a user's private information to a remote site without the user's knowledge.
While many of Nickispy’s malicious capabilities affect all Android smartphones, the malware's ability to surreptitiously intercept calls only affects Android smartphones running version 2.2 or earlier.  Smartphones running version 2.3 ("Gingerbread") or later are protected from this as a result of the modify_phone_state permission being disabled.

The Difference Between Encoding, Encryption, and Hashing

Encoding is often confused with encryption and hashing. They are not the same. But before I go into the differences, I'll first mention the similarities:
  1. All three transform data into another format.
  2. Both encoding and encryption are reversible, unlike hashing.
And now the differences:

Encoding

ascii
The purpose of encoding is to transform data so that it can be properly (and safely) consumed by a different type of system, e.g. binary data being sent over email, or viewing special characters on a web page. The goal is not to keep information secret, but rather to ensure that it's able to be properly consumed.
Encoding transforms data into another format using a scheme that is publicly available so that it can easily be reversed. It does not require a key as the only thing required to decode it is the algorithm that was used to encode it.
Examples: ASCIIUnicodeURL EncodingBase64

Encryption

ciphertext
The purpose of encryption is to transform data in order to keep it secret from others, e.g. sending someone a secret letter that only they should be able to read, or securely sending a password over the Internet. Rather than focusing on usability, the goal is to ensure the data cannot be consumed by anyone other than the intended recipient(s).
Encryption transforms data into another format in such a way that only specific individual(s) can reverse the transformation. It uses a key, which is kept secret, in conjunction with the plaintext and the algorithm, in order to perform the encryption operation. As such, the ciphertext, algorithm, and key are all required to return to the plaintext.
Examples: AESBlowfishRSA

Hashing

sha512
Hashing serves the purpose of ensuring integrity, i.e. making it so that if something is changed you can know that it's changed. Technically, hashing takes arbitrary input and produce a fixed-length string that has the following attributes:
  1. The same input will always produce the same output.
  2. Multiple disparate inputs should not produce the same output.
  3. It should not be possible to go from the output to the input.
  4. Any modification of a given input should result in drastic change to the hash.
Hashing is used in conjunction with authentication to produce strong evidence that a given message has not been modified. This is accomplished by taking a given input, hashing it, and then encrypting the sent hash with the recipient's public key.
When the recipient opens the message with their private key they then hash the message themselves and compare it to the hash that was given encrypted by the sender. If they match it is an unmodified message.

Summary

  • Encoding is for maintaining data usability and can be reversed by employing the same algorithm that encoded the content, i.e. no key is used.
  • Encryption is for maintaining data confidentiality and requires the use of a key (kept secret) in order to return to plaintext.
  • Hashing is for validating the integrity of content by detecting all modification thereof via obvious changes to the hash output.

Hashing

Hashing is the transformation of a string of characters into a usually shorter fixed-length value or key that represents the original string. Hashing is used to index and retrieve items in a database because it is faster to find the item using the shorter hashed key than to find it using the original value. It is also used in many encryption algorithms.
As a simple example of the using of hashing in databases, a group of people could be arranged in a database like this:
Abernathy, Sara Epperdingle, Roscoe Moore, Wilfred Smith, David (and many more sorted into alphabetical order)
Each of these names would be the key in the database for that person's data. A database search mechanism would first have to start looking character-by-character across the name for matches until it found the match (or ruled the other entries out). But if each of the names were hashed, it might be possible (depending on the number of names in the database) to generate a unique four-digit key for each name. For example:
7864 Abernathy, Sara 9802 Epperdingle, Roscoe 1990 Moore, Wilfred 8822 Smith, David (and so forth)
A search for any name would first consist of computing the hash value (using the same hash function used to store the item) and then comparing for a match using that value. It would, in general, be much faster to find a match across four digits, each having only 10 possibilities, than across an unpredictable value length where each character had 26 possibilities.
The hashing algorithm is called the hash function-- probably the term is derived from the idea that the resulting hash value can be thought of as a "mixed up" version of the represented value. 
In addition to faster data retrieval, hashing is also used to encrypt and decrypt digital signatures (used to authenticate message senders and receivers). The digital signature is transformed with the hash function and then both the hashed value (known as a message-digest) and the signature are sent in separate transmissions to the receiver. Using the same hash function as the sender, the receiver derives a message-digest from the signature and compares it with the message-digest it also received. (They should be the same.) 
The hash function is used to index the original value or key and then used later each time the data associated with the value or key is to be retrieved. Thus, hashing is always a one-way operation. There's no need to "reverse engineer" the hash function by analyzing the hashed values. In fact, the ideal hash function can't be derived by such analysis. A good hash function also should not produce the same hash value from two different inputs. If it does, this is known as a collision. A hash function that offers an extremely low risk of collision may be considered acceptable.
Here are some relatively simple hash functions that have been used:
  • Division-remainder method: The size of the number of items in the table is estimated. That number is then used as a divisor into each original value or key to extract a quotient and a remainder. The remainder is the hashed value. (Since this method is liable to produce a number of collisions, any search mechanism would have to be able to recognize a collision and offer an alternate search mechanism.)
  • Folding method: This method divides the original value (digits in this case) into several parts, adds the parts together, and then uses the last four digits (or some other arbitrary number of digits that will work ) as the hashed value or key.
  • Radix transformation method: Where the value or key is digital, the number base (or radix) can be changed resulting in a different sequence of digits. (For example, a decimal numbered key could be transformed into a hexadecimal numbered key.) High-order digits could be discarded to fit a hash value of uniform length.
  • Digit rearrangement method: This is simply taking part of the original value or key such as digits in positions 3 through 6, reversing their order, and then using that sequence of digits as the hash value or key.
There are several well-known hash functions used in cryptography. These include the message-digest hash functions MD2MD4, and MD5, used for hashing digital signatures into a shorter value called a message-digest, and the Secure Hash Algorithm (SHA), a standard algorithm, that makes a larger (60-bit) message digest and is similar to MD4. A hash function that works well for database storage and retrieval, however, might not work as for cryptographic or error-checking purposes.

Monday, 18 November 2013

Transparency in JAVA3D

This lesson will show one way to use a Transparent texture in Java3D 

Since I wanted to use fire in my program, so I used a fire image, and made the background transparent in Photoshop. 
But if you applied the transparent texture the same way as regular textures, you will not get the effect you want. 

In order to get the Transparent effect, you must alter the polygon's Appearance
	Appearance fireApp = new Appearance ();
Create an instance of TransparencyAttributes
	TransparencyAttributes ta = new TransparencyAttributes();
Choose a Transparency Mode type (NONE, FASTEST, NICEST, SCREEN_DOOR, or BLENDED), in this case I use BLENDED
	ta.setTransparencyMode (ta.BLENDED);
Set the Transparency, from 0.0 to 1.0, where 0.0 is opaque , and 1.0 is transparent. I used 0.5 in this sample.
	ta.setTransparency (0.5f);
Then apply the TransparencyAttributes to the Appearance
	fireApp.setTransparencyAttributes (ta);


I placed a green polygon behind the fire polygon so the transparency effects would be evident. 
Without TransparencyAttributesWith TransparencyAttributes

Simple Polygon Creation


Since you can't use ColorCube's for all of your polygons, 
the next step is to learn how to create your own shapes. 

First create an Appearance 
    Appearance polygon1Appearance = new Appearance();

Lets make a simple Rectangle:
in this example, the rectangle will have height of 3m and width of 2m, 
with coordinates (0,0,0), (2,0,0), (2,3,0) and (0,3,0) 
(notice the veritices are in counter-clockwise order) 

 QuadArray polygon1 = new QuadArray (4, QuadArray.COORDINATES);
     polygon1.setCoordinate (0, new Point3f (0f, 0f, 0f));
     polygon1.setCoordinate (1, new Point3f (2f, 0f, 0f));
     polygon1.setCoordinate (2, new Point3f (2f, 3f, 0f));
     polygon1.setCoordinate (3, new Point3f (0f, 3f, 0f));

Then add the Polygon to the Scene Graph using that Appearance (assuming objRoot is your SceneGraph name) 
     objRoot.addChild(new Shape3D(polygon1,polygon1Appearance));

 

Note: If you do not put your verticies in counter-clockwise order, they will not be seen. 

Lighting QuadArrays

QuadArrays as created in previous tutorials, are not effected by lighting effects. To make the QuadArrays effected by light, the normals need to be specified.

To start, lets use the Material and lighting from the previous tutorial.
 Appearance app = new Appearance();
 Material mat = new Material();
 mat.setAmbientColor(new Color3f(0.0f,0.0f,1.0f));
 mat.setDiffuseColor(new Color3f(0.7f,0.7f,0.7f));
 mat.setSpecularColor(new Color3f(0.7f,0.7f,0.7f));
 app.setMaterial(mat);     

 BoundingSphere bounds = new BoundingSphere (new Point3d (0, 0.0, 5), 5.0);
     Color3f lightColor = new Color3f (1.0f, 1.0f, 1.0f);
     Vector3f light1Direction = new Vector3f (0.0f, 0.0f, -1f);
     DirectionalLight light1  = new DirectionalLight (lightColor, light1Direction);
     light1.setInfluencingBounds (bounds);
     objRoot.addChild (light1);

     AmbientLight ambientLightNode = new AmbientLight (lightColor);
     ambientLightNode.setInfluencingBounds (bounds);
     objRoot.addChild (ambientLightNode);


Next we will create a QuadArray with a new parameter QuadArray.NORMALS which will allow us to specify the Normal at each vertex.
 QuadArray polygon1 = new QuadArray (4, QuadArray.COORDINATES | QuadArray.NORMALS);
 polygon1.setCoordinate(0, new Point3f (-3f,-1f,0f));
 polygon1.setCoordinate(1, new Point3f (3f,-1f,0f));
 polygon1.setCoordinate(2, new Point3f (3f,1f,0f));
 polygon1.setCoordinate(3, new Point3f (-3f,1f,0f));
 objRoot.addChild(new Shape3D(polygon1,app);

In this example, each vertex on the polygon has the same normal, so we'll create a Vector3f for the normal and set it in the QuadArray
 Vector3f polygon1Normal = new Vector3f(0f,0f,1f);
 polygon1.setNormal(0,polygonNormal);
 polygon1.setNormal(1,polygonNormal);
 polygon1.setNormal(2,polygonNormal);
 polygon1.setNormal(3,polygonNormal);

The 2 Screenshots show the polygon with the Material, and one without material (but with the ColoringAttributes used)
With MaterialWithout Material

Tuesday, 5 November 2013

How does this regex find triangular numbers?

 1 = 1
 3 = 1 + 2
 6 = 1 + 2 + 3
10 = 1 + 2 + 3 + 4
15 = 1 + 2 + 3 + 4 + 5
There are many ways to check if a number is triangular. There's this interesting technique that uses regular expressions as follows:
  • Given n, we first create a string of length n filled with the same character
  • We then match this string against the pattern ^(\1.|^.)+$
    • n is triangular if and only if this pattern matches the string
Here are some snippets to show that this works in several languages:

PHP (on ideone.com)

$r = '/^(\1.|^.)+$/';

foreach (range(0,50) as $n) {
  if (preg_match($r, str_repeat('o', $n))) {
     print("$n ");
  }
}

Java (on ideone.com)

for (int n = 0; n <= 50; n++) {
    String s = new String(new char[n]);
    if (s.matches("(\\1.|^.)+")) {
        System.out.print(n + " ");
    }
}

C# (on ideone.com)

Regex r = new Regex(@"^(\1.|^.)+$");

for (int n = 0; n <= 50; n++) {
    if (r.IsMatch("".PadLeft(n))) {
       Console.Write("{0} ", n);
    }
}