Showing posts with label Technology. Show all posts
Showing posts with label Technology. Show all posts

Thursday, August 28, 2008

World's longest motorcycle

The world's longest motorcycle is created by Oleg, "Leshij" Rogov of Tver, a small town near Moscow, Russia. After two years of planning and development, culminating Oleg saw his great effort.. The motorcycle measured a total of 31 feet 4 inches long, that is 9 meters 57 cm. With that size can carry 16 passengers, including the pilot.

Wednesday, August 27, 2008

Monday, August 11, 2008

Elgamal Encryption in java

package elgamal;

import java.util.Arrays;
import java.util.Vector;
import java.util.*;

/*
* Created on Mar 24, 2008
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/

/**
* @author suranga kulathunga
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class ElGamal {

/**
*
*/
public ElGamal() {
super();
// TODO Auto-generated constructor stub
}

public static void main(String[] args) {
Vector primeVector = new Vector();
Generator generator = new Generator();
int primeNumber = 0;
while (primeVector.isEmpty()) {
primeNumber = generator.createPrimeNumber(1000, 10000);
System.out.println("--------Prime Number--------");
System.out.println("Prime Number : " + primeNumber);
//Vector pnVector = generator.createPrimeNumberVector(1000, 2357);
primeVector = generator.createGenerator(primeNumber);
}
generator.initializeGenerator(Integer.parseInt(primeVector.elementAt(0)
.toString()), primeNumber);

System.out.println("--------Generator--------");
System.out.println("Generator : " + generator.getGenerator());
System.out.println("Prime Number : " + generator.getPrimeNumber());

// Create Encryption and Decryption keys
Keys keys = new Keys();
keys.initializeKeys(generator.getGenerator(), generator
.getPrimeNumber());
EncryptionKey encryptionKey = keys.getEncryptionKey();
DecryptionKey decryptionKey = keys.getDecryptionKey();

System.out.println("--------EncryptionKey--------");
System.out.println("Public Key : " + encryptionKey.getPublicKey());
System.out.println("Generator :" + encryptionKey.getGenerator());
System.out.println("Prime Number : " + encryptionKey.getPrimeNumber());

System.out.println("--------DecryptionKey--------");
System.out.println("Private Key : " + decryptionKey.getPrivateKey());
System.out.println("Prime Number : " + decryptionKey.getPrimeNumber());

// Initialize Encryption
String encryptionMessage = "suranga kulathunga";
Encryption encryption = new Encryption();
encryption.initializeEncryption(encryptionKey, encryptionMessage);
encryption.encrypt(encryptionMessage);
System.out.println("--------Encryption--------");
System.out.println("Encryption Message :" + encryptionMessage);
System.out.println("CipherTextOne : " + encryption.getCipherTextOne());
System.out.print("CipherTextTwo : ");
for (int i = 0; i < encryption.getCipherTextTwoArray().length; i++) {
System.out.print(encryption.getCipherTextTwoArray()[i] + " ");
}
System.out.println("");

// Initialize Decryption
Decryption decryption = new Decryption();
decryption.initializeDecryption(decryptionKey);
int[] mes = decryption.decrypt(encryption.getCipherTextOne(),
encryption.getCipherTextTwoArray());
System.out.println("--------Decryption--------");
String message = "";
int ASCII = 0;
System.out.print("Decryption Message :");
for (int i = 0; i < mes.length; i++) {
message += "" + ((char) mes[i]);
System.out.print(mes[i] + " ");
}
System.out.println("");

decryption.setMessage(message);
System.out.println("Final Message : " + decryption.getMessage());

}

}




package elgamal;
/*
* Created on Mar 31, 2008
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/

/**
* @author suranga kulathunga
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class Decryption {

private DecryptionKey decryptionKey = null;
private String message ="";
/**
*
*/
public Decryption() {
super();
// TODO Auto-generated constructor stub
}
/*
* Inverse of b mod a
*/
public long FindInverse(long a, long b){
long q =1;
long temp = 0;
long r = 1;
long sign = 1;
long store = a;
long s =0;

while(b!=0){
q=a/b;
temp = r;
r = temp*q+s;
s= temp;
temp = b;
b = a- q*temp;
a = temp;
sign =- sign;

}
long answer = (r-(sign*s))%store;
return answer;
}
public void initializeDecryption(DecryptionKey decryptionKey){
this.decryptionKey =decryptionKey;
}
public DecryptionKey getDecryptionKey(){
if(decryptionKey != null){
return this.decryptionKey;
}else{
this.decryptionKey = new DecryptionKey ();
return this.decryptionKey;
}
}
public int getModValue(int tempGenerator , int modNumber, int power){
int ReturnModValue = 1;
for(int i =0;i < power; i++){
ReturnModValue =(ReturnModValue*tempGenerator) % (modNumber);
}
return ReturnModValue;
}

public int[] decrypt(int cipherTextOne , int [] cipherTextTwoArray){
int []InverseValue2 = new int[cipherTextTwoArray.length];
long InverseValue = FindInverse(this.decryptionKey.getPrimeNumber(),cipherTextOne);
int InverseValue1 =getModValue((int)InverseValue,this.decryptionKey.getPrimeNumber(),this.decryptionKey.getPrivateKey());
for(int i =0; i InverseValue2[i] = (InverseValue1*cipherTextTwoArray[i])%decryptionKey.getPrimeNumber();
}
return InverseValue2;
}
public String getMessage(){
return this.message;
}

public void setMessage(String message){
this.message = message;
}
}



package elgamal;
/*
* Created on Mar 27, 2008
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/

/**
* @author suranga kulathunga
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class CipherText {

/**
*
*/

private int CipherTextOne = 0;
private int CipherTextTwo = 0;

public CipherText() {
}

public void setCipherTextOne(int CipherTextOne ){
this.CipherTextOne = CipherTextOne;
}
public void setCipherTextTwo(int CipherTextTwo ){
this.CipherTextTwo = CipherTextTwo;
}
public int getCipherTextOne(){
return this.CipherTextOne;
}
public int getCipherTextTwo(){
return this.CipherTextTwo;
}
}


package elgamal;

/*
* Created on Mar 28, 2008
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/

/**
* @author suranga kulathunga
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class DecryptionKey {

/**
*
*/
private int primeNumber = 0;
private int privateKey = 0;
public DecryptionKey() {

}

public int getPrivateKey(){
return privateKey;
}
public int getPrimeNumber(){
return primeNumber;
}
public void setPrivateKey(int privateKey){
this.privateKey = privateKey;
}
public void setPrimeNumber(int primeNumber){
this.primeNumber = primeNumber;
}


}


package elgamal;

/*
* Created on Mar 28, 2008
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/

/**
* @author suranga kulathunga
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class Encryption {

/**
*
*/
private int randomNumber = 0;
private int cipherTextOne = 0;
private int cipherTextTwo = 0;
private int [] cipherTextTwoArray = null;
private String Message = "";
private EncryptionKey encryptionKey = new EncryptionKey();
public Encryption() {
super();
// TODO Auto-generated constructor stub
}
public void createCipherTextOne(){
int primeNumber = this.encryptionKey.getPrimeNumber();
int generator= this.encryptionKey.getGenerator();
this.cipherTextOne = getModValue(generator,primeNumber,randomNumber);
//this.cipherTextOne =(Math.pow(generator,randomNumber))%publicKey;
}

public int createCipherTextTwo(int message){
int primeNumber = this.encryptionKey.getPrimeNumber();
int generator= this.encryptionKey.getGenerator();
int randomNumber =this.randomNumber;
//int powerValue = randomNumber*primeNumber;
int powerValue = getModValue(encryptionKey.getPublicKey(),primeNumber,randomNumber);
this.cipherTextTwo = (message*powerValue)%primeNumber;
//this.cipherTextTwo = (message*getMadValue(generator,primeNumber,randomNumber))%primeNumber;

//this.cipherTextOne =(Math.pow(generator,randomNumber))%publicKey;
return cipherTextTwo;
}

public void initializeEncryption(EncryptionKey encryptionKey,String encryptionMessage){
this.encryptionKey =encryptionKey;
this.randomNumber =(int)((this.encryptionKey.getPrimeNumber()-2)*(Math.random()));
this.Message = encryptionMessage;
}
public int getModValue(int tempGenerator , int modNumber, int power){
int ReturnModValue = 1;
for(int i =0;i < power; i++){
ReturnModValue =(ReturnModValue*tempGenerator) % (modNumber);
}
return ReturnModValue;
}
public int getCipherTextOne(){
return this.cipherTextOne;
}

public int getCipherTextTwo(){
return this.cipherTextTwo;
}

public int[] getCipherTextTwoArray(){
return this.cipherTextTwoArray;
}

public void encrypt(String Message){
this.createCipherTextOne();
int length = Message.length();
//int [] Ascii = new int[Message.];
cipherTextTwoArray = new int[length];
for (int i = 0 ; i cipherTextTwoArray[i] = this.createCipherTextTwo((int)Message.charAt(i));
}
}
}



package elgamal;

/*
* Created on Mar 28, 2008
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/

/**
* @author suranga kulathunga
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class EncryptionKey {

/**
*
*/
private int primeNumber = 0;
private int publicKey = 0;
private int generator = 0;
public EncryptionKey() {
super();
// TODO Auto-generated constructor stub
}

public int getPrimeNumber(){
return primeNumber;
}
public int getPublicKey(){
return publicKey;
}
public int getGenerator(){
return generator;
}

public void setPrimeNumber(int primeNumber){
this.primeNumber = primeNumber;
}

public void setPublicKey(int publicKey){
this.publicKey = publicKey;
}
public void setGenerator(int generator){
this.generator = generator;
}

}



package elgamal;

import java.util.Vector;

/*
* Created on Mar 26, 2008
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/

/**
* @author suranga kulathunga
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class Generator {

private int primeNumber = 0;
private int generator = 0;
/**
*
*/
public Generator() {
super();
// TODO Auto-generated constructor stub
}
public Vector createGenerator(int primeNumber){
Vector aa = new Vector();
int tempGenerator = 0;
for ( tempGenerator =2 ; tempGenerator boolean valueGenerated = false;
int[] TempArray = new int[primeNumber - 1];
int ReturnModValue = 1;
for (int tempVal = 1; tempVal < primeNumber; tempVal++) {

// Return the Mod value

ReturnModValue = getModValue(tempGenerator, primeNumber,
tempVal,ReturnModValue);

// Check the Mod value , if it is equal to 1 and not the last number
if(ReturnModValue == 1 && tempVal!=primeNumber-1){
break;
}

// Compare it with other mod values
boolean temp = compareValue(TempArray, ReturnModValue , tempVal);

// Add the Mod values to a array
TempArray[tempVal - 1] = ReturnModValue;

if (temp == true) {
break;
}
// If this is a generator set the flag true
if(tempVal == primeNumber-1 && TempArray[tempVal-1]==1){
valueGenerated= true;
break;
}
}

// Add the Generator to the Vetor
if(valueGenerated==true){
aa.addElement(String.valueOf(tempGenerator));
break;
}
}
return aa;
//return tempGenerator;
}
public int getModValue(int tempGenerator , int primeNumber, int tempVal, int ReturnModValue){
int anu =(ReturnModValue*tempGenerator) % (primeNumber);
return anu;
}
public boolean compareValue(int TempArray[],int ReturnModValue, int tempVal){
for ( int i =0 ; i if(TempArray[i] ==ReturnModValue ){
return true;
}
}
return false;
}

public int createPrimeNumber(int StartNumber , int EndNumber){
double x =0;
while (true){
double PrimeNumber =StartNumber+ (EndNumber - StartNumber)*Math.random();
int PrimeNumber1 =(int)PrimeNumber;
//double x = (Math.pow(2,PrimeNumber1-1))%PrimeNumber1;
x = getTotalModValue(2,PrimeNumber1,PrimeNumber1-1);
if(x==1){
return PrimeNumber1;
}
}

}
public Vector createPrimeNumberVector(int StartNumber , int EndNumber){
Vector aa = new Vector();
double x =0;
double y =0;
double xfinal =0;
int ans =0;
for ( int i =StartNumber ; i<=EndNumber ; i++){
// int index = i/1000;
// x = (Math.pow(2,1000))%i;
// y = (Math.pow(2,i-1-(index*1000)))%i;
// xfinal =Math.pow(x,index);
// ans = (xfinal*y)%i;
ans = getTotalModValue(2,i,i-1);
if(ans==1){
aa.addElement(String.valueOf(i));
}
}
return aa;
}
public int getTotalModValue(int tempGenerator , int modNumber, int power){
int ReturnModValue = 1;
for(int i =0;i < power; i++){
ReturnModValue =(ReturnModValue*tempGenerator) % (modNumber);
}
return ReturnModValue;
}
public void setPrimeNumber(int primeNumber){
this.primeNumber = primeNumber;
}
public void setGenerator(int generator){
this.generator = generator;
}
public int getPrimeNumber(){
return primeNumber;
}
public int getGenerator(){
return generator;
}
public void initializeGenerator(int generator,int primeNumber){
setPrimeNumber(primeNumber);
setGenerator(generator);
}
}



package elgamal;

/*
* Created on Mar 26, 2008
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/

/**
* @author suranga kulathunga
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class Keys {

/**
*
*/
public Keys() {

}

private int primeNumber = 0;
private int privateKey = 0;
private int publicKey = 0;
private int generator = 0;

public int getPrivateKey(){
return privateKey;
}
public int getPrimeNumber(){
return primeNumber;
}
public int getPublicKey(){
return publicKey;
}
public int getGenerator(){
return generator;
}

public void setPrimeNumber(int primeNumber){
this.primeNumber = primeNumber;
}
public void setGenerator(int generator){
this.generator = generator;
}
public void setPrivatePublicKeys(int privateKey,int primeNumber){
this.privateKey = privateKey;
//this.publicKey = (Math.pow(this.generator,privateKey))%primeNumber;
this.publicKey = getMadValue(generator,primeNumber,privateKey);
}
public void initializeKeys(int generator,int primeNumber){
setPrimeNumber(primeNumber);
setGenerator(generator);
this.privateKey =(int)((primeNumber-2)*(Math.random()));
this.publicKey = getMadValue(generator,primeNumber,privateKey);
//this.publicKey = (Math.pow(this.generator,privateKey))%primeNumber;
}
public EncryptionKey getEncryptionKey(){
EncryptionKey publicKey = new EncryptionKey();
publicKey.setGenerator(this.generator);
publicKey.setPrimeNumber(this.primeNumber);
publicKey.setPublicKey(this.publicKey);
return publicKey;
}

public DecryptionKey getDecryptionKey(){
DecryptionKey privateKey = new DecryptionKey();
privateKey.setPrivateKey(this.privateKey);
privateKey.setPrimeNumber(this.primeNumber);
return privateKey;
}
public int getMadValue(int tempGenerator , int modNumber, int power){
int ReturnModValue = 1;
for(int i =0;i < power; i++){
ReturnModValue =(ReturnModValue*tempGenerator) % (modNumber);
}
return ReturnModValue;
}
}



Tuesday, June 17, 2008

Nanotechnology


Nanotechnology deals with particles in scales of molecular or atomic range, normally 1 to 100 nanometers, it is an applied science and technology discipline used in with a broad area such as medicine, engineering, computer and IT, materials, energy generation and consumer goods.


Nano is a Greek word for English word dwarf, which implies that nanotechnology deals with very small scale things. As motioned above, those particles of non scale are used as fundamental building materials for inventing new applications.


  • Carbon Bucky balls
  • Carbon Nano tubes

Carbon Bucky balls


Also known as Buckministerfullerine, Named after American architect R. Buckminister Fuller who designed a geodesic dome with the same fundamental symmetry, is the roundest and most symmetrical large molecule known to man. This consists of 60 carbon atoms placed with equal distance with series of interlocking hexagons and pentagons forming a structure that looks similar to a soccer ball.


C60 is the third most common form of pure carbon next to graphite and diamond respectively. C60 is actually consisting of 12 pentagons and 20 hexagons creating a structure known as icosohedron. It is also the only molecule composed of a single element to form a hollow spheroid.




Buckyball has high receptivity to high speed collisions and can be made very hard and strong by compressing it. It can be obtain buckyball with more than twice as hard as its cousin, diamond by compressing it to 70 percent of its original size

Area 51

Area 51, a remote starch of land, located in southwestern portion of Lincoln County in southern Nevada in the western United States, equipped with maximum security on earth and is considered as one of the most secretive places in the modern world. One of its major attractions is the military airfield located in its center, on the southern shore of a dry lakebed. The Primary purpose of this facility has been to support development and testing of experimental aircraft and weapons systems. This remote facility is believed to be subjected to high level of extra terrestrial activates since its origin and it is also believed that US government has been using this as a basement for developing aircrafts with alien technologies (ex. B-2 Spirit).



Area 51 has been making headlines on various frontline magazines with stories surrounded with science fiction, myths which are based on numerous eyewitness accounts of extra-Terrestrial Activates and UFO in area 51.

Despite all of these tales, science fiction and myths surrounding Area 51, it continues to provide its primary purpose of development and testing of experimental aircraft and weapons systems.



to be continue....


Elgamal encryption

Elgamal encryption

Elgamal encryption invented by Taher El Gamal is an asymmetric key encryption algorithm for public-key cryptography based on discrete logarithm and Diffie-Hellman key exchange. It consists of three components the key generator, the encryption algorithm, and the decryption algorithm.

The following section describes the basics of elgamal algorithm.

Key generator

Let p be a large prime number and g be a generator of the multiplicative group Zp of the integers modulo p in the range {1… p-1}.

The group of units U (Zp) is the group of all integers relatively prime to p under multiplication mod p. All arithmetic here is done modulo p. Then we find the generators from the group of units U (Zp). Finding a Key generator is further generalized in section generator.

Public key and Private Key

Elgamal encryption consists of a public key and a private key corresponding to it. The public key and private key can be created as follows,

Choose a random number a in the range {1… p-2}.Then Computes A ,

A = ga mod p

Public key is (p, g, A) and Private Key is a.

Encryption algorithm

Let Message is an integer m in the range {1… p-1} and select a random number k in the range {1… p-2}. The Encrypted message is generated as follows,

C1 = gk mod p

C2 = m (g -a) k mod p

C= (C1, C2)

The cipher text C is send to the Receiver.

Decryption algorithm

To recover plaintext m from C (cipher text), the Receiver should need private key A and prime number p.

Decryption of the cipher text using el gamal, to retrieve the original message is as given.

M = C1-a *C2 mod p

M = C1-a *C2 mod p

= m (g -a) k * C1-a mod p

= m (ga) k *(g -a) k mod p

= m

Generator

A generator g is a number less than p for which g n mod p gives different values for every different value of n between 1 and p-1. Thus n = p-1 is the first and only time that gk mod p = 1. For example 3 is a generator for prime number 17, but 2 is not a generator for 17 because 2 8

mod 17 = 1.