Euclidean vs Chebyshev vs Manhattan Distance ?


You must have encountered with various programming puzzles (e.g. printing concentric rectangular pattern) which could be easily solved by using the concept of Chebyshev distance. There are many popular such puzzles which can be solved using different distance concepts. There are many metrics to calculate a distance between two points p (x1, y1) and q (x2, y2) in xy-plane.

EUCLIDEAN DISTANCE:

The Euclidean distance or Euclidean metric is the "ordinary" (i.e.straight-line) distance between two points in Euclidean space. 


MANHATTAN DISTANCE:

The Manhattan distance, also known as rectilinear distance, city block distance, taxicab metric is defined as the sum of the lengths of the projections of the line segment between the points onto the coordinate axes.


CHEBYSHEV (CHESSBOARD) DISTANCE:

In Chebyshev distance, all 8 adjacent cells from the given point can be reached by one unit i.e diagonal move is valid.



It is also known as chessboard distance, since in the game of chess the minimum number of moves needed by a king to go from one square on a chessboard to another equals the Chebyshev distance between the centers of the squares

Sending Simple Data From Java to PHP via a POST Request


So the software I am developing in my leisure time is about to complete. Past weekend I worked on it's security aspects and implemented many things like encryption and encapsulation of byte code, Encryption of POST data, Generation of unique ID for each system using my software and the licensing part. I will try to explain each part in my coming posts.

Earlier I demonstrated How to display Splash Screen in Java. Today I will show how I am sending simple data from my Java code to my PHP page on Web server.

 package www.isumitjha.com;  
 import java.io.BufferedReader;  
 import java.io.IOException;  
 import java.io.InputStreamReader;  
 import java.io.OutputStreamWriter;  
 import java.io.PrintStream;  
 import java.net.HttpURLConnection;  
 import java.net.MalformedURLException;  
 import java.net.URL;  
 import java.net.URLConnection;  
 import java.net.URLEncoder;  
 class Test {  
  public static void main(String args[]) {  
  try {  
   // opening a connection to the site  
   URL url = new URL("http://api.isumitjha.com/example.php");  
   HttpURLConnection con = (HttpURLConnection) url.openConnection();  
   // Setting the DoOutput flag true for using output   
   con.setDoOutput(true);  
   con.setRequestMethod("POST");  
   // Encoding the POST data  
   String data = URLEncoder.encode("key1", "UTF-8") + "=" + URLEncoder.encode("Hello", "UTF-8") + "&" + URLEncoder.encode("key2", "UTF-8") + "=" + URLEncoder.encode("World", "UTF-8");  
   OutputStreamWriter osw = new OutputStreamWriter(  
   con.getOutputStream());  
   // Sending parameter to site  
   osw.write(data);  
   osw.flush();  
   con.getInputStream();  
   System.out.println("RESPONSE CODE = " + con.getResponseCode());  
   BufferedReader in = new BufferedReader(new InputStreamReader(  
   con.getInputStream()));  
   String line = null;  
   while ((line = in .readLine()) != null) {  
   System.out.println(line);  
   }  
  } catch (MalformedURLException e) {  
   e.printStackTrace();  
  } catch (IOException e) {  
   e.printStackTrace();  
  }  
  }  
 }  

Now let's see the simple PHP code that prints all value received via POST request.

 <?php  
 foreach ($_POST as $key => $data) {  
   echo $data." ";  
   }  
 ?>  

So this is how I am sending data to my server. In my next post I will show you how to encrypt POST data using Advanced Encryption Standard and receive response from server in JSON format.

I hope you enjoyed reading :)

How to display Splash Screen in Java



We all know the importance of user interface in any commercial as well as non commercial software. Today while working on one of my project I felt that the loading time of my application is quite longer than usual.

The reasons behind  longer loading time are the loading of configuration file and downloading of resources from web. Here splash screen is the requirement for this situation.

 Although there are many ways to implement splash screen in java but I prefer the built in API for splash screen. Let's see how to use this native Splash screen API for your application.

Java SE 6 provides a solution that allows the application to display the splash screen much earlier, even before the virtual machine starts. A Java application launcher is able to decode an image and display it in a simple non-decorated window.

Below is the sample Java Swing application that do some time consuming task before initializing UI.

Copy and save below code in file  MySplashScreenDemo.java

 package com.decryptoniter.splash;  
 import java.awt.FlowLayout;  
 import javax.swing.*;  
 public class MySplashScreenDemo {  
  MySplashScreenDemo() {  
  // some time consuming task before UI initialization  
  someTask();  
  // UI will initialize now   
  initUI();  
  }  
  void someTask() {  
  System.out.println("Some time consuming task is executed");  
  try {  
   Thread.sleep(10000);  
  } catch (Exception e) {  
   e.printStackTrace();  
  }  
  }  
  void initUI() {  
  JFrame frame = new JFrame("Splash Screen Demo");  
  JPanel panel = new JPanel();  
  panel.setLayout(new FlowLayout());  
  JLabel label = new JLabel("www.isumitjha.com");  
  panel.add(label);  
  frame.add(panel);  
  frame.setSize(300, 300);  
  frame.setLocationRelativeTo(null);  
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
  frame.setVisible(true);  
  System.out.println("UI initialized");  
  }  
  public static void main(String s[]) {  
  MySplashScreenDemo ss = new MySplashScreenDemo();  
  }  
 }  

Now compile MySplashScreenDemo.java:
javac -d . MySplashScreenDemo.java

Run this application: java com.decryptoniter.splash.MySplashScreenDemo

You will notice that it takes 15 seconds to load the UI after running the application. Now to display splash screen while UI is not loaded we can use java command line argument.

Display a Splash Screen using the Command-Line Argument 

To display a splash screen from the command line use the -splash: command-line argument. This argument is a Java application launcher option that displays a splash screen:

java -splash:<file name> <class name>

For our application use. java -splash:loading.gif  com.decryptoniter.splash.MySplashScreenDemo

Now you can see the splash screen as soon as application is run while UI is not loaded.

Note: The splash screen can display any gif, png, or jpeg image, with transparency, translucency, and animation.

“Stagefright” Google's Android megabug: Everything you need to know about Stagefright

Still wondering what the heck is this "Stagefright" doing the round on internet since last week?

Ever since the Internet erupted over the announcement of a mega bug in Google’s Android OS , everyone seems to be concerned about their privacy. 


This vulnerability was discovered by an Israeli enterprise mobile security company Zimperium. 
"Unlike spear-phishing, where the victim needs to open a PDF file or a link sent by the attacker, this vulnerability can be triggered while you sleep. Before you wake up, the attacker will remove any signs of the device being compromised, and you will continue your day as usual—with a trojaned phone." --Zimperium
A simple Text Message Received and you're hacked!!

Hacker just need your phone number to sends the malicious message that will silently execute malicious code on your device without any action or notifications. Once message is received, hacker can remotely execute this malicious code and delete that message. He can now have full control of your device without your knowledge. Seriously.. You know nothing !!




Now you  wondering if your phone is safe or not?


Here is all the information you need to know about this security hole in Android. 

What is stage fright?

According to Oxford dictionary stage fright is the "Nervousness before or during an appearance before an audience:an attack of stage fright".

What?? What it has to do with my android phone? Oh wait..


Stagefright, is the nickname of a mega Android flaw found in the open source code of Google’s Android OS. This vulnerability was discovered by an Israeli enterprise mobile security company Zimperium. It exposes 95% of Android devices—950 million gadgets—at risk of being hacked.


Basically Straight fright is the part of Android open source code. It is a media library in which this major bug is found. 

Source: http://source.android.com/devices/media.html

Is my device vulnerable?

You own an Android Device. Right??
Well then your device is exposed to this vulnerability. No matter you are using Lollipop or ICS.

What all can a hacker do with my vulnerable device?

What not?
  • He can steal your personal data.
  • Send SMS/MMS from your phone to all users in your contact list. (What if that MMS contain malicious code?)  
  • Make you to be part of botnet network of hacked Android devices.
  • Make you to contribute in any DDOS attack. etc.

What should I do now?

Although Google patched this bug but that doesn't mean you are safe now. You have to wait for your phone-manufacturer like Samsung, HTC, Lenovo, Sony, among others to provide software updates with this patch. 

Meanwhile you should change the settings on your Android apps that use MMS, like Messaging and Hangouts. Un-click “automatically retrieve MMS messages.”

Use WhatsApp and other messaging app to send and receive video clips.

StageFright: Android's Heart of Darkness

Security researchers from Trend Micro have discovered two new attack scenarios that could trigger Stagefright vulnerability without sending malicious multimedia messages. The vulnerability can also be exploited using other attack techniques, such as luring victims to malicious websites.

Drake, who discovered this issue will present his full findings, including six additional attack techniques to exploit the vulnerability, at Black Hat security conference in Las Vegas on on August 5 and DEF CON 23 on August 7, where he is scheduled to deliver a talk titled, 

Stagefright: Scary Code in the Heart of Android.

Lenovo A7000 Wifi Hotspot Issue after ugrading to build A7000-a_S142_150630_ROW

No doubt Lenovo A7000 is the best affordable smart phone below 10k. However in it's recent build "A7000-a_S142_150630_ROW ", some critical bugs have been found. Users are facing problem in wifi and hotspot. Also phone shows sign of lags after the upgrade.
Some of the issue reported by its users on forum are below.

1 ) Wi-Fi Connection not working  after update.
     Unable to connect to any wifi connection. Also wifi hotspot is not working. No laptop or phone are able to connect to phone hotspot.

2 ) Battery drop down at 20% to 15% immediate.
3 ) Messaging Issue ( Takes Times To Response )
4 ) Back Key Responding Lags Now
5 ) After Update Phone Getting Little Bit Lags Now.
6 ) Gameloft Mod APK Issue.
7 ) Heating Issue ( While Game Play, Charging Time, Downloading Time, Camera Using Video Mode )
8 ) Camera Video Portrait Mode Shooting not seen proper view while landscape Mode Watching.
9 ) Phone vibrates on call connect even this feature is not enabled.
10 ) Led notification lights are not working
11 ) Touch Response Issues & OTG Issues.

If you are facing any other issue please share in comments.

Download Huge list of MS Excel Keyboard Shortcuts

Using shortcuts saves a lot of time and it shows your proficiency in application usage. 

Here we have listed a complete list of Microsoft Excel keyboard shortcuts and their descriptions. 




Key Alone Shift Ctrl Alt Shift Ctrl
F1 Help What's This Help   Insert Chart Sheet  
F2 Edit Mode Edit Comment   Save As  
F3 Paste Name Formula Paste Function Define Name   Names From Labels
F4 Repeat Action Find Again Close Window Quit Excel  
F5 Goto Find Restore Window Size    
F6 Next Pane Prev Pane Next Workbook Switch To VBA Prev Workbook
F7 Spell Check   Move Window    
F8 Extend Selection Add To Selection Resize Window Macro List  
F9 Calculate All Calculate Worksheet Minimize Workbook    
F10 Activate Menu Context Menu Restore Workbook    
F11 New Chart New Worksheet New Macro Sheet VB Editor  
F12 Save As Save Open   Print
A     Select All    Formula Arguments
B     Bold    
C     Copy    
D     Fill Down Data Menu  
E       Edit Menu  
F     Find File Menu Font Name
G     Goto    
H     Replace Help Menu  
I     Italics Insert Menu  
J          
K     Insert  Hyperlink    
L          
M          
N     New Workbook    
O     Open Workbook Format Menu Select Comments
P     Print   Font Size
Q          
R     Fill Right    
S     Save    
T       Tools Menu  
U     Underline    
V     Paste    
W     Close Workbook Window Menu  
X     Cut    
Y     Repeat Active    
Z     Undo  


4 Safety Tips for a safer online banking

Gone are the days when you had to stand in long lines simply to get your work done at the bank. With the internet, banking has almost become a pleasurable experience. All you need is a unique user ID and your password, and you have access to a ton of banking transactions – from making transfers, to ordering a new check book, to giving standing instructions to the bank for any EMIs, or checking your balance, or even making payments for your shopping, eating and entertainment. Not only is it convenient, it saves your time, it is available 24/7 as the internet has no time restriction, it is much faster and totally environment friendly. But while all this is tempting, there are some safety measures you should employ while working online.4-tips-for-safer-online-banking



1. Never share your banking password:


Whether you are at a shop or a restaurant, do not share your banking password with anyone. Even bank officials should not know this. You also ought to change it regularly, and ensure it isn’t something so simple that anyone can guess it. Most internet banking passwords are tested for strength while you are making them.

2. Use internet banking at trusted sites:


While every site you visit will give you the choice of paying by entering your internet banking passwords, you should exercise discretion at choosing which sites you really want to use it at. Use only those sites which you trust. Make sure that the site is not one that offers to save your passwords. Even your browser should refrain from knowing your passwords, so before you make the transaction, disable that selection. Read the privacy policies of the sites you are visiting for the first time to check if they are legitimate.

3. Be secure:


This means everything from having an updated internet protection service, to being careful with your ID. When you are making the transaction, look for HTTPS and the lock sign in the address bar. While this is by no means foolproof, it is a beginning. Keep your antivirus updated. New viruses are launched every day and they can track your keystrokes to access your information and send it to a remote server. You ought to be protected against such threats. Always use a firewall.

4. Log out when you are done:


Again a no-brainer, but some of us by force of habit, only shut the browser window without logging off. Sometimes this works – for example in Chrome, but it is by no means the right way to exit your internet bank. Always log out and wait to see whether you have been logged out. You will know if you return to the home page of the site. Also never use internet banking at an internet shop/cafĂ©. Try using only a single computer for your online banking needs instead of too many. That way if there is any trouble, officials will find it easy to check what the source of the problem is.