irishstorm

EncodeText

Dec 17th, 2015
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.45 KB | None | 0 0
  1. public static void EncodeText()
  2.     {
  3.         Random rand = new Random();
  4.         Scanner input = new Scanner(System.in);
  5.         String alphabet[] = {"a","b","c","d","e","f","g","h","i","j","k","j","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
  6.         int key[] = new int[4];
  7.         boolean isKeySet = false;
  8.  
  9.         //  Generate Random key.
  10.         if(!isKeySet)
  11.         {
  12.             for(int i = 0; i < key.length; i++)
  13.             {
  14.                 key[i] = rand.nextInt(26);
  15.  
  16.                 System.out.print("Key["+ i + "] - " + key[i]);
  17.             }          
  18.         }
  19.  
  20.         // We Enter text to be encoded and pull the corresponding positions out of the array.
  21.         System.out.print("\nEnter Message : ");
  22.         String plaintext = input.next();
  23.  
  24.         String parts[] = plaintext.split("");
  25.         //int index[] = new int[parts.length];
  26.  
  27.         //  We want to compare the alphabet to parts and pull out the position of any matches
  28.         //  Iterate tru the array
  29.         //  compare both arrays
  30.         //  get position and store them in an array?
  31.         for(int x = 0; x < alphabet.length; x++)
  32.         {
  33.             for(int y = 0; y < parts.length; y++)
  34.             {
  35.                 if( alphabet[x] == parts[y] )
  36.                 {
  37.                     //index[x] = y;
  38.                     System.out.println("Match Found : letter [" + alphabet[x] + "]");
  39.                 }
  40.             }
  41.         }
  42.     }
Add Comment
Please, Sign In to add comment