1. lab2の内容は、前回のクラス演習の内容です。行った質問を実験レポートに記入してください。手順を説明する必要がある場合は、クラス演習のWebサイトにアクセスして、いくつかの質問を見つけることもできます。
最初の質問、01-番号シーケンス
この質問の冒頭で、ファクタリングを試みましたが、結果は見つかりませんでした。前の質問を完了した後、前の質問の後の素数の文字列に触発され、これらの番号と番号の文字列が1だけ異なることがわかりました。素数が1減算され、40 = 41-1であり、41の後の最初の素数は43であるため、次の数は42であることが発見されました。
質問2.02-番号シーケンス-パート2
与えられた数がすべて5の倍数であることは簡単にわかります。5で割ると2、3、5、7、11、13、17、19、23になり、すべてが素数であり、順番に配置されていることがわかります。 、したがって、次の2つの数値は29 5 = 145、31 5 = 155になります。
質問3:番号シーケンス–パート3
最初はこの数が大きくなり、次に小さくなるのを見ました。最初の反応は二次関数でしたが、そうではないことがわかりました。次に、最初の2つの数値が4,16であり、前の数値の2乗だと思いましたが、後者は256ではなく37であり、これより小さくすることはできませんでした。したがって、それが各桁の2乗の合計であるかどうかを推測し、16 = 4 4,37 = 6 6 + 1 1,58 = 7 7 + 3 3であることがわかります。したがって、次は5 5 + 8 8 = 89,8 8 +9になります。9 = 145であり、計算により1 1 + 4 4 + 5 5 = 42,4 * 4 + 2 + 2 = 20であることがわかりました。これにより、このルールが確認されます。したがって、これら2つの数値は89,145になります。
4番目の質問:番号シーケンス–パート4
一見、最初の数個は少し特別だと思います。特に101、101自体は素数であり、何も考えることはありませんが、100 + 1に等しいので、残りの数から1を引いて0,1を取得します。 、9、?、100、225、?、784、?、2025、?
既知の数値はすべて正方形の数値であり、0、1、3、および?、10、15 、?、28、?、45、?の二乗、そしてこれらの数字の間の関係を探すと、1 = 0 + 1,3 = 1 + 2,15 = 10 + 5であり、最初の疑問符の数字と2つの隣接する数字の間にあるはずです。特定の接続があるため、毎回1つ追加すると推測されるため、最初の疑問符は3 + 3 = 6であり、10は6 + 4と正確に等しく、上記の条件が満たされています。後で確認して、2番目の疑問符は15+である必要があります。 6 = 21、21 + 7 = 28も私たちの推測を満たしています。この時点で、基本的に推測が正しいことは確認できますが、まだ既知の数値があります。次に、28 + 8 = 36、36 + 9 = 45であることを確認します。これも推測を満たしているため、次の数値は次のようになります。間違いなく45+ 10 = 55になる可能性があります。次に、ルールに従って、これらの数値の2乗に1を加算して、疑問符の数値を6 6 + 1 = 37、21 21 + 1 = 442、36 36 + 1 = 1297、55 55 + 1 = 3026の順に取得します。
5番目の質問:
暗号
テキスト:JQRRG、JQRRG、TGKVGT JQRRG、JQRRG、TGKVGT、YGPP GT HCGNNV、FCPP UEJTGKVGT。 。JWORVA FWORVA UCV QP C YCNN JWORVA FWORVA JCF C ITGCV HCNN CNN VJG MKPI'U JQTUGU CPF CNN VJG MKPI'U OGP EQWNFP'V RWV JWORVA VQIGVJGT CICKP
:タイトルは、元のシーザー暗号解読され
たソースコード:
Affine.java
/**
* @Auther:
* @Date: 2018/9/27 18:58
* @Description:
*/
class Affine {
String deciphering(String s, int a, int b){
// 解密的实现
char[] ch = s.toCharArray();
int length = ch.length;// 密文长度
int[] in = new int[length];
for (int i = 0; i < ch.length; i++) {
if(ch[i] == ' '|| ch[i] == '.' || ch[i] == ','||ch[i] == '!'||ch[i] == '\''){
}
else {
in[i] = ch[i] - 97;// 利用ascii变成0-25数字
in[i] = ((in[i] - b) * a) % 62;// 解密算法
if (in[i] < 0) {
in[i] += 62;
}
ch[i] = (char) (in[i] + 97);// 将数字变成字母
}
}
return String.valueOf(ch);// 将字符串数字变成String类型的字符串,返回
}
}
Test.java
import First.Arithmetic;
import java.util.Scanner;
/**
* @Auther:
* @Date: 2018/9/27 19:36
* @Description:
*/
public class Test {
public static void main(String[] args) {
Arithmetic arithmetic = new Arithmetic();
final int MOD = 26;
int [] gcd = new int[12];
int m = 0;
String out = null;
for(int i=1;i<MOD;i++){
//求与26互素的数
if((arithmetic.euclid(i,MOD)) == 1) {
//求这些数mod26的逆,并把它加入gcd数组
gcd[m] = (arithmetic.euclid_2(i,MOD)+26)%26;
m++;
}
}
Scanner input = new Scanner(System.in);
System.out.println("请输入需要解密的密文:");
// 输入密文
String s = input.nextLine();
Affine affine = new Affine();
int k =1;
for(int i=0;i<12;i++) {
for (int j = 0; j < 26; j++) {
out = affine.deciphering(s.toLowerCase(), gcd[i], j);
//System.out.println("第"+k+"条明文为:"+out);
System.out.println("第"+k+"条明文为:"+out.toUpperCase());
k++;
}
}
}
}
実験結果のスクリーンショット:
復号化されたテキスト:HOPPE、HOPPE、REITER HOPPE、HOPPE、REITER、WENN ER FAELLT、DANNSCHREITER。FAELLTERIN DEN GRABEN、FRESSEN IHN DIE RABEN、FAELLT ER IN DEN SUMPF、DANN MACHT DER REITER PLUMPS! DUMPT ?? HUMPT ?? DUMPT ?? SAT ON A WALL HUMPT ?? DUMPT ??すべての王の馬とすべての王の男性がHUMPTを入れられなかった??
これらは2つのドイツの子供の歌です、質問の入力プロンプトは次のとおりです。この課題の解決策は、プレーンテキストのドイツ語部分の最後の単語であり、大文字で入力する必要があります。正解は次のとおりです。PLUMPS。
質問6:17-templer-03-ja
最初にこの質問を翻訳し、次の情報を取得します。まず、すべてのスペースがプレーンテキストから削除されます。次に、メッセージをキーと同じ長さのブロックに分割します。この場合、ブロック長は7文字です。最後に、各ブロックは個別に暗号化されます。例:プレーンテキストは郵便の顧客です。7文字のブロックに分割された後、postalcustomerを生成します。この例では、キーは7531426です。これは、最初の文字が7番目の位置に移動し、2番目の文字が5番目の位置に移動することを意味します。したがって、次のメッセージはtlsaocpoetmsruです。したがって、暗号テキストはtlsaocpoetmsruです。
したがって、ブルートフォース法を使用して7の可能な因数分解力をリストし、最初の7つの単語に基づいて大まかな推測を行います。
暗号テキストは次のとおりです。
ydonoaT4ethh1tpStefeo1e30brmKuinor7saighsgndareanwsaretr-N-aatrsityangdaalunopelaTmltwhnsirexptecoonuaoYibteceorrtedpuaet13nhoOocthft1e30broaBck(l7aiy)rdFodnvncadtasceitriceehrobeyusinngogllniqadssdseiauncfisoteadTctsyraleohbaerhmcesntasheadlelsrtstteealdmalotiransiovffietweitcsichhatehoeopgtretmonhennotadnrfeteobrmnieohtohegfnOtct3h11e30brotnosad7tilyrctolwtolfsitrenhotnsciuaninotctthedoeIrfyodwifltuaoyrouamoveesslreewihrtabnulelcredpendtwaneeaorrefv-T-assektecdanfeyoroalsvereufnaiadstoountleestdrneaoumtileorwlrznedaigclefoipTchereoaplsoePlinowlokayobctlhipPiuaVsdIhpoepevleoiwnhsdtregtasiellhwyhtePutpnedepuosrsuperwHileerehattrlstplnoeaFnctriucrcsheinnsadhtgeaiateossrcpetgrnhosnofudotriceehhneeitstnhaetvPhoptetlastfieciondsoenhiiutpuorspsyooufrtnloteyRethenhooothpfl-拍車-erofayutnhthtiiawleonesnsaterymoudandobeLrrytouihw
暗号テキストの最初の7文字から、Tが最初の文字であると推測でき、最初の文字が今日であると大まかに推測できます。最後に、ブラストによって取得したすべてのプレーンテキストで次のコードを取得し、結果をtxtファイルに保存します。 。
総当たりのJAVAコードは次のとおりです
。Post.java
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class Post{
/** @list存储全排列的所有可能性
*/
public static List<String> list;
public static void permutation(int[] array, int index) {
if (index > array.length) {
return;
}
if (index == array.length) {
StringBuilder b = new StringBuilder();
for (int i = 0; i < array.length; i++) {
b.append("" + array[i]);
}
list.add(b.toString());
}
for (int i = index; i < array.length; i++) {
swap(array, index, i);
permutation(array, index + 1);
swap(array, index, i); // 再次交换,保持原状
}
}
private static void swap(int[] array, int index, int target) {
int tmp = array[index];
array[index] = array[target];
array[target] = tmp;
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
while (scan.hasNext()) {
int n = scan.nextInt();
int array[] = new int[n];
for (int i = 0; i < array.length; i++) {
array[i] = scan.nextInt();
}
list = new ArrayList<String>();
permutation(array, 0);
Collections.sort(list);
String str1="ydonoaT4ethh1tpStefeo1e30brmKuinor7saighsgndareanwsaretr-n-aatrsityangdaalunopelaTmltwhnsirexptecoonuaoYibteceorrtedpuaet13nhoOocthft1e30broaBck(l7aiy)rdFodnvncadtasceitriceehrobeyusinngogllniqadssdseiauncfisoteadTctsyraleohbaerhmcesntasheadlelsrtstteealdmalotiransiovffietweitcsichhatehoeopgtretmonhennotadnrfeteobrmnieohtohegfnOtct3h11e30brotnosad7tilyrctolwtolfsitrenhotnsciuaninotctthedoeIrfyodwifltuaoyrouamoveesslreewihrtabnulelcredpendtwaneeaorrefv-t-assektecdanfeyoroalsvereufnaiadstoountleestdrneaoumtileorwlrznedaigclefoipTchereoaplsoePlinowlokayobctlhipPiuaVsdIhpoepevleoiwnhsdtregtasiellhwyhtePutpnedepuosrsuperwHileerehattrlstplnoeaFnctriucrcsheinnsadhtgeaiateossrcpetgrnhosnofudotriceehhneeitstnhaetvPhoptetlastfieciondsoenhiiutpuorspsyooufrtnloteyRethenhooothpfl-spur-erofayutnhthtiiawleonesnsaterymoudandobeLrrytouihw";
System.out.println(str1.length());
for (String str : list) {
int order[]=new int [7];
for(int i1=0;i1<7;i1++)
{
order[i1]=str.charAt(i1)-49;
}
StringBuilder str3=new StringBuilder();
int len=0;
for(int i1=0;i1<str1.length()-7;i1=i1+7)
{
String str2=str1.substring(i1, i1+7);
for(int j=0;j<7;j++)
{
str3.append(str2.charAt(order[j]));
}
len=i1;
}
FileWriter fw = null;
try {
//如果文件存在,则追加内容;如果文件不存在,则创建文件
File f=new File("D:/123/a.txt");
fw = new FileWriter(f, true);
} catch (IOException e) {
e.printStackTrace();
}
PrintWriter pw = new PrintWriter(fw);
pw.println(str3);
pw.println(str);
pw.flush();
try {
fw.flush();
pw.close();
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(str3);
System.out.println(str);
}
}
}
}
最初の文字に従ってTで始めると、Todayという単語は次のプレーンテキストを見つけます。
プレーンテキストは次のとおりです。
Todayonthe14thofSeptember1307ourKinghassignedanarrestwarrant-againstyouandallTemplarswithnoexceptionYouaretobecapturedonthe13thofOctober1307(ブラックフライデー)andconvictedashereticsyourbelongingsandliquidassetsconfiscatedTheroyalchamberhassentsealedletterstoalladministrativeofficeswiththechargetoopenthemonandnotbeforethemorningofthe13thOctober1307andtostrictlyfollowtheinstructionscontainedtothewordIfyoufailtoarmyourselvestherewillbeanunprecedentedwaveofarrests-andtakecareofyourselvesandfailnottounderestimateourwellorganizedpoliceforceThePopealsowillnotbackyouPhilippIVhasdevelopedhisownstrategyhewillputthePopeunderpressureHewillthreatentosplitFranceschurchandinstigateaprocessonthegroundsofhereticsintheeventthatthePopefailstodiscontinuehissupportforyouRelynotonthehelpofothers-putyourfaithintheownalertnessandmayourLordbewithyou
タイトルの問題は、騎士がすべての信仰をどのように置くべきかということです。
課題を解決するには、この名詞を入力してください。
大文字のみを使用してください。解決策の最終的な答えはアラートです。