この暗号化アルゴリズムは私の自由な時間に数日間書いていますが、最終的には動作していると思っていましたが、私は文字のシフトのためにサイクリングキーで置換を実行するように設定しました。問題は、翻訳されている1文字だけが切り捨てられていることです。 復号化コードは以下の通りです:!復号化プログラムに奇妙なバグがあります
import java.util.Scanner;
import java.io.*;
/* File CycleDeCipher.java*/
public class CycleDeCipher
{
public static void main(String[] args)
{
new CycleDeCipher();
}
public CycleDeCipher()
{
String plainTxt;
Scanner in = new Scanner(System.in);
System.out.println("This program decrypts My Cyclical Substitution Algorithm. v0.2");
System.out.println("Enter a multi digit number : ");
Long mainKey = new Long(in.nextLong());;
System.out.print("Enter your Cipher Text message :");
in.nextLine();
plainTxt = new String(in.next());
in.nextLine();
int[] keys = longParser(mainKey);
String cipherTxt="";
int j = 0;
while(j < plainTxt.length())
{
cipherTxt+=decryptCharacter(plainTxt.charAt(j),keys[j%4]);
j++;
System.out.println("char number " + j + " successfully translated!");
}
System.out.println("Your text is translated to :"+cipherTxt.toUpperCase());
}
private String decryptCharacter(Character ch, int key)
{
System.out.println("Decrypting character "+ch.toString() + " with key "+key);
if(Character.isLetter(ch)){
ch = (char) ((int) Character.toLowerCase(ch) - key%10);
}
else {
ch = (char) ((int) ch-key%10);
}
return(ch.toString());
}
public int[] longParser(Long key)
{
System.out.println("Parsing long to crypto keys...");
int i = 0;
int[] result;
String sInput = new String(key.toString());
char[] keys = new char[sInput.length()];
for(i = 0; i < sInput.length(); i++)
{
keys[i] = sInput.charAt(i);
}
i = 0;
result = new int[sInput.length()];
for(i=0; i<keys.length; i++)
{
result[i] = (int) keys[i];
}
return result;
}
}
The input I gave it that broke the program was
123089648734
キーとして 、および R EWW'U(
AO)TP(MO \ QAU)暗号文として 。それは私がそれを行うにはしたくない
に出てくるはずです! `
を、私はちょうどそれがそれらの答えをあきらめていないので、誰もがコードを修正することができるかどうかを知りたいです。
「私はコードフォーマットが私が持っていた方法でここに来ているかどうかわからない」質問のテキスト領域のすぐ下に入力すると、プレビュー画面が表示されます。あなたはそれを使ってあなたの質問をフォーマットすることができます。 – Nishant
私はそれに取り組んでいました。私は数回編集して修正しました。ごめんなさい。 –