欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

****实验Lab2

程序员文章站 2022-04-26 10:01:30
...

赞赏码 & 联系方式 & 个人闲话

****前言

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:

****实验Lab2

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:还原加密逆过程-解密

解密流程如下图所示:

****实验Lab2

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”这几种搭配。带着这种想法寻找答案,不难发现正确的破译答案。

****实验Lab2

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

 

闲话

这次实验实际上是在网站上当堂做题考试,事先没有通知,不同难度等级算不同积分,最后计算总分(我们队记得好像是第一吧,多亏两位队友解决了大部分题,让我有充足的时间啃下两道难题)但更重要的是,杨明老师,当初说好的

没 有 考 试 呢

相关标签: ****