import java.util.Scanner; import java.io.*; public class caesarC{ public static void main(String [] args) { String l="abcdefghijklmnopqrstuvwxyz"; int k; // String p; try{ Scanner in = new Scanner(System.in); String s,output=""; System.out.print("plz enter key !!"); k=in.nextInt(); BufferedReader reader =new BufferedReader(new FileReader("ss.txt")); while((s=reader.readLine())!=null) { output+=s; String cipher = Encrypt(output,k,l); System.out.print("file to encrypt: "+cipher); } } catch(FileNotFoundException ex ) { ex.printStackTrace(); } catch(IOException e) { e.printStackTrace(); } } public static String Encrypt(String str,int key,String l) { String enc=""; for (int i=0;i<str.length();i++) { char c = str.charAt(i); if(c==' ') { enc+=' '; continue; } int ind=l.indexOf(c); int npos=(ind+(key*i+1))%26; enc +=l.charAt(npos); } return enc; } }
new FileReader(new File("ss.txt"));
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)