Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class EncryptedGrid {
- private List<Character> grid = new ArrayList<>();
- private String keyword;
- /**
- * Constructor of the EncryptedGrid class
- * @param plaintext - the plaintext we wish to encrypt, already with all lowercase and now punctuation
- * @param keyword - the keyword, already in all lowercase
- */
- public EncryptedGrid(String plaintext, String keyword) {
- this.keyword = keyword;
- // calculates length of grid arraylist to be the least multiple of keyword length greater than
- // the cipher text length
- int gridLength = plaintext.length() + keyword.length() - (plaintext.length() % keyword.length());
- for(int i=0; i<plaintext.length(); i++) {
- grid.add(plaintext.charAt(i));
- }
- for(int i=plaintext.length(); i<gridLength; i++) {
- grid.add('x');
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement