逆向工程實驗Lab2

讚賞碼 & 聯繫方式 & 個人閒話

逆向工程前言

Lab2

1、(LEVEL Ⅰ)Number sequence:What is the next number in this sequence?

1 - 2 - 4 - 6 - 10 - 12 - 16 - 18 - 22 - 28 - 30 - 36 - 40 - ?

How did you find the solution?

Step1:分析題目要求

求解數字序列接下來的一個數字。

Step2:找出數字序列的規律

所求數字序列的每一個數字都是質數序列的數字減1得到的:

1=2-1;

2=3-1;

4=5-1;

6=7-1;

……

40=41-1;

所以:

第14個數字=42=43-1

Step3:獲得完整的數字序列

1 - 2 - 4 - 6 - 10 - 12 - 16 - 18 - 22 - 28 - 30 - 36 - 40 - 42

 

 2、(LEVEL Ⅰ)Number Sequence-Part2:What are the next two numbers in this sequence?

10 - 15 - 25 - 35 - 55 - 65 - 85 - 95 - 115 - ? - ?

Please hand in the two numbers separated by a comma (and with no blank).

Step1:分析題目要求

求解數字序列接下來的兩個數字。

Step2:找出數字序列的規律

質數序列的各個數字×5可以得到本題的數字序列:

10=2×5;

15=3×5;

25=5×5;

35=7×5;

……

115=23×5;

所以:

第10個數字=29×5=145

第11個數字=31×5=155

Step3:獲得完整的數字序列

10 - 15 - 25 - 35 - 55 - 65 - 85 - 95 - 115 - 145 - 155

 

 3、(LEVEL Ⅰ)Number Sequence-Part3:See if you can work out the missing two numbers in the following sequence:

4 - 16 - 37 - 58 - ? - ? - 42 - 20 - ... goes back to the start!

In your answer please separate the first and the second number by a comma.

Step1:分析題目要求

求解數字序列中缺失的兩個數字。

Step2:找出數字序列的規律

後一個數是前一個數各位數字的平方和:

16=42;

37=12+62;

58=32+72;

……

所以:

第5個數字=52+82=89

第6個數字=82+92=145

Step3:獲得完整的數字序列

4 - 16 - 37 - 58 - 89 - 145 - 42 - 20

 

4、(LEVEL Ⅰ)Number Sequence-Part4See if you can work out the missing four numbers in the following sequence:

1 - 2 - 10 - ? - 101 - 226 - ? - 785 - ? - 2026 - ? - ...

In your answer please separate the numbers only by a comma.

Step1:分析題目要求

求解數字序列中缺失的四個數字。

Step2:找出數字序列的規律

後一個數字減前一個數字的差恰好是遞增的正整數序列(1、2、3...)的三次方:

2-1=13;

10-2=23;

第4個數-10=33;(第4個數=37)

101-37=43;

226-101=53;

第7個數-226=63;(第7個數=442)

785-442=73;

第9個數-785=83;(第9個數=1297)

2026-1297=93;

第11個數-2026=103(第11個數=3026)

Step3:獲得完整的數字序列

1 - 2 - 10 - 37 - 101 - 226 - 442 - 785 - 1297 - 2026 - 3026

 

 5、(LEVEL Ⅰ)Number Sequence-Part8The first ten numbers of a certain infinite sequence are:

3 - 5 - 11 - 17 - 31 - 41 - 59 - 67 - 83 - 109 - ? - ? - ?

Determine the next three numbers in this sequence.

As solution please enter the three numbers separated by a comma (and without spaces).Hint: Prime numbers are involved.

Step1:分析題目要求

求解數字序列接下來的三個數字。

Step2:找出數字序列的規律

第i位數是第n(i)位質數(其中,n(i)表示從小到大順序排列的質數)

3:第2位質數;

5:第3位質數;

11:第5位質數;

17:第7位質數;

……

109:第29位質數;

所以:

第11個數是第31位質數:127

第12個數是第37位質數:157

第13個數是第41位質數:179

Step3:獲得完整的數字序列

3 - 5 - 11 - 17 - 31 - 41 - 59 - 67 - 83 - 109 - 127 - 157 - 179

 

6、(LEVEL Ⅰ)THE ORIGINAL CAESAR ENCRYPTIONYour challenge is to decrypt the ciphertext given on the following page.

(Hints:The plaintext is partly German and partly English.The solution to this challenge is the last word of the German part of the plaintext and must be typed in with capital letters.)

Step1:分析明文加密過程

明文由英文和德文組成,經過凱撒加密變成了如下的字符:

JQRRG, JQRRG, TGKVGT
JQRRG, JQRRG, TGKVGT,
YGPP GT HCGNNV, FCPP UEJTGKV GT.
HCGNNV GT KP FGP ITCDGP,
HTGUUGP KJP FKG TCDGP,
HCGNNV GT KP FGP UWORH,
FCPP OCEJV FGT TGKVGT RNWORU!
JWORVA FWORVA
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.

根據題目要求現在要找出明文的最後一個德語單詞。

Step2:編程輸出所有可能的移位結果

凱撒密碼的加密原理就是簡單的移位,所以只要把所有的可能的移位結果列出來(26種),找出最完整的明文就ok了。

代碼如下:

#include<stdio.h>
#include<string.h>

int main() {
	char cipher[] = "JQRRG, JQRRG, TGKVGT;JQRRG, JQRRG, TGKVGT, ;YGPP GT HCGNNV, FCPP UEJTGKV GT.;HCGNNV GT KP FGP ITCDGP, ;HTGUUGP KJP FKG TCDGP, ;HCGNNV GT KP FGP UWORH, ;FCPP OCEJV FGT TGKVGT RNWORU!;JWORVA FWORVA;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.;";
	int i;
	int j;
	char tmp;
	for (i = 0; i < 26; i++) {
		printf("明文(移位%d次):\n", i);
		for (j = 0; j < strlen(cipher); j++) {
			if (cipher[j] == ';') {
				printf("\n");
				continue;
			}
			else if (cipher[j] > 64 && cipher[j] < 91) {
				tmp = cipher[j];
				tmp = tmp - i;
				if (tmp < 65)
					tmp += 26;
				printf("%c", tmp);
			}
			else {
				printf("%c", cipher[j]);
			}
			
		}
		printf("\n\n");
	}
}

Step3:確定偏移量,獲得明文

由輸出結果可以看出,加密選擇的偏移量應爲2:

Step4:確定問題的答案

最後一個德文單詞是:PLUMPS。

 

7、(LEVEL Ⅰ)BEAVER CODEThe following ciphertext has been encrypted using the Beaver Code: TTRNEHEORAVNEWESEAABBTREOT

In order to solve the challenge, you need to decrypt the English sentence, insert spaces at the correct positions and enter the sentence in capital letters (without punctuation marks).

Step1:分析題目要求

題目給出了26個密文字母要求解密,由題可知Beaver Code只是交叉打亂字符順序,並沒有進行增減和替換。所以,我們不難推測出26個字符開始時的組別劃分,按照加密的逆過程即可解密。

Step2:還原加密逆過程-解密

解密流程如下圖所示:

Step3:確定明文

最終得到明文:TWO BEAVERS ARE BETTER THAN ONE

 

8、(LEVEL Ⅱ)LETTER TO THE TEMPLARS PART 3You can find the ciphertext in the file.The letter was written in English.In what should the knights put all their faith?To solve the challenge, please enter this noun. Use only capital letters.

Step1:分析題目要求

仔細分析題目,題意爲去除密文空格後,每7個字符爲一組,每個組內按照某種順序進行打亂即把組內7個字符進行某種全排列,並且每個組的打亂順序是一樣的。其實只要讀懂了這個意思題目就不難了。

Step2:編程輸出所有可能的明文

首先把密文按每7個字符一組進行分組。接着遍歷每種打亂的順序(遍歷所有可能的全排列),這裏一共有7!=5040種。我們只要在其中找出可以輸出完整英文段落的明文即爲破解成功。

代碼如下:

import hashlib
import copy

#遞歸求解1-7的全排列
def permutation(lst,k):
    result = []
    length = len(lst)
    tmp = [0]*k
    def next_num(a,ni=0):
        if ni == k:
            result.append(copy.copy(tmp))
            return
        for lj in a:
            tmp[ni] = lj
            b = a[:]
            b.pop(a.index(lj))
            next_num(b,ni+1)
    c = lst[:]
    next_num(c,0)
    return result

P=permutation([0,1,2,3,4,5,6],7)

SS="ydonoaT4ethh1tpStefeo1e30brmKuinor7saighsgndareanwsaretr-n-aatrsityangdaalunopelaTmltwhnsirexptecoonuaoYibteceorrtedpuaet13nhoOocthft1e30broaBck(l7aiy)rdFodnvncadtasceitriceehrobeyusinngogllniqadssdseiauncfisoteadTctsyraleohbaerhmcesntasheadlelsrtstteealdmalotiransiovffietweitcsichhatehoeopgtretmonhennotadnrfeteobrmnieohtohegfnOtct3h11e30brotnosad7tilyrctolwtolfsitrenhotnsciuaninotctthedoeIrfyodwifltuaoyrouamoveesslreewihrtabnulelcredpendtwaneeaorrefv-t-assektecdanfeyoroalsvereufnaiadstoountleestdrneaoumtileorwlrznedaigclefoipTchereoaplsoePlinowlokayobctlhipPiuaVsdIhpoepevleoiwnhsdtregtasiellhwyhtePutpnedepuosrsuperwHileerehattrlstplnoeaFnctriucrcsheinnsadhtgeaiateossrcpetgrnhosnofudotriceehhneeitstnhaetvPhoptetlastfieciondsoenhiiutpuorspsyooufrtnloteyRethenhooothpfl-spur-erofayutnhthtiiawleonesnsaterymoudandobeLrrytouihw"
print(len(SS))
for k in range(0,len(P)):
    TSS=""
    for i in range(0,len(SS),7):
        S=SS[i+P[k][0]]+SS[i+P[k][1]]+SS[i+P[k][2]]+SS[i+P[k][3]]+SS[i+P[k][4]]+SS[i+P[k][5]]+SS[i+P[k][6]]
        TSS=TSS+S
    print(k,"   ", end='')
print(TSS)

Step3:確定唯一的明文

然而5040種對我們來說單憑肉眼來看還是多了些。我們不妨先來看第一塊的七個字符:ydonoaT。容易看出在句首大概率爲大寫T開頭,那麼可能會有“To do”、“Tony”、“Today”這幾種搭配。帶着這種想法尋找答案,不難發現正確的破譯答案。

Step4:確定問題的答案

明文:

Today on the 14th of September 1307 our King has signed an arrest warrant--against you and all Templars with no exception You are to be captured on the 13th of October 1307 (Black Friday) and convicted a sheretics your belongings and liquid as sets confiscated The royal chamber has sent sealed letters to all administrative offices with the charge to open the monand not before the morning of the 13th October 1307 and to strictly follow the instruction scontained to the word If you fail to army ourselves there will be an unprecedented wave of arrests--and take care of yourselves and fail not tounderes timate our well organized police force The Popealso will not back you PhilippIV has developed his own strategy he will put the Popeunder pressure He will threaten to split Frances church and instigate a process on the grounds of here ticsin the event that the Pope fails to discontinue his support for you Rely not on the help of others--put your faith in the own alertness and may our Lord be with you

問題:“In what should the knights put all their faith?”騎士把所有的信仰放在哪裏?

根據明文我們得出最終答案:ALERTNESS

 

閒話

這次實驗實際上是在網站上當堂做題考試,事先沒有通知,不同難度等級算不同積分,最後計算總分(我們隊記得好像是第一吧,多虧兩位隊友解決了大部分題,讓我有充足的時間啃下兩道難題)但更重要的是,楊明老師,當初說好的

沒 有 考 試 呢

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章