Advertisement
Guest User

Encrypted.java

a guest
May 22nd, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. import java.util.*;
  2. public class EncryptedGrid {
  3.  
  4. private List<Character> grid = new ArrayList<>();
  5. private String keyword;
  6.  
  7. /**
  8. * Constructor of the EncryptedGrid class
  9. * @param plaintext - the plaintext we wish to encrypt, already with all lowercase and now punctuation
  10. * @param keyword - the keyword, already in all lowercase
  11. */
  12. public EncryptedGrid(String plaintext, String keyword) {
  13. this.keyword = keyword;
  14.  
  15. // calculates length of grid arraylist to be the least multiple of keyword length greater than
  16. // the cipher text length
  17. int gridLength = plaintext.length() + keyword.length() - (plaintext.length() % keyword.length());
  18.  
  19. for(int i=0; i<plaintext.length(); i++) {
  20. grid.add(plaintext.charAt(i));
  21. }
  22.  
  23. for(int i=plaintext.length(); i<gridLength; i++) {
  24. grid.add('x');
  25. }
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement