How to write a java program that would encrypt the entered letter / set of letters according to the table? Example: PRIVET = |> | 2 | / 37 
- Describe what you have knowledge of the theory of algorithms and the language itself - JVic
- It is difficult to write a program. Show what you have already written? - Roman C
- 2" How to write a program ": 1. Come up with an algorithm. 2. To study the functions of the language that are needed for implementation. 3. implement. 4. debug. Actually, what is your question, which of the steps causes difficulties and which ones - Mike
|
1 answer
Very interesting task)) I offer you my option:
class Encryptor { private static final Map<String, String> keys = new HashMap<>(); static { keys.put("A", "4"); keys.put("B", "13"); keys.put("C", "("); } public String encrypt(final String message) { StringBuilder builder = new StringBuilder(); for(int i = 0; i < message.length(); i++) { for(Map.Entry<String, String> entry: keys.entrySet()) { if(message.charAt(i) == entry.getKey().charAt(0)) { builder.append(entry.getValue()); } } } return builder.toString(); } } Use it like this:
Encryptor encryptor = new Encryptor(); System.out.println(encryptor.encrypt("ABC")); Immediately, I note that this option is the simplest implementation. This is more like food for thought to you)))
- thanks for the reply - kanjo19
|