KeeganT

Rebel Cipher

Mar 8th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | None | 0 0
  1. package rebelcypher;
  2. import java.io.File;
  3. import java.io.FileNotFoundException;
  4. import java.util.Scanner;
  5.  
  6. public class RebelCypher
  7. {
  8.     public static void main(String[] args) throws FileNotFoundException
  9.     {
  10.         Scanner sc=new Scanner(new File("data.txt"));
  11.         String stolen=sc.nextLine();
  12.         String encrypted=sc.nextLine();
  13.         String decode=sc.nextLine();
  14.         String alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ ";
  15.         String decodedMessage="";
  16.         char[] encryptedArray=encrypted.toCharArray();
  17.         char[] decodeArray=decode.toCharArray();
  18.         char[] alphabetArray=alphabet.toCharArray();
  19.         String newAlphabet="";
  20.         for(int c=0;c<27;c++)
  21.         {
  22.             for(int x=0;x<stolen.length();x++)
  23.             {
  24.                 if(stolen.indexOf(alphabetArray[c])!=-1)newAlphabet+=encryptedArray[stolen.indexOf(alphabetArray[c])];
  25.                 else newAlphabet+='.';
  26.                 break;
  27.             }
  28.         }
  29.         for(int c=0;c<decode.length();c++)
  30.         {
  31.            if(newAlphabet.indexOf(decodeArray[c])==-1)decodedMessage+='.';
  32.            else decodedMessage+=alphabetArray[newAlphabet.indexOf(decodeArray[c])];
  33.         }
  34.         System.out.println("Regular Alphabet: "+alphabet);
  35.         System.out.println("Decoded Alphabet: "+newAlphabet);
  36.         System.out.println("Message to Decode: "+decode);
  37.         System.out.println("Decrypted Message: "+decodedMessage);
  38.     }  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment