diff --git a/ciphers/ColumnarTranspositionCipher.java b/ciphers/ColumnarTranspositionCipher.java new file mode 100644 index 000000000000..b12743715984 --- /dev/null +++ b/ciphers/ColumnarTranspositionCipher.java @@ -0,0 +1,169 @@ +/** + * Columnar Transposition Cipher Encryption and Decryption. + * @author freitzzz + */ +public class ColumnarTranspositionCipher { + private static String keyword; + private static Object[][] table; + private static String abecedarium; + public static final String ABECEDARIUM="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,.;:-@"; + private static final String ENCRYPTION_FIELD="≈"; + private static final char ENCRYPTION_FIELD_CHAR='≈'; + /** + * Encrypts a certain String with the Columnar Transposition Cipher Rule + * @param word Word being encrypted + * @param keyword String with keyword being used + * @return a String with the word encrypted by the Columnar Transposition Cipher Rule + */ + public static String encrpyter(String word,String keyword){ + ColumnarTranspositionCipher.keyword=keyword; + abecedariumBuilder(500); + table=tableBuilder(word); + Object[][] sortedTable=sortTable(table); + String wordEncrypted=""; + for(int i=0;iword.length()/keyword.length()){ + return (word.length()/keyword.length())+1; + }else{ + return word.length()/keyword.length(); + } + } + private static Object[] findElements(){ + Object[] charValues=new Object[keyword.length()]; + for(int i=0;i(int)table[0][j]){ + Object[] column=getColumn(tableSorted,tableSorted.length,i); + switchColumns(tableSorted,j,i,column); + } + } + } + return tableSorted; + } + private static Object[] getColumn(Object[][] table,int rows,int column){ + Object[] columnArray=new Object[rows]; + for(int i=0;i>> "+wordBeingEncrypted); + System.out.println("Word encrypted ->>> "+ColumnarTranspositionCipher.encrpyter(wordBeingEncrypted,keywordForExample)); + System.out.println("Word decryped ->>> "+ColumnarTranspositionCipher.decrypter()); + System.out.println("\n### Encrypted Table ###"); + showTable(); + } +}