Saturday, June 10, 2017

Array Sort in Java (better performance)

package yourpackagename;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Timer;

public class ArrayPractices {

public static void main(String[] args){
//Array Declaration
int[] intArray={0, 100, 2, 22, 66, 501, 6, 8, 0};
long startTime= -1;
long endTime = -1;

// Java inbuilt Arrays.sort method from DualPivotQuicksort class method (Arrays.sort)
startTime=System.nanoTime();
Arrays.sort(intArray);

for(int i=0; i<=intArray.length-1;i++){
System.out.println(intArray[i]);
}
endTime= System.nanoTime();
System.out.println("Total execution time: " + (endTime - startTime) );

// User Defined method for sorting Array in ascending order
startTime=System.nanoTime();
int[] op = sorting(intArray, 0, intArray.length-1);
for(int i=0; i<=op.length-1; i++){
System.out.println(op[i]);
}

endTime= System.nanoTime();
System.out.println("Total execution time: " + (endTime - startTime) );
}

public static int[] sorting(int[] a, int start, int end){
int lowVal=-1;
int highVal=-1;
for(int i=start; i<=end; i++){
if(a.length-1>=i+1){
if(a[i]>a[i+1]){
lowVal = a[i+1];
highVal = a[i];
a[i]=lowVal;
a[i+1]=highVal;
i--;
}else if(a[i]<a[i+1]){
for(int k=end; k>=i+1; k--){
if(a.length-1>=k){
if(a[k]<a[i]){
highVal = a[i];
lowVal = a[k];
a[k]=highVal;
a[i]=lowVal;
}

}
}
}
}
}
return a;
}
}

Saturday, December 17, 2016

Password Encoder Utility - Selenium


Hi All,
 
We have password utility which generates based on your input string in QTP/UFT which is called as "Password encoder".  As selenium is freeversion :) they're not providing you any direct utility, but you've option to encrypt and decrypt your password by using org.apache.commons.codec.binary.Base64 from Selenium-Java.
 
Step 1:
Create Maven Project/Java Project
You must have below dependency in maven project or add jar to your project manually
 
 
Step 2:
Create one package and create a class "PasswordEncoder" with Main method
 
Step 3:
Copy and paste below code to your class file
 
import org.apache.commons.codec.binary.Base64;
 
public class PasswordEncoder {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println();
System. out .println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
System.out.println("Encrypted password of given string is in next line");
System.out.println(EncyptPassword(args[0]));
System.out.println();
System. out .println("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
}
public static String EncyptPassword(String strOrgPwd){
byte [] encoded =Base64.encodeBase64(strOrgPwd.getBytes());
return new String(encoded);
}

 
Step 4:
Export Maven project/Java project as (executable) Runnable jar file with name "passwordEncoder.jar"
 
Step 5:
Create a Folder in your local drive
 
Step 6:
Copy runnable jar file into the created folder
 
Step 7:
Create a bat file and copy paste below code
 
@echo off
cd\
setlocal
 
 
 

call:pwd pass
call:pwd pass2
cd /d %~dp0
IF "%pass%" == "%pass2%" ( echo.Passwords entered are matched, Hurray!!!
java —jar passwordEncoder.jar %pass% ) ELSE (
echo.Passwords entered does not matched... Try with correct password again!!!
pause
EXIT
)
pause

 

GOTO:EOF
:pwd var title color —— shows a password dialog box
:$created 20060101 :$changed 20080226 :$categories Input,Password
SETLOCAL
 

 

set "tit=%~2"
set "col=%~3"
set "pwd="
if not defined col set "col=EF"
if not defined tit set "tit=Password:"
set "f=%temp%\%~nx0.tmp~0.tmp"
start "%tit%" /wait cmd /c "mode con cols=50 lines=1&color %col%&set /p "in="&call echo.%%in%%>"%f%""
for /f "usebackq tokens=*" %%a in ("%f%") do set "pwd=%%a"
del /q "%f%"
ENDLOCAL&if "%~1" NEQ "" (SET %~1=%pwd%) ELSE ECHO.%txt%
EXIT /b
 
 
Step 8:
Create a short for the bat file and change icon as you like
 
Step 9:
Copy the shortcut file of bat and paste under all programs of you windows
 
Your Utility is ready... Go ahead and enjoy your own utility
 
Advantages:
1. You can enter string even during screen share. Text you're entering won't be displayed to all
2. Utility will ask for your password confirmation twice, which avoids typo error encryptions
 
"A good threat is worth a thousand tests" - Boris Beizer
There was an error in this gadget