I'm making a Random Substitution Cipher in Java. Basically, the program asks you for a sentence, you input the sentence, it takes the sentence and using a randomly generated alphabet, encrypts it. The user has the choice of encrypting or decrypting. The encrypted cipher text is then displayed on screen. If the user chooses so, the program will decrypt the cipher and show the original plain text message.
Here's what I have so far:
Random gen = new Random();
PrintWriter write = new PrintWriter(new File("CryptCode.txt"));
char[] chars = new char[] {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
//'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
char[] cryptList = new char[26];
int tracker = 0;
while(tracker < 26)
{
int num = gen.nextInt(26);
if(cryptList[num] == '\u0000')
{
cryptList[num] = chars[tracker];
tracker++;
}
}
for(int i = 0; i < 26; i++)
{
write.println(chars[i] + " " + cryptList[i]);
}
write.close();
This just generates the random alphabet. I have no idea how I would implement the actual encrypt method though. I can handle the file IO and the prompts to the user on my own. I just can't understand how to go about creating a substitution algorithm. Any help is greatly appreciated. I can probably figure out the decryption method once I have the encryption method in front of me, but as of right now I have no idea how to proceed. Thanks!