柱状换位密码:如何加密

时间:2018-11-13 09:16:16

标签: java

嗨,我是Java的新手,我正在尝试弄清楚如何创建列式转置密码。如果创建了一个,可以显示它的编码方式。密码通过根据密钥索引找到打印出的列来进行加密。例如,如果键是TAPE,则根据输入字符串的长度,将有4列乘以行数。然后,系统将根据字母表中的第一个字母进行打印,在这种情况下,将先打印列A,然后再打印E,依此类推。我需要知道如何按键顺序打印这些列。我知道如何为输入字符串创建列。任何帮助将不胜感激!!!

import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Collections;
import java.io.PrintWriter;

public class SortEncrypt {
    public static String key;
    public static char sortKey;
    public SortEncrypt(String theKey) {
        key = theKey;
        List<Integer> myList = new ArrayList<Integer>();
        char tempArray[] = key.toCharArray();
        Arrays.sort(tempArray);
        /// I am trying to sort the array and the give the index of the character in the sorted array to the same character of the unsorted array.
    }
    public String encrypt(String theString) {
        String s = theString;
        int x = 0;
        int y = 0;
        for (int i = 0; (i * i) < s.length(); i++) {
            y = i;
            x = i + 1;
        }
        // creates x arraylists 
        List<List<Character>> column = new ArrayList<>();
        for (int i = 0; i < x; i++) {
            column.add(new ArrayList<>());
        }   
    }
}

import java.util.Scanner;

public class TranspositionCipher {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("Please print out a word for a key and a sentence for a string: ");
        SortEncrypt s = new SortEncrypt(sc.nextLine());
    }
}

编辑:

我尝试通过这种方式对密钥进行排序:

import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Collections;
import java.io.PrintWriter;
public class SortEncrypt
{
public static String key;
public static char sortKey;

public SortEncrypt(String theKey){
    key = theKey;
    List<Integer> myList = new ArrayList<Integer>(); 
    char tempArray[] = key.toCharArray();
    Arrays.sort(tempArray);
    String imp = tempArray.toString();
    System.out.println(key);
    System.out.println(tempArray);
    for (int i = 0; i<imp.length();i ++){
       char a_char = imp.charAt(i);
       if (a_char == a_char){
           int a = key.indexOf(a_char);
           myList.add(a);

        }
    }
    System.out.println(myList);
}

0 个答案:

没有答案