Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class main
- {
- public static void main(String[] args)
- {
- encryption("ALGORYTM_PRZESTAWIENIOWY", true);
- encryption("BTLLTU_ĘL_EOYPM_ĄPJZLCYNDREOKYLI_ZMFO_ĄGJY_Ó_N_DEWFWGISYSII_ŁEI", false);
- }
- public static void encryption(String toEncrypt, boolean action)
- {
- int n = (int) Math.ceil(Math.sqrt(toEncrypt.length()));
- char[][] tab = new char[n][n];
- char[][] tab2 = new char[n][n];
- for (int i = 0; i < n; i++)
- for (int j = 0; j < n; j++)
- {
- if (toEncrypt.length() > 0)
- {
- tab[i][j] = toEncrypt.charAt(0);
- toEncrypt = toEncrypt.substring(1);
- }
- else
- tab[i][j] = '_';
- }
- if (action)
- System.out.println("Tablica znaków przed zaszyfrowaniem:");
- else
- System.out.println("Tablica znaków przed odszyfrowaniem:");
- printArray(tab);
- for (int i = 0; i < n; i++)
- for (int j = 0; j < n; j++)
- if (action)
- tab2[i][j] = tab[j][i];
- else
- tab2[j][i] = tab[i][j];
- if (action)
- System.out.println("Tablica znaków po zaszyfrowaniu:");
- else
- System.out.println("Tablica znaków po odszyfrowaniu:");
- printArray(tab2);
- }
- public static void printArray(char[][] array)
- {
- for (int i = 0; i < array.length; i++)
- {
- for (int j = 0; j < array.length; j++)
- {
- System.out.print(array[i][j]);
- if (j != array.length - 1)
- System.out.print(" ");
- }
- System.out.println();
- }
- System.out.println();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment