Writing a Java program to encrypt and decrypt a ADFGVX cipher

有些话、适合烂在心里 提交于 2019-12-13 02:06:08

问题


I need to be able to encrypt and decrypt a message using a Polybius Square. I know how this works on paper but don't know where to start when turning it into a program. I was planning to use a hash map but I was told thats a bad way to go about it and that there are better approaches to do this...but I don't know what approaches that would be.

I've been given code to help me by my lecture from a workshop on the project but I don't fully understand it. I'll paste it below and if anyone could explain it I would greatly appreciate it! I've been focusing on C a lot this past while so now I am a bit rusty when it comes to Java.

char [][] poly = {
    {",'A','B','D'.....
    {'A','P','H','Q'}
}

Thats a double array that I'll be using to sort the Polybius square right?

for(int row = 0; row < poly.length; row++) {
}

for(int col = 0; col < poly[row].length; col++) {
}

// c is the char I'm looking for
if(poly[row][col] == c){
}

This is used for navigating the array and finding the chars I want?

// how to break a line down to a character
String[] words = line.split(" ");
for(int i=0; i < words.length; i++){
    String word = words[i];
    for(int j = 0; j <word.length(); j++){
        char letter = word.charAt(j);
        encrypt(letter);
    }
}

This is breaking a line down to letters obviously? what do I do then? Is the method encrypt in the Java runtime library or do I have to make my own somehow?

I'm not sure where to begin or what would be the best way to go about this, I think I might just watch hash map tutorials and try that? This is my first time trying encryption and the whole thing looks hard and intimidating.

来源:https://stackoverflow.com/questions/29319831/writing-a-java-program-to-encrypt-and-decrypt-a-adfgvx-cipher

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!