Data Encryption Standard (Java)

import java.util.*;
import java.io.*;
class des
{

static int ip[] = new int[] {2,6,3,1,4,8,5,7};
static int ip_inv[] = new int[] {4,1,3,5,7,2,8,6};
static int p_4[] = new int[] {2,4,3,1};
static int p_10[] = new int[] {3,5,2,7,4,10,1,9,8,6};
static int p_8[] = new int[] {6,3,7,4,8,5,10,9};
static int left_one[] = new int[] {2,3,4,5,1,7,8,9,10,6};
static int left_two[] = new int[] {3,4,5,1,2,8,9,10,6,7};
static int expand[] = new int[] {4,1,2,3,2,3,4,1};
static int sbox0[][] = new int[][] {{1,0,3,2},{3,2,1,0},{0,2,1,3},{3,1,3,2}};
static int sbox1[][] = new int[][] {{0,1,2,3},{2,0,1,3},{3,0,1,0},{2,1,0,3}}; Continue reading “Data Encryption Standard (Java)”

Basic OTP (Java)

import java.util.*; class TimeOutTask extends TimerTask { boolean isTimedOut = false; public void run() { isTimedOut = true; } } class BasicOTP { public static void main(String args[]) { Random r = new Random(); String otp = new String(); for(int i=0 ; i<8 ; i++) { otp += r.nextInt(10); } System.out.println(otp); TimeOutTask task = new TimeOutTask(); Timer t = new Timer(); t.schedule(task, 10000L); ClientThread c … Continue reading Basic OTP (Java)

OTP Client (Java)

import java.util.*; import java.io.*; import java.net.*; class OTPClient { public static void main(String args[]) throws IOException { Scanner scan = new Scanner(System.in); System.out.println(“Connecting to the server…”); Socket clientSocket = new Socket(“localhost”, 7777); PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true); BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); // Client enters ID. This will be used by the program for verifying who // is communicating as well as check … Continue reading OTP Client (Java)

OTP Server (Java)

import java.util.*; import java.io.*; import java.net.*; class TimeOutTask extends TimerTask { boolean isTimedOut = false; public void run() { isTimedOut = true; } } class OTPServer { public static void main(String args[]) throws IOException { ServerSocket serverSocket = new ServerSocket(7777); System.out.println(“Server running and waiting for client…”); Socket clientSocket = serverSocket.accept(); PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true); BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); // Server waits … Continue reading OTP Server (Java)

CAPTCHA Client (Java)

import java.util.*; import java.io.*; import java.net.*; import java.awt.*; import java.awt.image.*; import javax.swing.*; import javax.imageio.*; class ImagePanel extends JPanel { BufferedImage img; ImagePanel(BufferedImage img) { this.img = img; } public void paint(Graphics g) { g.drawImage(img, 0, 0, this); } } class CaptchaClient { static BufferedImage img; public static void main(String args[]) throws Exception { JFrame frame = new JFrame(); Scanner scan = new Scanner(System.in); System.out.println(“Connecting to … Continue reading CAPTCHA Client (Java)