Skip to main content

Posts

Showing posts with the label Encryption Algorithm

GCD of two number using euclidean algorithm in Java

//File Name: GCDExample.java import java.util.*; public class GCDExample { public static void main(String args[]){ //Enter two number whose GCD needs to be calculated. Scanner scanner = new Scanner(System.in); System.out.println("Please enter first number to find GCD"); int number1 = scanner.nextInt(); System.out.println("Please enter second number to find GCD"); int number2 = scanner.nextInt(); System.out.println("GCD of two numbers " + number1 +" and " + number2 +" is :" + findGCD(number1,number2)); } /* * Java method to find GCD of two number using Euclid's method * @return GDC of two numbers in Java */ private static int findGCD(int number1, int number2) { //base case if(number2 == 0){ return number1; } return findGCD(number2, number1%number2...

Implementation One time pad cipher in Java

// File Name: OneTimePad.java import java.util.*; class msg{ int a=97; char all[]=new char[27]; msg() { for(int i=0;i 26) ct[i]=ct[i]%26; } String cipher=""; for(int i=0;i OUTPUT Enter plaintext: onetimepadalogrihtmsneedlongkey Enter key: longkeyisrequiredforonetimepad Encrpted text is:zbrzsqcxsuebioimky jbriwt rvkhj Decrypted text is:onetimepadalogrihtmsneedlongkey

Implementation of Playfair cipher in Java

//File Name: PlayFairCipher.java import java.util.*; class Basic{ String allChar="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; boolean indexOfChar(char c) { for(int i=0;i 4) { b=0; a++; } } } char p='A'; while(a 4) r1=0; if(r2>4) r2=0; cipherChar+=keyMatrix[r1][c2]; cipherChar+=keyMatrix[r2][c1]; } else if(r1==r2) { ++c1; ++c2; if(c1>4) c1=0; if(c2>4) c2=0; cipherChar+=keyMatrix[r1][c1]; cipherChar+=keyMatrix[r2][c2]; } else{ cipherChar+=keyMatrix[r1][c2];...

implement Rail fence cipher in Java

// File Name: RailFence.java import java.util.*; class RailFenceBasic{ int depth; String Encryption(String plainText,int depth)throws Exception { int r=depth,len=plainText.length(); int c=len/depth; char mat[][]=new char[r][c]; int k=0; String cipherText=""; for(int i=0;i OUTPUT Enter plain text: railfencecipher Enter depth for Encryption: 3 Encrypted text is: rlnchafcieieepr Decrypted text is: railfencecipher

Implementation of Hill cipher in Java

// File name:HillCipher.java import java.util.*; class Basic{ String allChar="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; int indexOfChar(char c) { for(int i=0;i OUTPUT Enter plain-text: meet Enter block size of matrix: 2 Enter key Matrix 3 1 5 2 Encrypted Text is: OQ FG Enter key Inverse Matrix: 2 -1 -5 3 Decrypted Text is: ME ET

Implementation of Caeser cipher in java with brute force attack

//file name CeaserCipher.java import java.util.*; class basic{ String allChar="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; int indexOfChar(char c) { for(int i=0;i =0) { decryptedText+=b.charAtIndex(index-key); } else { decryptedText+=b.charAtIndex((index-key)+26); } } return decryptedText; } void bruteForce(String cipherText) { cipherText=cipherText.toUpperCase(); for(int k=0;k =0) { decryptedText+=b.charAtIndex(index-key); } else { decryptedText+=b.charAtIndex((index-key)+26); } } System.out.println("Decrypted Text Using key"+key+":"+decryptedText); } } } class CeaserCipher{ public static void main(String args[])throws Exception { Scanner scn=new Scanner(System.in); String plainText,cipherText; int key; System.out.println("Enter Plaintext message:"); plainText=scn.nextLine(); System.out.println("Enter key for Encry...