All pastes #195863 Raw Edit

Someone

public text v1 · immutable
·published 2006-10-10 03:36 UTC
rendered paste body
import java.io.*;
import java.text.*;
import java.lang.*;
import java.util.*;
public class N4
{
    public static String finalString = "";
    public static String tempString = "";
    public static String scrambledAlpha = "";
    public static String result = "";
    public static void main (String [] args) throws IOException
    {

        String command;
        String keyword;
        String file;

        String string = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

        BufferedReader in = new BufferedReader (new InputStreamReader (System.in));

        while (true)
        {

            result = "";
            finalString = "";
            tempString = "";

            System.out.println ("Enter e for encipher, d for decipher");
            command = in.readLine ();
            System.out.println ("Enter keyword");
            keyword = in.readLine ().toUpperCase ();
            System.out.println ("Enter name for source file");
            file = in.readLine ();
            if (command.equals ("e"))
            {
                e (keyword, file);

                System.out.println (finalString);
                System.out.println (keyword + " " + result);

            }


        }




    }



    //Adds the keyword to the alphabet and removes any duplicate letters.
    public static String makeAlpha (String keyword, String finalString)
    {

        while (keyword.length () != finalString.length ())
        {
            if (keyword.length () > finalString.length ())
            {
                keyword = keyword.substring (0, finalString.length ());
            }
            if (keyword.length () < finalString.length ())
            {
                keyword += keyword;
            }
        }
        return keyword;
    }


    //Encipher
    public static void e (String keyword, String file) throws IOException
    {
        BufferedReader in;
        in = new BufferedReader (new FileReader (file));

        while ((tempString = in.readLine ()) != null)
        {


            finalString = finalString.concat (tempString.toUpperCase ());

        }

        scrambledAlpha = (makeAlpha (keyword, finalString));

        for (int i = 0 ; i < finalString.length () ; i++)
        {

            result += (char) ((finalString.charAt (i) + scrambledAlpha.charAt (i) - 130) % 26 + 65);

       
        }

    }



}