Quote:/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package javaapplication7; import java.io.File; import java.util.Scanner; /** * * @author Ragunath Gunasekaran */ public class JavaApplication7 { /** * @param args the command line arguments */ public static void main(String[] args) throws Exception { Scanner in = new Scanner(System.in); Scanner file = new Scanner(new File("C:/Users/Ragunath Gunasekaran/Desktop/sample/file.txt")); System.out.println("Enter the key : "); // TIMER START long startTime = System.currentTimeMillis(); long total = 0; for (int i = 0; i < 10000000; i++) { total += i; } String key = in.nextLine().toUpperCase(); String input=""; while(file.hasNext()) input+=file.nextLine().toUpperCase(); System.out.println("PlainText : "+input); String cipher=""; for(int i=0;i<input.length();i++) { char c = input.charAt(i); if(c>='A'&&c<='Z') { c=(char)(c+(key.charAt(i%key.length())-'A')); // if(c<'A')c+=26; if(c>'Z')c-=26; } cipher+=c; } System.out.println("CipherText : "+cipher); String plaintext1 = ""; for(int i=0;i<cipher.length();i++)> { char c = cipher.charAt(i); if(c>='A'&&c<='Z') { c=(char)(c-(key.charAt(i%key.length())-'A')); if(c<'A')c+=26; // if(c>'Z')c-=26; } plaintext1 +=c; } System.out.println("PlainText : "+plaintext1); // TIMER Run time & Print long stopTime = System.currentTimeMillis(); long elapsedTime = stopTime - startTime; System.out.println("Runtime"+elapsedTime); //TIME FINISH -Result Finish } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)