mardi 15 février 2022

Encrypt a Paragraph of Text in Java

I am trying to make a game where a paragraph of text is “encrypted” using a simple substitution cipher, so for example, all A's will be F's and B's will be G's an so on. The idea is that the user/player will need to try to guess the famous quote by trying to decrypt the letters. So the screen shows them a blank space with a letter A and they have to figure out it's really an F that goes in the place within the string. I've not got very far, basically I can manually change each letter using a for loop, but there must be an easier way.

import java.util.Scanner;
import java.util.Random;

public class cryptogram {
    

    public static void main(String[] args) {
        
        char[] alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
        
        for (char i = 0; i <alphabet.length; i++) {
            if (alphabet[i] == 'B') {
                    alphabet[i] = 'Z';
            }
        }
        System.out.println(alphabet);
    }
}



Aucun commentaire:

Enregistrer un commentaire