The Top 10s
Monday, March 23, 2015
Simplest codes in JAVA- Brute Force attack for Substitution Cipher
package pkgnew;
import java.io.*;
import javax.swing.JOptionPane;
public class New
{
static void gui()throws IOException
{ String s1=JOptionPane.showInputDialog("Plaease");
//char[] arr= new char[s1.length()];
//double[] arr1=new double[s1.length()];
for(char aa='a';aa<='z';aa++)
{ for(char bb='a';bb<='z';bb++)
{ if(aa==bb){}
for(char cc='a';cc<='z';cc++)
{ if(cc==(aa|bb)){}
for(char dd='a';dd<='z';dd++)
{ if(dd==(aa|bb|cc)){}
for(char ee='a';ee<='z';ee++)
{ if(ee==(aa|bb|cc|dd)){}
for(char ff='a';ff<='z';ff++)
{ if(ff==(aa|bb|cc|dd|ee)){}
for(char gg='a';gg<='z';gg++)
{ if(gg==(aa|bb|cc|dd|ee|ff)){}
for(char hh='a';hh<='z';hh++)
{ if(hh==(aa|bb|cc|dd|ee|ff|gg)){}
for(char ii='a';ii<='z';ii++)
{ if(ii==(aa|bb|cc|dd|ee|ff|gg|hh)){}
for(char jj='a';jj<='z';jj++)
{ if(jj==(aa|bb|cc|dd|ee|ff|gg|hh|ii)){}
for(char kk='a';kk<='z';kk++)
{ if(kk==(aa|bb|cc|dd|ee|ff|gg|hh|ii|jj)){}
for(char ll='a';ll<='z';ll++)
{ if(ll==(aa|bb|cc|dd|ee|ff|gg|hh|ii|jj|kk)){}
for(char mm='a';mm<='z';mm++)
{ if(mm==(aa|bb|cc|dd|ee|ff|gg|hh|ii|jj|kk|ll)){}
for(char nn='a';nn<='z';nn++)
{ if(nn==(aa|bb|cc|dd|ee|ff|gg|hh|ii|jj|kk|ll|mm)){}
for(char oo='a';oo<='z';oo++)
{ if(oo==(aa|bb|cc|dd|ee|ff|gg|hh|ii|jj|kk|ll|mm|nn)){}
for(char pp='a';pp<='z';pp++)
{ if(pp==(aa|bb|cc|dd|ee|ff|gg|hh|ii|jj|kk|ll|mm|nn|oo)){}
for(char qq='a';qq<='z';qq++)
{ if(qq==(aa|bb|cc|dd|ee|ff|gg|hh|ii|jj|kk|ll|mm|nn|oo|pp)){}
for(char rr='a';rr<='z';rr++)
{ if(rr==(aa|bb|cc|dd|ee|ff|gg|hh|ii|jj|kk|ll|mm|nn|oo|pp|qq)){}
for(char ss='a';ss<='z';ss++)
{ if(ss==(aa|bb|cc|dd|ee|ff|gg|hh|ii|jj|kk|ll|mm|nn|oo|pp|qq|rr)){}
for(char tt='a';tt<='z';tt++)
{ if(tt==(aa|bb|cc|dd|ee|ff|gg|hh|ii|jj|kk|ll|mm|nn|oo|pp|qq|rr|ss)){}
for(char uu='a';uu<='z';uu++)
{ if(uu==(aa|bb|cc|dd|ee|ff|gg|hh|ii|jj|kk|ll|mm|nn|oo|pp|qq|rr|ss|tt)){}
for(char vv='a';vv<='z';vv++)
{ if(vv==(aa|bb|cc|dd|ee|ff|gg|hh|ii|jj|kk|ll|mm|nn|oo|pp|qq|rr|ss|tt|uu)){}
for(char ww='a';ww<='z';ww++)
{ if(ww==(aa|bb|cc|dd|ee|ff|gg|hh|ii|jj|kk|ll|mm|nn|oo|pp|qq|rr|ss|tt|uu|vv)){}
for(char xx='a';xx<='z';xx++)
{ if(xx==(aa|bb|cc|dd|ee|ff|gg|hh|ii|jj|kk|ll|mm|nn|oo|pp|qq|rr|ss|tt|uu|vv|ww)){}
for(char yy='a';yy<='z';yy++)
{ if(yy==(aa|bb|cc|dd|ee|ff|gg|hh|ii|jj|kk|ll|mm|nn|oo|pp|qq|rr|ss|tt|uu|vv|ww|xx)){}
for(char zz='a';zz<='z';zz++)
{ if(zz==(aa|bb|cc|dd|ee|ff|gg|hh|ii|jj|kk|ll|mm|nn|oo|pp|qq|rr|ss|tt|uu|vv|ww|xx|yy)){}
s1=s1.replace('a', aa);s1=s1.replace('b', bb);s1=s1.replace('c', dd);
s1=s1.replace('d', dd);s1=s1.replace('e', ee);s1=s1.replace('f', ff);
s1=s1.replace('g', gg);s1=s1.replace('h', hh);s1=s1.replace('i', ii);
s1=s1.replace('j', jj);s1=s1.replace('k', kk);s1=s1.replace('l', ll);
s1=s1.replace('m', mm);s1=s1.replace('n', nn);s1=s1.replace('o', oo);
s1=s1.replace('p', pp);s1=s1.replace('q', qq);s1=s1.replace('r', rr);
s1=s1.replace('s', ss);s1=s1.replace('t', uu);s1=s1.replace('v', vv);
s1=s1.replace('w', ww);s1=s1.replace('x', xx);s1=s1.replace('y', yy);
s1=s1.replace('z', zz);s1=s1.replace('u', uu);
if(s1.contains("that")||s1.contains("is")||s1.contains("up")||s1.contains("you")||s1.contains("meet")||
s1.contains("sky")||s1.contains("cool")||s1.contains("my")||s1.contains("me")||s1.contains("in")||s1.contains("of")||s1.contains("was"))
{System.out.println(s1);System.in.read();}
else{long k=0;k++;System.out.println(k);}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}}
public static void main(String args[])throws IOException
{
gui();
System.out.println("I have returned in main");
}
}
Simplest Codes in JAVA- Reading from a URL
package readingfromaurl;
import java.io.*;
import java.net.*;
public class ReadingFromAURL {
public static void main(String[] args) throws Exception {
URL oracle = new URL("http://docs.oracle.com/javase/tutorial/networking/urls/readingWriting.html");
URLConnection yc = oracle.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(
yc.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);}}
import java.io.*;
import java.net.*;
public class ReadingFromAURL {
public static void main(String[] args) throws Exception {
URL oracle = new URL("http://docs.oracle.com/javase/tutorial/networking/urls/readingWriting.html");
URLConnection yc = oracle.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(
yc.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);}}
Top Simplest Codes in JAVA- Dividing a file in chunks
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package nwproject;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.nio.file.Files;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ArrayList;
/**
*
* @author Muhammad Asim
*/
public class Nwproject {
private static String Driver_Class = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
private static String URL = "jdbc:sqlserver://localhost\\localhost (sa):1433;databaseName=Tracker_Server";
private static String User_Name = "sa";
private static String Password = "123";
private static int No_Of_Chunks;
private static String File_Size;
private static String File_Name;
private static String IP;
public static ArrayList<File> File_List = new ArrayList<>();
public static void main(String[] args) throws IOException {
// TODO code application logic here
Socket Server = new Socket("localhost", 9999);
Recieve_Files(Server);
Merge_Files();
Server.close();
Data_Shared_With_DataBase();
Update_Tracker_Server();
}
private static void Recieve_Files(Socket Server) throws IOException {
int File_Size = 262144,File_Index = 0;
BufferedInputStream IS =new BufferedInputStream (Server.getInputStream());
File newFile ;
FileOutputStream ChunkOS ;
BufferedOutputStream ChunkBOS = null ;
byte[] Byte_Array = new byte[File_Size];
int tmp;
while ( (tmp = IS.read(Byte_Array,0,File_Size)) != -1) {
newFile = new File("C:\\Users\\MuhammadKhaliq\\Desktop\\hi", "ChunkReceived" + String.format("%03d", ++File_Index)); //making file chunks
ChunkOS = new FileOutputStream(newFile);
ChunkBOS = new BufferedOutputStream(ChunkOS);
ChunkBOS.write(Byte_Array);
File_List.add(newFile);
}
ChunkBOS.flush();
ChunkBOS.close();
}
private static void Merge_Files() throws FileNotFoundException, IOException {
FileOutputStream ChunkOS = new FileOutputStream("C:\\Users\\MuhammadKhaliq\\Desktop\\receive.mp3"); //Merge the chunks to destination with name
BufferedOutputStream ChunkBOS = new BufferedOutputStream(ChunkOS);
for (File f : File_List) {
Files.copy(f.toPath(), ChunkBOS);
}
}
private static void Update_Tracker_Server() {
Connection conn = null;
try {
Class.forName(Driver_Class);
conn = DriverManager.getConnection(URL, User_Name, Password);
System.out.println("Connected!");
String query = "{ call Add_Data( ?, ?, ?, ? )}";
CallableStatement con = conn.prepareCall(query);
con.setString(1, IP);
con.setString(2, File_Name);
con.setString(3, File_Size + " KB");
con.setInt(4, No_Of_Chunks);
con.executeUpdate();
} catch (ClassNotFoundException | SQLException ex) {
System.out.println("Error!" + ex + "");
}
}
private static void Data_Shared_With_DataBase() throws UnknownHostException {
File file = new File("C:\\Users\\MuhammadKhaliq\\Desktop\\receive.mp3");
File_Name = file.getName();
double Size = file.length() / 1024;
File_Size = String.valueOf(Size);
No_Of_Chunks = File_List.size();
InetAddress ip = InetAddress.getLocalHost();
IP = ip.getHostAddress();
}
}
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package nwproject;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.nio.file.Files;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ArrayList;
/**
*
* @author Muhammad Asim
*/
public class Nwproject {
private static String Driver_Class = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
private static String URL = "jdbc:sqlserver://localhost\\localhost (sa):1433;databaseName=Tracker_Server";
private static String User_Name = "sa";
private static String Password = "123";
private static int No_Of_Chunks;
private static String File_Size;
private static String File_Name;
private static String IP;
public static ArrayList<File> File_List = new ArrayList<>();
public static void main(String[] args) throws IOException {
// TODO code application logic here
Socket Server = new Socket("localhost", 9999);
Recieve_Files(Server);
Merge_Files();
Server.close();
Data_Shared_With_DataBase();
Update_Tracker_Server();
}
private static void Recieve_Files(Socket Server) throws IOException {
int File_Size = 262144,File_Index = 0;
BufferedInputStream IS =new BufferedInputStream (Server.getInputStream());
File newFile ;
FileOutputStream ChunkOS ;
BufferedOutputStream ChunkBOS = null ;
byte[] Byte_Array = new byte[File_Size];
int tmp;
while ( (tmp = IS.read(Byte_Array,0,File_Size)) != -1) {
newFile = new File("C:\\Users\\MuhammadKhaliq\\Desktop\\hi", "ChunkReceived" + String.format("%03d", ++File_Index)); //making file chunks
ChunkOS = new FileOutputStream(newFile);
ChunkBOS = new BufferedOutputStream(ChunkOS);
ChunkBOS.write(Byte_Array);
File_List.add(newFile);
}
ChunkBOS.flush();
ChunkBOS.close();
}
private static void Merge_Files() throws FileNotFoundException, IOException {
FileOutputStream ChunkOS = new FileOutputStream("C:\\Users\\MuhammadKhaliq\\Desktop\\receive.mp3"); //Merge the chunks to destination with name
BufferedOutputStream ChunkBOS = new BufferedOutputStream(ChunkOS);
for (File f : File_List) {
Files.copy(f.toPath(), ChunkBOS);
}
}
private static void Update_Tracker_Server() {
Connection conn = null;
try {
Class.forName(Driver_Class);
conn = DriverManager.getConnection(URL, User_Name, Password);
System.out.println("Connected!");
String query = "{ call Add_Data( ?, ?, ?, ? )}";
CallableStatement con = conn.prepareCall(query);
con.setString(1, IP);
con.setString(2, File_Name);
con.setString(3, File_Size + " KB");
con.setInt(4, No_Of_Chunks);
con.executeUpdate();
} catch (ClassNotFoundException | SQLException ex) {
System.out.println("Error!" + ex + "");
}
}
private static void Data_Shared_With_DataBase() throws UnknownHostException {
File file = new File("C:\\Users\\MuhammadKhaliq\\Desktop\\receive.mp3");
File_Name = file.getName();
double Size = file.length() / 1024;
File_Size = String.valueOf(Size);
No_Of_Chunks = File_List.size();
InetAddress ip = InetAddress.getLocalHost();
IP = ip.getHostAddress();
}
}
Top Simplest Codes of JAVA- Shift Cipher
package ShiftCipher;
import java.util.Scanner;
import javax.swing.JOptionPane;
public class ShiftCipher
{
static String cipher(String msg, int shift){
String s = "";
int len = msg.length();
for(int x = 0; x < len; x++)
{
char c = (char)(msg.charAt(x) + shift);
if (c > 'z')
s += (char)(msg.charAt(x) - (26-shift));
else
s += (char)(msg.charAt(x) + shift); } return s;}
public static void main( String args[] )
{
String s1=JOptionPane.showInputDialog("Enter Value");
for (int i=1;i<=26;i++){
System.out.println("For k="+i +"\t\t"+cipher(s1, i));
} }}
import java.util.Scanner;
import javax.swing.JOptionPane;
public class ShiftCipher
{
static String cipher(String msg, int shift){
String s = "";
int len = msg.length();
for(int x = 0; x < len; x++)
{
char c = (char)(msg.charAt(x) + shift);
if (c > 'z')
s += (char)(msg.charAt(x) - (26-shift));
else
s += (char)(msg.charAt(x) + shift); } return s;}
public static void main( String args[] )
{
String s1=JOptionPane.showInputDialog("Enter Value");
for (int i=1;i<=26;i++){
System.out.println("For k="+i +"\t\t"+cipher(s1, i));
} }}
Monday, February 17, 2014
Top 10 Largest Air Force in the World
Rank 1 - United States Air Force (USA):
2,132 Fighter Aircrafts
329,600 Airforce Personnel
Rank 2 - Russian Air Force (RUSSIA):
252 Fighter Aircrafts
160,000 Airforce Personnel
Rank 3 - People’s Liberation Army Air Force (CHINA):
1770 Fighters and Attack aircrafts
330,000 Airforce Personnel
Rank 4 - Royal Air Force (UNITED KINGDOM):
240 Fighter Aircrafts
41,300 Airforce Personnel
Rank 5 - Armée de l’Air (FRANCE):
234 Fighter combat aircrafts
58,900 Airforce Personnel
Rank 6 - Luftwaffe (GERMANY):
100 Fighter aircrafts
35,560 Airforce Personnel
Rank 7 - Pakistan Air Force (PAKISTAN) :
571 Fighter Aircrafts
127,000 Airforce Personnel
Rank 8 - Royal Australian Air Force (AUSTRALIA):
95 Fighter/Attack aircrafts
17,375 Airforce personnel
Rank 9 - Indian Air Force (INDIA) :
265 Fighter Aircrafts
127,000 Airforce Personnel
Rank 10 - Japan Air Force (INDIA) :
123 Fighter Aircrafts
27,000 Airforce Personnel
123 Fighter Aircrafts
27,000 Airforce Personnel
Top 10 Gold Producing Countries
10. Uzbekistan – 90,000 kilograms
9. Indonesia – 100,000 kilograms
8. Ghana – 100,000 kilograms
7. Canada – 110,000 kilograms
6. Peru – 150,000 kilograms
5. South Africa – 190,000 kilograms
4. Russia – 200,000 kilograms
3. United States – 237,000 kilograms
2. Australia – 270,000 kilograms
1. China – 355,000 kilograms
Top 10 Countries with greatest oil reserves
Billions of Barrels
- Saudi Arabia > 261.8
- Canada > 180.0
- Iraq > 112.5
- U.A.E. > 97.8
- Kuwait > 96.5
- Iran > 89.7
- Venezuela > 77.8
- Russia > 60.0
- Libya > 29,5
- Nigeria > 24.0
Subscribe to:
Posts (Atom)