Research on Python Assignment Generator#3

python assignment generator v3

题目:每个人会被“随机”分配24个图形,每个图形由四个部分组成,颜色,形状,数字,方向。 如果一个图形带有方向,那么把这个图形根据不同的逻辑判断,送到相应的方向。如果一个图形没有方向,那么不进行任何操作。每个人都有六个颜色逻辑函数,六个形状逻辑函数,一个能否被某数整除函数。

代码部分如下

把原始代码中很难被理解的字母O和数字0组合起来的变量名,换位字母abcd后效果如下:

from os import getcwd as a ,listdir as b ,path as c ,remove as d #line:2
from sys import argv as e #line:3
from zipfile import ZipFile as f #line:4
import textwrap as g #line:5
CURRENT_CLASS_LIST_FILE ="current_class_list.dat"#line:8
LIST_OF_REQUISITE_FILES =[CURRENT_CLASS_LIST_FILE ]#line:9
LIST_OF_LIBRARY_MODULES =["_liberr.py","_libtui.py","_libprg.py",]#line:14

def gen(list):
    for i in range(len(list)):
        bb=generate_assignment_instructions(list[i])
'''
This will remove all the files that were extracted from the companion

@params                      none
@return                      none
'''#line:22
def clean_current_working_directory ():#line:23
	print("hi")
'''
This is end the program after cleaning the current working directory

@params                      none
@return                      none
'''#line:44
def exit_program ():#line:45
	clean_current_working_directory ()#line:46
	exit ()#line:47
'''
This is the actual instruction generator that is specific to this assignment

@params                      none
@return                      none
'''#line:55

def get_first_logic(logic_pre1,index):
	j = ["circle", "square", "diamond", "cross", "triangle", "pentagon"]  # line:62
	str = logic_pre1+j[index]+"(e)"
	return str
def get_second_logic(logic_pre2,index):
	k = ["red", "orange", "green", "blue", "purple", "black"]  # line:63
	return logic_pre2+k[index]+"(e)"
def get_third_logic(logic_pre3,number_str):
	return logic_pre3+"(e,"+number_str+")"

def generate_code(studentnum,pointlist,logic_pre1, logic_pre2, logic_pre3):
	file = open("comp1405_f17_"+studentnum+"_a3.py","w+")
	left_str = ""
	down_str = ""
	right_str =""
	for x in pointlist:
		shape = x.split(",")
		#shape = [a,b,c,d]
		logical_str = ""
		logical_str += "("
		logical_str += get_first_logic(logic_pre1,int(shape[0]))
		logical_str += " and "
		logical_str += get_second_logic(logic_pre2,int(shape[1]))
		logical_str += " and "
		logical_str += get_third_logic(logic_pre3,shape[2])
		logical_str += ")"
		if shape[3] == "0":
			#left
			if left_str != "":
				left_str += " or "
			left_str += logical_str
		elif shape[3] == "1":
			#right
			if right_str != "":
					right_str+= " or "
			right_str += logical_str
		elif shape[3] == "2":
			#down
			if down_str != "":
					down_str += " or "
			down_str += logical_str
	down_str = "	condition_for_sending_down ="+down_str
	left_str = "	condition_for_sending_left =" + left_str
	right_str = "	condition_for_sending_right = " + right_str

	file.write("# ============================================================\n")
	file.write("#                                                             \n")
	file.write("# Student Name (as it appears on cuLearn): Enter Your Name Here\n")
	file.write("# Student ID (9 digits in angle brackets): <" + studentnum + ">\n")
	file.write("# Course Code (for this current semester): COMP1405A\n")
	file.write("#                                                             \n")
	file.write("# ============================================================\n")
	file.write("\n")
	file.write("from comp1405_f17_assistant_a3 import *\n\n")
	file.write("def decision_making_function(e):\n\n")
	file.write(down_str+"\n")
	file.write(left_str+"\n")
	file.write(right_str+"\n\n")
	file.write("	return (condition_for_sending_down, condition_for_sending_left, condition_for_sending_right)\n\n\n")
	file.write("run_the_program(decision_making_function)\n")





def generate_assignment_instructions (h ):#line:56
	print(h)
	import _libprg as _i #line:58
	_i .set_random_source (h )#line:60
	j =["circle","square","diamond","cross","triangle","pentagon"]#line:62
	k =["red","orange","green","blue","purple","black"]#line:63
	l =["is_inside_a_","wrapped_in_a_","is_shaped_like_a_"]#line:64
	m =["is_colored_","color_is_","painted_"]#line:65
	n =["is_divisible_by","evenly_divides_by","divides_evenly_by"]#line:66
	o =l [_i .get_random_integer (0 ,2 )]#line:68
	p =m [_i .get_random_integer (0 ,2 )]#line:69
	q =n [_i .get_random_integer (0 ,2 )]#line:70
	r =[o +s +"(e)"for s in j ]+[p +t +"(e)"for t in k ]+[q +"(e, d)"]#line:72
	u =r .pop ()#line:74
	for v in r :#line:76
		u =u +", "+v #line:77
	w =[]#line:79
	w .append (_i .get_random_shuffle ([x for x in range (10 ,100 )if x %2 ==0 and x %3 !=0 and x %5 !=0 ]))#line:80
	w .append (_i .get_random_shuffle ([y for y in range (10 ,100 )if y %2 !=0 and y %3 ==0 and y %5 !=0 ]))#line:81
	w .append (_i .get_random_shuffle ([z for z in range (10 ,100 )if z %2 !=0 and z %3 !=0 and z %5 ==0 ]))#line:82
	w .append (_i .get_random_shuffle ([aa for aa in range (10 ,100 )if all (aa %ab !=0 for ab in range (2 ,aa ))]))#line:83
	ac =_i .get_random_integer (0 ,2 )#line:85
	ad =w .pop (ac )#line:86
	w =w [0 ]+w [1 ]+w [2 ]#line:87
	ae =_i .get_random_shuffle (list (range (0 ,6 )))[0 :4 ]#line:88
	af =_i .get_random_shuffle (list (range (0 ,6 )))[0 :4 ]#line:89
	ag =[]#line:91
	ag .append ((4 ,1 ,True ))#line:92
	ag .append ((2 ,1 ,False ))#line:93
	ag .append ((3 ,2 ,False ))#line:94
	ag .append ((1 ,1 ,True ))#line:95
	ag .append ((2 ,3 ,False ))#line:96
	ag .append ((3 ,4 ,False ))#line:97
	ag .append ((1 ,4 ,True ))#line:98
	ag .append ((4 ,1 ,False ))#line:99
	ag .append ((1 ,3 ,True ))#line:100
	ag .append ((1 ,2 ,False ))#line:101
	ag .append ((1 ,1 ,False ))#line:102
	ag .append ((1 ,2 ,True ))#line:103
	ag .append ((1 ,2 ,True ))#line:104
	ag .append ((1 ,1 ,True ))#line:105
	ah =ag #line:106
	_ai =[ah .pop (aj )for aj in range (3 ,12 ,3 )]#line:107
	ak =[2 ,3 ,3 ,3 ,3 ,1 ,2 ,2 ,1 ,2 ,2 ]#line:109
	al =[1 ,2 ,2 ,3 ,3 ,4 ,4 ,4 ,4 ,1 ,1 ]#line:110
	am =[0 ,1 ,0 ,1 ,2 ,3 ,2 ,1 ,0 ,2 ,1 ]#line:111
	an =open ("your-assigned-entities-"+str(h)+".dat","w")#line:113
	for v in range (24 ):#line:114
		an .write (str (ag [v %11 ][0 ])+","+str (ag [v %11 ][1 ])+"\n")#line:115
	an .close ()#line:116
	ao =[]#line:118
	for v in range (len (ak )):#line:119
		for ap in range (ak [v ]):#line:120
			ao .append (str ([ae [ag [v ][0 ]-1 ],af [ag [v ][1 ]-1 ],_i .get_random_element (ad *ag [v ][2 ]+w *(1 -ag [v ][2 ])),al [v ]-1 ]).replace (' ',''))#line:121
	an =open ("your-assigned-entities-"+str(h)+".dat","w")#line:123
	shape_list = []
	for v in _i .get_random_shuffle (ao ):#line:124
		an .write (v .strip ("[]")+"\n")#line:125
		shape_list.append(v.strip("[]"))
	an .close ()#line:126
	generate_code(h,shape_list,o,p,q)
	aq =["When you ran the generator it used your student number to create a file called 'your-assigned-entities.dat'. Once you have downloaded the assignment template from cuLearn, place it in the same folder as 'your-assigned-entities.dat' and 'comp1405_f17_assistant_a3.py' (a file you extracted when you extracted the generator). You must rename the assignment template to 'comp1405_f17_#########_a3.py', replacing the hashtags with your nine-digit student number.","You should test out the template by running it from the terminal by typing 'python3 comp1405_f17_#########_a3.py'. If you have done everything correctly you will see a window appear where shapes are falling from the top of the screen and disappearing when they get to the center.","Each falling shape has certain properties (such as the shape, the colour, and the numerical value) that you will be able to test (once the shape reaches the center of the screen) by calling one of the functions that has been provided. Each falling shape might also be associated with a direction (displayed as a yellow arrow under the falling shape).","Virtually all of the programming required for this assignment has already been completed for you - your ONLY task is to create the logical expressions that, once evaluated, will be assigned to the variables condition_for_sending_down, condition_for_sending_left, and condition_for_sending_right.","Each of the logical expressions you create will require that you call some of your assigned functions and use the correct logical operators (i.e., and, or, and not). As a clarifying example, if you were assigned the function 'is_the_falling_shape_red', then you could set... condition_for_sending_left = is_the_falling_shape_red(e) ...and then when you run the program, any falling shape that has the colour red will be directed to the left.","If a falling shape doesn't satisfy any of your three conditions it will disappear when it reaches the center of the screen. The shapes that do not have a yellow arrow underneath them (to indicate their target direction) should be made to disappear in this manner","Every time a falling shape is sent to its correct destination by your conditions, you will receive two points. Your score can be seen in the bottom right corner of the screen. The maximum score that is possible will be 48 (if all your shapes are each sent to their correct destinations), so if your program is able to reach that score you will know you are sorting your shapes correctly.","Please note that you can hold down the space bar to make the shapes fall more quickly while you are testing your submission.","To solve this problem you will need to run the program first and see what shapes you have been assigned (take notes!), then try to deterine what combinations of features should be sent left, right, etc. You might notice, for instance, that any shape that is a red circle or a blue triangle should be directed left.","Your conditions will not be trivial (i.e., they won't ever just require a single call to one of your assigned functions) but they should not be unneccessarily complex either.","You may use the logical operators and, or, and not to construct your conditions. You may also use any or all of the following functions: "+u ,"WARNING: The validator does not check what functions you are using, and if you use a function you are not permitted you will receive a mark of zero even if your program works perfectly. YOUR MUST NOT USE ANY FUNCTION OTHER THAN THE ONES APPEARING IN THE LIST ABOVE!"]#line:141
	return aq #line:143

def main ():#line:154
	clean_current_working_directory ()#line:157
	import _liberr as _av #line:179
	import _libtui as _au #line:180
	_au .clear_screen ()#line:183
	print ()#line:185
	print ("     ** PLEASE NOTE:  IF YOU FAIL TO FOLLOW THESE INSTRUCTIONS PRECISELY **     ")#line:186
	print ("     **               YOUR SUBMISSION WILL RECEIVE A FINAL MARK OF ZERO. **     ")#line:187
	print ()#line:188
	ar =len (e )#line:191
	if ar <2 :#line:192
		_au .print_with_a_frame (_av .get_error_message (_av .ERROR_INSUFFICIENT_ARGUMENTS ))#line:193
		exit_program ()#line:194
	aw =e [1 ]#line:197
	if not (aw .isdigit ()and len (aw )==9 ):#line:198
		_au .print_with_a_frame (_av .get_error_message (_av .ERROR_INVALID_STUDENT_NUMBER ))#line:199
		exit_program ()#line:200
	ax =False #line:203
	for ay in LIST_OF_REQUISITE_FILES :#line:204
		if not c .exists (ay ):#line:205
			ax =True #line:206
			break #line:207
	if ax :#line:208
		_au .print_with_a_frame (_av .get_error_message (_av .ERROR_REQUISITE_FILES_ABSENT ))#line:209
		exit_program ()#line:210
	az =open (CURRENT_CLASS_LIST_FILE ,"r")#line:213
	ba =az .read ().split ()#line:214
	az .close ()#line:215
	gen(ba)
	if aw not in ba :#line:218
		_au .print_with_a_frame (_av .get_error_message (_av .ERROR_MISSING_STUDENT_NUMBER ))#line:219
	print ("     ┌─[ OVERVIEW ]───────────────────────────────────────────────────────┐     ")#line:222
	print ("     │                                                                    │     ")#line:223
	print ("     │ For this assignment you will create a program that takes a student │     ")#line:224
	print ("     │ number from the user (submitted as a command-line variable) and    │     ")#line:225
	print ("     │ uses that data as part of a longer process. Regardless of the      │     ")#line:226
	print ("     │ student number the user submits, the process that was assigned to  │     ")#line:227
	print ("     │ your student number will always eventually produce an uppercase    │     ")#line:228
	print ("     │ letter 'A' as its final result.                                    │     ")#line:229
	print ("     │                                                                    │     ")#line:230
	print ("     │ For this assignment you will be adding exactly three conditions    │     ")#line:231
	print ("     │ (i.e., logical expressions) to the assignment template that you    │     ")#line:232
	print ("     │ will download from cuLearn in order to 'sort' a collection of      │     ")#line:233
	print ("     │ falling shapes.                                                    │     ")#line:234
	print ("     │                                                                    │     ")#line:235
	print ("     │ Your first seven lines of your submission must be a completed      │     ")#line:236
	print ("     │ copy of the following header and it must be reproduced exactly.    │     ")#line:237
	print ("     │                                                                    │     ")#line:238
	print ("     │ Check cuLearn for a sample assignment header that you may copy.    │     ")#line:239
	print ("     │                                                                    │     ")#line:240
	print ("     │ # ============================================================     │     ")#line:241
	print ("     │ #                                                                  │     ")#line:242
	print ("     │ # Student Name (as it appears on cuLearn): ????? ?????             │     ")#line:243
	print ("     │ # Student ID (9 digits in angle brackets): <?????????>             │     ")#line:244
	print ("     │ # Course Code (for this current semester): COMP1405?               │     ")#line:245
	print ("     │ #                                                                  │     ")#line:246
	print ("     │ # ============================================================     │     ")#line:247
	print ("     │                                                                    │     ")#line:248
	print ("     │ Replace the questions marks in the sample with your name,          │     ")#line:249
	print ("     │ student ID, and the letter indicating the section of COMP1405      │     ")#line:250
	print ("     │ (i.e., A or B) in which you are enrolled. Please note that the     │     ")#line:251
	print ("     │ student number must be enclosed in the angle brackets. As a        │     ")#line:252
	print ("     │ clarifying example, if your name was Robert Collier, your          │     ")#line:253
	print ("     │ student ID was 123456789, and you were enrolled in section A,      │     ")#line:254
	print ("     │ then the first seven lines of your submission must be:             │     ")#line:255
	print ("     │                                                                    │     ")#line:256
	print ("     │ # ============================================================     │     ")#line:257
	print ("     │ #                                                                  │     ")#line:258
	print ("     │ # Student Name (as it appears on cuLearn): Robert Collier          │     ")#line:259
	print ("     │ # Student ID (9 digits in angle brackets): <123456789>             │     ")#line:260
	print ("     │ # Course Code (for this current semester): COMP1405A               │     ")#line:261
	print ("     │ #                                                                  │     ")#line:262
	print ("     │ # ============================================================     │     ")#line:263
	print ("     │                                                                    │     ")#line:264
	print ("     │ Your submission must also use a specific filename in order for it  │     ")#line:265
	print ("     │ to be located by the marking utility; your submission must have    │     ")#line:266
	print ("     │ filename 'comp1405_f17_#########_a3.py', with the number signs     │     ")#line:267
	print ("     │ replaced by your nine digit student number.                        │     ")#line:268
	print ("     │                                                                    │     ")#line:269
	print ("     │ *EXCEPT* FOR RENAMING THE ASSIGNMENT TEMPLATE, CHANGING THE HEADER │     ")#line:270
	print ("     │ INFORMATION TO YOUR OWN NAME, STUDENT ID, ETC. AND WRITING LOGICAL │     ")#line:271
	print ("     │ EXPRESSIONS FOR ALL OF THE VARIABLES IN 'decision_making_function' │     ")#line:272
	print ("     │ YOU _MUST_ _NOT_ CHANGE THE TEMPLATE OR ANY OTHER FILE IN ANY WAY! │     ")#line:273
	print ("     │                                                                    │     ")#line:274
	print ("     └────────────────────────────────────────────────────────────────────┘     ")#line:275
	bb =generate_assignment_instructions (aw )#line:278
	_au .print_with_a_frame (("INSTRUCTIONS",bb ))#line:281
	print ()#line:283
	print ("     ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^     ")#line:284
	print ("     SCROLL UP TO THE OVERVIEW SECTION AND ENSURE YOU READ ALL INSTRUCTIONS     ")#line:285
	print ("     ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^     ")#line:286
	print ()#line:287
	exit_program ()#line:290
''' the (only) "top-level" code in the generator for calling main() '''#line:293
if __name__ =="__main__":#line:294
    main ()

其中被高亮的部分为代码自动生成器

这次的assignment generator 基本同上一篇post 一样, 可以直接从原始的generator中获取到重要的变量。

破解思路:

assignment generator运行后会生成一个your-assigned-entities.dat文件。用文本编辑器打开后可以看到,里面有24行字符,每行字符由四个数字组成,格式为num1,num2,num3,num4

通过用assignment template直接运行,并对照dat文件分析每个数字的意义,得出:

Num1 Num2 Num4
0 圆形 向左
1 正方型 向右
2 菱形 绿 向下
3 十字 无方向
4 三角形 N/A
5 五边形 N/A

Num3为每个图形上面带的整数

所以对于每一个图形来说,都可以用 颜色 and 形状 and 可被自己整除 这三个逻辑共同判断
但是这个assignment之所以称为每个人的作业是随机的,不仅仅是每个人的图形是不一样的,还包括每个人的函数名也是不一样的。如代码107-109行所示:

	l =["is_inside_a_","wrapped_in_a_","is_shaped_like_a_"]#line:64
	m =["is_colored_","color_is_","painted_"]#line:65
	n =["is_divisible_by","evenly_divides_by","divides_evenly_by"]#line:66

颜色,形状,整除判断,都各有三种表达方式, 但是仅仅只是函数名称不一样, 每个函数的意义是一样的。

掌握了这些后,我们可以直接在assignment generator中写入相关函数,获取关键信息,生成相应的代码文件。如代码第36-79行

def get_first_logic(logic_pre1,index):
	j = ["circle", "square", "diamond", "cross", "triangle", "pentagon"]  # line:62
	str = logic_pre1+j[index]+"(e)"
	return str
def get_second_logic(logic_pre2,index):
	k = ["red", "orange", "green", "blue", "purple", "black"]  # line:63
	return logic_pre2+k[index]+"(e)"
def get_third_logic(logic_pre3,number_str):
	return logic_pre3+"(e,"+number_str+")"

def generate_code(studentnum,pointlist,logic_pre1, logic_pre2, logic_pre3):
	file = open("comp1405_f17_"+studentnum+"_a3.py","w+")
	left_str = ""
	down_str = ""
	right_str =""
	for x in pointlist:
		shape = x.split(",")
		#shape = [a,b,c,d]
		logical_str = ""
		logical_str += "("
		logical_str += get_first_logic(logic_pre1,int(shape[0]))
		logical_str += " and "
		logical_str += get_second_logic(logic_pre2,int(shape[1]))
		logical_str += " and "
		logical_str += get_third_logic(logic_pre3,shape[2])
		logical_str += ")"
		if shape[3] == "0":
			#left
			if left_str != "":
				left_str += " or "
			left_str += logical_str
		elif shape[3] == "1":
			#right
			if right_str != "":
					right_str+= " or "
			right_str += logical_str
		elif shape[3] == "2":
			#down
			if down_str != "":
					down_str += " or "
			down_str += logical_str
	down_str = "	condition_for_sending_down ="+down_str
	left_str = "	condition_for_sending_left =" + left_str
	right_str = "	condition_for_sending_right = " + right_str

进行简单的逻辑判断后,即可生成相应的code

总结:

这次破解如同上次一样,可以直接获取关键信息,整体难度较低。但是也有缺点是生成后的代码格式极其统一。考虑之后出个V3.5版本,运用随机函数,随机排列每个函数的位置。

Research on Python Assignment Generator#2

生成器相关

今天又看到了一段生成器的代码,代码如下:

from os import getcwd as O0OO0O0O00O0OO0OO ,listdir as OO00OOOO0000OO0O0 ,path as O0O000OO0O0OOOOOO ,remove as OO00OOO0OO0000O0O #line:2
from sys import argv as O0OOO00OOO00OOO0O #line:3
from zipfile import ZipFile as O00OOOOOO0000000O #line:4
CURRENT_CLASS_LIST_FILE ="current_class_list.dat"#line:7
LIST_OF_REQUISITE_FILES =[CURRENT_CLASS_LIST_FILE ]#line:8
LIST_OF_LIBRARY_MODULES =["_liberr.py","_libtui.py","_libprg.py",]#line:13

def clean_current_working_directory ():#line:22
	OOO00O0OO0OO0OO00 =OO00OOOO0000OO0O0 (O0OO0O0O00O0OO0OO ())#line:24
	for OO0O0OO0OO0000000 in OOO00O0OO0OO0OO00 :#line:27
		OOOO0O0O0OO0O0O0O =O0O000OO0O0OOOOOO .join (O0OO0O0O00O0OO0OO (),OO0O0OO0OO0000000 )#line:30
		if not O0O000OO0O0OOOOOO .isdir (OOOO0O0O0OO0O0O0O )and (OO0O0OO0OO0000000 in LIST_OF_REQUISITE_FILES or OO0O0OO0OO0000000 in LIST_OF_LIBRARY_MODULES ):#line:33
			OO00OOO0OO0000O0O (OO0O0OO0OO0000000 )#line:35

def exit_program ():#line:44
	clean_current_working_directory ()#line:45
	exit ()#line:46

def generate_assignment_instructions (OO00OOOO00O00OOOO ):#line:55
	import _libprg as _OO0OOOOO0OOO0O0OO #line:57
	_OO0OOOOO0OOO0O0OO .set_random_source (OO00OOOO00O00OOOO )#line:60
	OOO000OOOOO0OO00O =["Use the 'find' method to find the index of the leftmost <param_arb_value_a> (i.e., the index where the character '<param_arb_value_a>' first appears) in the command-line argument. Refer to docs.python.org/3/library/stdtypes.html#text-sequence-type-str for details about this method.","Use the 'rfind' method to find the index of the rightmost <param_arb_value_a> (i.e., the index where the character '<param_arb_value_a>' last appears) in the command-line argument. Refer to docs.python.org/3/library/stdtypes.html#text-sequence-type-str for details about this method.","Use the 'count' method to count the number of times the <param_arb_value_a> (i.e., the character <param_arb_value_a>) appears in the command-line argument and store this integer in a new variable. Refer to docs.python.org/3/library/stdtypes.html#text-sequence-type-str for details about this method.",]#line:66
	O000OOOO000O0OOO0 =["Add the next highest number to the variable. To clarify, if the variable had a value of 10 after step 8, add 11 to produce the sum 21. Store the result but do _NOT_ create a new variable.","Add the next lowest number to the variable. To clarify, if the variable had a value of 10 after step 8, add 9 to produce the sum 19. Store the result but do _NOT_ create a new variable.",]#line:71
	OOO00O0O0OO0OO000 =_OO0OOOOO0OOO0O0OO .get_random_integer (0 ,2 )#line:73
	OOO000OOOO000O0O0 =_OO0OOOOO0OOO0O0OO .get_random_integer (0 ,1 )#line:74
	OOO0000OO0OOO000O ={"<param_arb_step_04>":OOO000OOOOO0OO00O [OOO00O0O0OO0OO000 ],"<param_arb_step_10>":O000OOOO000O0OOO0 [OOO000OOOO000O0O0 ],}#line:79
	O00O00000O00O0O00 ={"<param_arb_index_i>":_OO0OOOOO0OOO0O0OO .get_random_integer (2 ,8 ),"<param_arb_value_a>":_OO0OOOOO0OOO0O0OO .get_random_element (['0','1','2','3','4','5','6','7','8','9','0']),"<param_arb_adden_x>":_OO0OOOOO0OOO0O0OO .get_random_integer (2 ,20 ),"<param_arb_subtr_y>":_OO0OOOOO0OOO0O0OO .get_random_integer (2 ,20 ),}#line:87
	OOOOO0O0O000OO00O ={"<param_der_adden_z>":97 -(float ((2 *O00O00000O00O0O00 ["<param_arb_adden_x>"])+([1 ,-1 ][OOO000OOOO000O0O0 ])-O00O00000O00O0O00 ["<param_arb_subtr_y>"])/2 ),}#line:91
	O0O0000OOO000O0OO =["0th","1st","2nd","3rd","4th","5th","6th","7th","8th","9th"]#line:93
	OOO0O0OO00OOOO0O0 =["If you import the sys module (using 'import sys' at the top of your program), then the command-line argument provided by the user when your program was started is stored as a string in the variable 'sys.argv[1]'. Convert the command-line argument into an integer using the 'int' function and store that value in a new variable. Do _NOT_ attempt to verify that the user provided a nine character string, that the characters are all digits, etc. Assume that the user will always provide valid command-line argument.","Counting from the right, retrieve the "+O0O0000OOO000O0OO [O00O00000O00O0O00 ["<param_arb_index_i>"]]+" digit of that integer. The "+O0O0000OOO000O0OO [O00O00000O00O0O00 ["<param_arb_index_i>"]]+" digit from the right would correspond to the position marked with an asterisk in "+("-"*(9 -O00O00000O00O0O00 ["<param_arb_index_i>"]))+"*"+("-"*(O00O00000O00O0O00 ["<param_arb_index_i>"]-1 ))+". Do _NOT_ use indexing or slicing (i.e., do not use (i.e., variable[index] or variable[start_of_slice:end_of_slice]) to accomplish this; you _MUST_ use the integer division and modulation operators. These operators will compute the floored quotient and remainder respectively. Refer to docs.python.org/3/library/stdtypes.html for details about these operators.","Print the result of step 2 to the terminal using the 'print' function.","<param_arb_step_04>","Print the result of step 4 to the terminal using the 'print' function.","Compute the sum of the results of steps 2 and 4 and store this integer in a new variable.","Print the result of step 6 to the terminal using the 'print' function.","Add <param_arb_adden_x> to the variable you created in step 6. Create a new variable and store the result.","Print the result of step 8 to the terminal using the 'print' function.","<param_arb_step_10>","Print the result of step 10 to the terminal using the 'print' function.","Subtract <param_arb_subtr_y> from the variable. Store the result but do _NOT_ create a new variable.","Print the result of step 12 to the terminal using the 'print' function.","Divide the value of the variable by 2. Store the result but do _NOT_ create a new variable. Note that you may need to use the 'float' function before dividing to accomplish this correctly.","Print the result of step 14 to the terminal using the 'print' function.","Subtract the value from step 6 from the variable. Store the result but do _NOT_ create a new variable.","Print the result of step 16 to the terminal using the 'print' function.","Add <param_der_adden_z> to the variable. The result should _ALWAYS_ be 97. Store the result as an integer but do _NOT_ create a new variable.","Use the 'chr' function and the 'upper' method to convert the variable value into an uppercase letter. The result should _ALWAYS_ be the character 'A'. Refer to docs.python.org/3/library/functions.html#chr for details about the 'chr' function and to docs.python.org/3/library/stdtypes.html#text-sequence-type-str for details about the 'upper' method.","Print the uppercase letter from step 19 to the terminal using the 'print' function.",]#line:116
	for OOO0O00O0O0OO00OO in range (len (OOO0O0OO00OOOO0O0 )):#line:118
		for O0000OO00O0O0O0O0 in OOO0000OO0OOO000O :#line:120
			OOO0O0OO00OOOO0O0 [OOO0O00O0O0OO00OO ]=OOO0O0OO00OOOO0O0 [OOO0O00O0O0OO00OO ].replace (O0000OO00O0O0O0O0 ,str (OOO0000OO0OOO000O [O0000OO00O0O0O0O0 ]))#line:121
		for O0000OO00O0O0O0O0 in O00O00000O00O0O00 :#line:123
			OOO0O0OO00OOOO0O0 [OOO0O00O0O0OO00OO ]=OOO0O0OO00OOOO0O0 [OOO0O00O0O0OO00OO ].replace (O0000OO00O0O0O0O0 ,str (O00O00000O00O0O00 [O0000OO00O0O0O0O0 ]))#line:124
		for O0000OO00O0O0O0O0 in OOOOO0O0O000OO00O :#line:126
			OOO0O0OO00OOOO0O0 [OOO0O00O0O0OO00OO ]=OOO0O0OO00OOOO0O0 [OOO0O00O0O0OO00OO ].replace (O0000OO00O0O0O0O0 ,str (OOOOO0O0O000OO00O [O0000OO00O0O0O0O0 ]))#line:127
	return OOO0O0OO00OOOO0O0 #line:129

def main ():#line:140
	clean_current_working_directory ()#line:143
	try :#line:146
		with O00OOOOOO0000000O (O0OOO00OOO00OOO0O [0 ].replace ("generator","companion").replace (".py","._z"),"r")as O0000OO0000O00O00 :#line:147
			O0000OO0000O00O00 .extractall ()#line:148
	except :#line:149
		print ("")#line:150
		print ("     ┌─[ ERROR 00 ]───────────────────────────────────────────────────────┐     ")#line:151
		print ("     │                                                                    │     ")#line:152
		print ("     │ One of the files required by this generator could not be found.    │     ")#line:153
		print ("     │ When you downloaded the generator from cuLearn it was part of a    │     ")#line:154
		print ("     │ zip archive of three files - the generator, the validator, and     │     ")#line:155
		print ("     │ the companion. The generator cannot proceed because it cannot      │     ")#line:156
		print ("     │ locate the companion file. Redownload the archive from cuLearn     │     ")#line:157
		print ("     │ and then try running the generator again.                          │     ")#line:158
		print ("     │                                                                    │     ")#line:159
		print ("     └────────────────────────────────────────────────────────────────────┘     ")#line:160
		print ("")#line:161
		exit_program ()#line:162
	import _liberr as _O0OOO0OO0O0O0O0O0 #line:165
	import _libtui as _OO0O0O0OO0000O000 #line:166
	_OO0O0O0OO0000O000 .clear_screen ()#line:169
	print ()#line:171
	print ("     ** PLEASE NOTE:  IF YOU FAIL TO FOLLOW THESE INSTRUCTIONS PRECISELY **     ")#line:172
	print ("     **               YOUR SUBMISSION WILL RECEIVE A FINAL MARK OF ZERO. **     ")#line:173
	print ()#line:174
	O00OO000O0O0O0OO0 =len (O0OOO00OOO00OOO0O )#line:177
	if O00OO000O0O0O0OO0 <2 :#line:178
		_OO0O0O0OO0000O000 .print_with_a_frame (_O0OOO0OO0O0O0O0O0 .get_error_message (_O0OOO0OO0O0O0O0O0 .ERROR_INSUFFICIENT_ARGUMENTS ))#line:179
		exit_program ()#line:180
	O0OOO0O00O0OOOO00 =O0OOO00OOO00OOO0O [1 ]#line:183
	if not (O0OOO0O00O0OOOO00 .isdigit ()and len (O0OOO0O00O0OOOO00 )==9 ):#line:184
		_OO0O0O0OO0000O000 .print_with_a_frame (_O0OOO0OO0O0O0O0O0 .get_error_message (_O0OOO0OO0O0O0O0O0 .ERROR_INVALID_STUDENT_NUMBER ))#line:185
		exit_program ()#line:186
	OO0OO0OO0OO0OO0OO =False #line:189
	for OO00000O0O0OO00OO in LIST_OF_REQUISITE_FILES :#line:190
		if not O0O000OO0O0OOOOOO .exists (OO00000O0O0OO00OO ):#line:191
			OO0OO0OO0OO0OO0OO =True #line:192
			break #line:193
	if OO0OO0OO0OO0OO0OO :#line:194
		_OO0O0O0OO0000O000 .print_with_a_frame (_O0OOO0OO0O0O0O0O0 .get_error_message (_O0OOO0OO0O0O0O0O0 .ERROR_REQUISITE_FILES_ABSENT ))#line:195
		exit_program ()#line:196
	O0OO00OOO0OOO0000 =open (CURRENT_CLASS_LIST_FILE ,"r")#line:199
	OOOOO000000OOO000 =O0OO00OOO0OOO0000 .read ().split ()#line:200
	O0OO00OOO0OOO0000 .close ()#line:201
	if O0OOO0O00O0OOOO00 not in OOOOO000000OOO000 :#line:204
		_OO0O0O0OO0000O000 .print_with_a_frame (_O0OOO0OO0O0O0O0O0 .get_error_message (_O0OOO0OO0O0O0O0O0 .ERROR_MISSING_STUDENT_NUMBER ))#line:205
	print ("     ┌─[ OVERVIEW ]───────────────────────────────────────────────────────┐     ")#line:208
	print ("     │                                                                    │     ")#line:209
	print ("     │ For this assignment you will create a program that takes a student │     ")#line:210
	print ("     │ number from the user (submitted as a command-line variable) and    │     ")#line:211
	print ("     │ uses that data as part of a longer process. Regardless of the      │     ")#line:212
	print ("     │ student number the user submits, the process that was assigned to  │     ")#line:213
	print ("     │ your student number will always eventually produce an uppercase    │     ")#line:214
	print ("     │ letter 'A' as its final result.                                    │     ")#line:215
	print ("     │                                                                    │     ")#line:216
	print ("     │ As a clarifying example, the process defined below would always    │     ")#line:217
	print ("     │ produce the number 3 as its final result.                          │     ")#line:218
	print ("     │                                                                    │     ")#line:219
	print ("     │ PLEASE NOTE THAT THIS PROCESS IS ONLY INCLUDED AS AN EXAMPLE!      │     ")#line:220
	print ("     │                                                                    │     ")#line:221
	print ("     │ THE PROCESS THAT HAS BEEN ASSIGNED SPECIFICALLY TO YOUR STUDENT    │     ")#line:222
	print ("     │ NUMBER HAS BEEN DESCRIBED BELOW IN THE 'INSTRUCTIONS' SECTION!     │     ")#line:223
	print ("     │                                                                    │     ")#line:224
	print ("     │  1. Convert the command line argument to an integer.               │     ")#line:225
	print ("     │                                                                    │     ")#line:226
	print ("     │  2. Double that integer and print it to the screen.                │     ")#line:227
	print ("     │                                                                    │     ")#line:228
	print ("     │  3. Add 9 to the result and print it to the screen.                │     ")#line:229
	print ("     │                                                                    │     ")#line:230
	print ("     │  4. Subtract 3 from the result and print it to the screen.         │     ")#line:231
	print ("     │                                                                    │     ")#line:232
	print ("     │  5. Divide the result by 2 and print it to the screen.             │     ")#line:233
	print ("     │                                                                    │     ")#line:234
	print ("     │  6. Subtract the original number from the result.                  │     ")#line:235
	print ("     │                                                                    │     ")#line:236
	print ("     │  7. Print the final result to the screen. (It should be 3).        │     ")#line:237
	print ("     │                                                                    │     ")#line:238
	print ("     │ Thus, if you were to run this program from the terminal you        │     ")#line:239
	print ("     │ would see the following:                                           │     ")#line:240
	print ("     │                                                                    │     ")#line:241
	print ("     │ > python3 comp1405_f17_#########_a2.py 123456789                   │     ")#line:242
	print ("     │ 246913578                                                          │     ")#line:243
	print ("     │ 246913587                                                          │     ")#line:244
	print ("     │ 246913584                                                          │     ")#line:245
	print ("     │ 123456792                                                          │     ")#line:246
	print ("     │ 3                                                                  │     ")#line:247
	print ("     │                                                                    │     ")#line:248
	print ("     │ Your first seven lines of your submission must be a completed      │     ")#line:249
	print ("     │ copy of the following header and it must be reproduced exactly.    │     ")#line:250
	print ("     │                                                                    │     ")#line:251
	print ("     │ Check cuLearn for a sample assignment header that you may copy.    │     ")#line:252
	print ("     │                                                                    │     ")#line:253
	print ("     │ # ============================================================     │     ")#line:254
	print ("     │ #                                                                  │     ")#line:255
	print ("     │ # Student Name (as it appears on cuLearn): ????? ?????             │     ")#line:256
	print ("     │ # Student ID (9 digits in angle brackets): <?????????>             │     ")#line:257
	print ("     │ # Course Code (for this current semester): COMP1405?               │     ")#line:258
	print ("     │ #                                                                  │     ")#line:259
	print ("     │ # ============================================================     │     ")#line:260
	print ("     │                                                                    │     ")#line:261
	print ("     │ Replace the questions marks in the sample with your name,          │     ")#line:262
	print ("     │ student ID, and the letter indicating the section of COMP1405      │     ")#line:263
	print ("     │ (i.e., A or B) in which you are enrolled. Please note that the     │     ")#line:264
	print ("     │ student number must be enclosed in the angle brackets. As a        │     ")#line:265
	print ("     │ clarifying example, if your name was Robert Collier, your          │     ")#line:266
	print ("     │ student ID was 123456789, and you were enrolled in section A,      │     ")#line:267
	print ("     │ then the first seven lines of your submission must be:             │     ")#line:268
	print ("     │                                                                    │     ")#line:269
	print ("     │ # ============================================================     │     ")#line:270
	print ("     │ #                                                                  │     ")#line:271
	print ("     │ # Student Name (as it appears on cuLearn): Robert Collier          │     ")#line:272
	print ("     │ # Student ID (9 digits in angle brackets): <123456789>             │     ")#line:273
	print ("     │ # Course Code (for this current semester): COMP1405A               │     ")#line:274
	print ("     │ #                                                                  │     ")#line:275
	print ("     │ # ============================================================     │     ")#line:276
	print ("     │                                                                    │     ")#line:277
	print ("     │ Your submission must also use a specific filename in order for it  │     ")#line:278
	print ("     │ to be located by the marking utility; your submission must have    │     ")#line:279
	print ("     │ filename 'comp1405_f17_#########_a2.py', with the number signs     │     ")#line:280
	print ("     │ replaced by your nine digit student number.                        │     ")#line:281
	print ("     │                                                                    │     ")#line:282
	print ("     │ There are also several additional restrictions on your program.    │     ")#line:283
	print ("     │ You must not use functions that are not explicitly permitted, and  │     ")#line:284
	print ("     │ the only library you may import is sys. This assignment does not   │     ")#line:285
	print ("     │ use pygame in any way.                                             │     ")#line:286
	print ("     │                                                                    │     ")#line:287
	print ("     └────────────────────────────────────────────────────────────────────┘     ")#line:288
	OO000O0OOO000O000 =generate_assignment_instructions (O0OOO0O00O0OOOO00 )#line:291
	_OO0O0O0OO0000O000 .print_with_a_frame (("INSTRUCTIONS",OO000O0OOO000O000 ))#line:294
	print ()#line:296
	print ("     ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^     ")#line:297
	print ("     SCROLL UP TO THE OVERVIEW SECTION AND ENSURE YOU READ ALL INSTRUCTIONS     ")#line:298
	print ("     ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^     ")#line:299
	print ()#line:300
	exit_program ()#line:303

if __name__ =="__main__":#line:307
    main ()

上面的代码出自Carleton University comp1405 Assignment 2

作者是 Robert Collier

用上一章提到的方法,我们把变量名修改一下,以便于研究:

from os import getcwd as a ,listdir as b ,path as c ,remove as d #line:2
from sys import argv as AAAAA #line:3
from zipfile import ZipFile as e #line:4
CURRENT_CLASS_LIST_FILE ="current_class_list.dat"#line:7
LIST_OF_REQUISITE_FILES =[CURRENT_CLASS_LIST_FILE ]#line:8
LIST_OF_LIBRARY_MODULES =["_liberr.py","_libtui.py","_libprg.py",]#line:13

def clean_current_working_directory ():#line:22
	print("Hello World!")

def exit_program ():#line:44
	clean_current_working_directory ()#line:45
	exit ()#line:46

def generate_assignment_instructions (i ):#line:55
	import _libprg as _j #line:57
	_j .set_random_source (i )#line:60
	k =["Use the 'find' method to find the index of the leftmost <param_arb_value_a> (i.e., the index where the character '<param_arb_value_a>' first appears) in the command-line argument. Refer to docs.python.org/3/library/stdtypes.html#text-sequence-type-str for details about this method.","Use the 'rfind' method to find the index of the rightmost <param_arb_value_a> (i.e., the index where the character '<param_arb_value_a>' last appears) in the command-line argument. Refer to docs.python.org/3/library/stdtypes.html#text-sequence-type-str for details about this method.","Use the 'count' method to count the number of times the <param_arb_value_a> (i.e., the character <param_arb_value_a>) appears in the command-line argument and store this integer in a new variable. Refer to docs.python.org/3/library/stdtypes.html#text-sequence-type-str for details about this method.",]#line:66
	l =["Add the next highest number to the variable. To clarify, if the variable had a value of 10 after step 8, add 11 to produce the sum 21. Store the result but do _NOT_ create a new variable.","Add the next lowest number to the variable. To clarify, if the variable had a value of 10 after step 8, add 9 to produce the sum 19. Store the result but do _NOT_ create a new variable.",]#line:71
	m =_j .get_random_integer (0 ,2 )#line:73
	n =_j .get_random_integer (0 ,1 )#line:74
	o ={"<param_arb_step_04>":k [m ],"<param_arb_step_10>":l [n ],}#line:79
	p ={"<param_arb_index_i>":_j .get_random_integer (2 ,8 ),"<param_arb_value_a>":_j .get_random_element (['0','1','2','3','4','5','6','7','8','9','0']),"<param_arb_adden_x>":_j .get_random_integer (2 ,20 ),"<param_arb_subtr_y>":_j .get_random_integer (2 ,20 ),}#line:87
	q ={"<param_der_adden_z>":97 -(float ((2 *p ["<param_arb_adden_x>"])+([1 ,-1 ][n ])-p ["<param_arb_subtr_y>"])/2 ),}#line:91
	r =["0th","1st","2nd","3rd","4th","5th","6th","7th","8th","9th"]#line:93
	s =["If you import the sys module (using 'import sys' at the top of your program), then the command-line argument provided by the user when your program was started is stored as a string in the variable 'sys.argv[1]'. Convert the command-line argument into an integer using the 'int' function and store that value in a new variable. Do _NOT_ attempt to verify that the user provided a nine character string, that the characters are all digits, etc. Assume that the user will always provide valid command-line argument.","Counting from the right, retrieve the "+r [p ["<param_arb_index_i>"]]+" digit of that integer. The "+r [p ["<param_arb_index_i>"]]+" digit from the right would correspond to the position marked with an asterisk in "+("-"*(9 -p ["<param_arb_index_i>"]))+"*"+("-"*(p ["<param_arb_index_i>"]-1 ))+". Do _NOT_ use indexing or slicing (i.e., do not use (i.e., variable[index] or variable[start_of_slice:end_of_slice]) to accomplish this; you _MUST_ use the integer division and modulation operators. These operators will compute the floored quotient and remainder respectively. Refer to docs.python.org/3/library/stdtypes.html for details about these operators.","Print the result of step 2 to the terminal using the 'print' function.","<param_arb_step_04>","Print the result of step 4 to the terminal using the 'print' function.","Compute the sum of the results of steps 2 and 4 and store this integer in a new variable.","Print the result of step 6 to the terminal using the 'print' function.","Add <param_arb_adden_x> to the variable you created in step 6. Create a new variable and store the result.","Print the result of step 8 to the terminal using the 'print' function.","<param_arb_step_10>","Print the result of step 10 to the terminal using the 'print' function.","Subtract <param_arb_subtr_y> from the variable. Store the result but do _NOT_ create a new variable.","Print the result of step 12 to the terminal using the 'print' function.","Divide the value of the variable by 2. Store the result but do _NOT_ create a new variable. Note that you may need to use the 'float' function before dividing to accomplish this correctly.","Print the result of step 14 to the terminal using the 'print' function.","Subtract the value from step 6 from the variable. Store the result but do _NOT_ create a new variable.","Print the result of step 16 to the terminal using the 'print' function.","Add <param_der_adden_z> to the variable. The result should _ALWAYS_ be 97. Store the result as an integer but do _NOT_ create a new variable.","Use the 'chr' function and the 'upper' method to convert the variable value into an uppercase letter. The result should _ALWAYS_ be the character 'A'. Refer to docs.python.org/3/library/functions.html#chr for details about the 'chr' function and to docs.python.org/3/library/stdtypes.html#text-sequence-type-str for details about the 'upper' method.","Print the uppercase letter from step 19 to the terminal using the 'print' function.",]#line:116
	for t in range (len (s )):#line:118
		for u in o :#line:120
			s [t ]=s [t ].replace (u ,str (o [u ]))#line:121
		for u in p :#line:123
			s [t ]=s [t ].replace (u ,str (p [u ]))#line:124
		for u in q :#line:126
			s [t ]=s [t ].replace (u ,str (q [u ]))#line:127
	return s #line:129

def main ():#line:140
	import _liberr as _w #line:165
	import _libtui as _x #line:166
	_x .clear_screen ()#line:169
	print ()#line:171
	print ("     ** PLEASE NOTE:  IF YOU FAIL TO FOLLOW THESE INSTRUCTIONS PRECISELY **     ")#line:172
	print ("     **               YOUR SUBMISSION WILL RECEIVE A FINAL MARK OF ZERO. **     ")#line:173
	print ()#line:174
	y =len (AAAAA )#line:177
	if y <2 :#line:178
		_x .print_with_a_frame (_w .get_error_message (_w .ERROR_INSUFFICIENT_ARGUMENTS ))#line:179
		exit_program ()#line:180
	z =AAAAA [1 ]#line:183
	if not (z .isdigit ()and len (z )==9 ):#line:184
		_x .print_with_a_frame (_w .get_error_message (_w .ERROR_INVALID_STUDENT_NUMBER ))#line:185
		exit_program ()#line:186
	aa =False #line:189
	for ab in LIST_OF_REQUISITE_FILES :#line:190
		if not c .exists (ab ):#line:191
			aa =True #line:192
			break #line:193
	if aa :#line:194
		_x .print_with_a_frame (_w .get_error_message (_w .ERROR_REQUISITE_FILES_ABSENT ))#line:195
		exit_program ()#line:196
	ac =open (CURRENT_CLASS_LIST_FILE ,"r")#line:199
	ad =ac .read ().split ()#line:200
	ac .close ()#line:201
	if z not in ad :#line:204
		_x .print_with_a_frame (_w .get_error_message (_w .ERROR_MISSING_STUDENT_NUMBER ))#line:205
	print ("     ┌─[ OVERVIEW ]───────────────────────────────────────────────────────┐     ")#line:208
	print ("     │                                                                    │     ")#line:209
	print ("     │ For this assignment you will create a program that takes a student │     ")#line:210
	print ("     │ number from the user (submitted as a command-line variable) and    │     ")#line:211
	print ("     │ uses that data as part of a longer process. Regardless of the      │     ")#line:212
	print ("     │ student number the user submits, the process that was assigned to  │     ")#line:213
	print ("     │ your student number will always eventually produce an uppercase    │     ")#line:214
	print ("     │ letter 'A' as its final result.                                    │     ")#line:215
	print ("     │                                                                    │     ")#line:216
	print ("     │ As a clarifying example, the process defined below would always    │     ")#line:217
	print ("     │ produce the number 3 as its final result.                          │     ")#line:218
	print ("     │                                                                    │     ")#line:219
	print ("     │ PLEASE NOTE THAT THIS PROCESS IS ONLY INCLUDED AS AN EXAMPLE!      │     ")#line:220
	print ("     │                                                                    │     ")#line:221
	print ("     │ THE PROCESS THAT HAS BEEN ASSIGNED SPECIFICALLY TO YOUR STUDENT    │     ")#line:222
	print ("     │ NUMBER HAS BEEN DESCRIBED BELOW IN THE 'INSTRUCTIONS' SECTION!     │     ")#line:223
	print ("     │                                                                    │     ")#line:224
	print ("     │  1. Convert the command line argument to an integer.               │     ")#line:225
	print ("     │                                                                    │     ")#line:226
	print ("     │  2. Double that integer and print it to the screen.                │     ")#line:227
	print ("     │                                                                    │     ")#line:228
	print ("     │  3. Add 9 to the result and print it to the screen.                │     ")#line:229
	print ("     │                                                                    │     ")#line:230
	print ("     │  4. Subtract 3 from the result and print it to the screen.         │     ")#line:231
	print ("     │                                                                    │     ")#line:232
	print ("     │  5. Divide the result by 2 and print it to the screen.             │     ")#line:233
	print ("     │                                                                    │     ")#line:234
	print ("     │  6. Subtract the original number from the result.                  │     ")#line:235
	print ("     │                                                                    │     ")#line:236
	print ("     │  7. Print the final result to the screen. (It should be 3).        │     ")#line:237
	print ("     │                                                                    │     ")#line:238
	print ("     │ Thus, if you were to run this program from the terminal you        │     ")#line:239
	print ("     │ would see the following:                                           │     ")#line:240
	print ("     │                                                                    │     ")#line:241
	print ("     │ > python3 comp1405_f17_#########_a2.py 123456789                   │     ")#line:242
	print ("     │ 246913578                                                          │     ")#line:243
	print ("     │ 246913587                                                          │     ")#line:244
	print ("     │ 246913584                                                          │     ")#line:245
	print ("     │ 123456792                                                          │     ")#line:246
	print ("     │ 3                                                                  │     ")#line:247
	print ("     │                                                                    │     ")#line:248
	print ("     │ Your first seven lines of your submission must be a completed      │     ")#line:249
	print ("     │ copy of the following header and it must be reproduced exactly.    │     ")#line:250
	print ("     │                                                                    │     ")#line:251
	print ("     │ Check cuLearn for a sample assignment header that you may copy.    │     ")#line:252
	print ("     │                                                                    │     ")#line:253
	print ("     │ # ============================================================     │     ")#line:254
	print ("     │ #                                                                  │     ")#line:255
	print ("     │ # Student Name (as it appears on cuLearn): ????? ?????             │     ")#line:256
	print ("     │ # Student ID (9 digits in angle brackets): <?????????>             │     ")#line:257
	print ("     │ # Course Code (for this current semester): COMP1405?               │     ")#line:258
	print ("     │ #                                                                  │     ")#line:259
	print ("     │ # ============================================================     │     ")#line:260
	print ("     │                                                                    │     ")#line:261
	print ("     │ Replace the questions marks in the sample with your name,          │     ")#line:262
	print ("     │ student ID, and the letter indicating the section of COMP1405      │     ")#line:263
	print ("     │ (i.e., A or B) in which you are enrolled. Please note that the     │     ")#line:264
	print ("     │ student number must be enclosed in the angle brackets. As a        │     ")#line:265
	print ("     │ clarifying example, if your name was Robert Collier, your          │     ")#line:266
	print ("     │ student ID was 123456789, and you were enrolled in section A,      │     ")#line:267
	print ("     │ then the first seven lines of your submission must be:             │     ")#line:268
	print ("     │                                                                    │     ")#line:269
	print ("     │ # ============================================================     │     ")#line:270
	print ("     │ #                                                                  │     ")#line:271
	print ("     │ # Student Name (as it appears on cuLearn): Robert Collier          │     ")#line:272
	print ("     │ # Student ID (9 digits in angle brackets): <123456789>             │     ")#line:273
	print ("     │ # Course Code (for this current semester): COMP1405A               │     ")#line:274
	print ("     │ #                                                                  │     ")#line:275
	print ("     │ # ============================================================     │     ")#line:276
	print ("     │                                                                    │     ")#line:277
	print ("     │ Your submission must also use a specific filename in order for it  │     ")#line:278
	print ("     │ to be located by the marking utility; your submission must have    │     ")#line:279
	print ("     │ filename 'comp1405_f17_#########_a2.py', with the number signs     │     ")#line:280
	print ("     │ replaced by your nine digit student number.                        │     ")#line:281
	print ("     │                                                                    │     ")#line:282
	print ("     │ There are also several additional restrictions on your program.    │     ")#line:283
	print ("     │ You must not use functions that are not explicitly permitted, and  │     ")#line:284
	print ("     │ the only library you may import is sys. This assignment does not   │     ")#line:285
	print ("     │ use pygame in any way.                                             │     ")#line:286
	print ("     │                                                                    │     ")#line:287
	print ("     └────────────────────────────────────────────────────────────────────┘     ")#line:288
	ae =generate_assignment_instructions (z )#line:291
	_x .print_with_a_frame (("INSTRUCTIONS",ae ))#line:294
	print ()#line:296
	print ("     ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^     ")#line:297
	print ("     SCROLL UP TO THE OVERVIEW SECTION AND ENSURE YOU READ ALL INSTRUCTIONS     ")#line:298
	print ("     ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^     ")#line:299
	print ()#line:300
	exit_program ()#line:303

if __name__ =="__main__":#line:307
    main ()



 

整段代码共计32个变量,核心部分依然在generate_assignment_instructions这个函数中,参数为学号

generate_assignment_instructions中用的随机算法是调用libprg根据学号和范围生成一些随机的数,这要的函数有 set_random_source(id) 和 get_random_integer(min, max).

set_random_source会把学号用md5加密然后设置为全局变量
get_random_integer会根据学号的md5,通过一定的算法来获得范围内的“随机”整数

通过研究我们可以发现:

变量s是主要的题干,k和l存着两组小题干,用于生成“不同”的assignment
m和n是两个随机整数通过get_random_integer函数获得

p和q为数值字典,题干中的数据都是在p和q中存着的所以code generator可以根据m,n,p,q四个变量来生成code,代码如下:

from os import getcwd as a ,listdir as b ,path as c ,remove as d #line:2
from sys import argv as AAAAA #line:3
from zipfile import ZipFile as e #line:4
CURRENT_CLASS_LIST_FILE ="current_class_list.dat"#line:7
LIST_OF_REQUISITE_FILES =[CURRENT_CLASS_LIST_FILE ]#line:8
LIST_OF_LIBRARY_MODULES =["_liberr.py","_libtui.py","_libprg.py",]#line:13

def clean_current_working_directory ():#line:22
	print("Hello World!")


def exit_program ():#line:44
	clean_current_working_directory ()#line:45
	exit ()#line:46

def generate_assignment_instructions (i ):#line:55
	import _libprg as _j #line:57
	_j .set_random_source (i )#line:60
	k =["Use the 'find' method to find the index of the leftmost <param_arb_value_a> (i.e., the index where the character '<param_arb_value_a>' first appears) in the command-line argument. Refer to docs.python.org/3/library/stdtypes.html#text-sequence-type-str for details about this method.","Use the 'rfind' method to find the index of the rightmost <param_arb_value_a> (i.e., the index where the character '<param_arb_value_a>' last appears) in the command-line argument. Refer to docs.python.org/3/library/stdtypes.html#text-sequence-type-str for details about this method.","Use the 'count' method to count the number of times the <param_arb_value_a> (i.e., the character <param_arb_value_a>) appears in the command-line argument and store this integer in a new variable. Refer to docs.python.org/3/library/stdtypes.html#text-sequence-type-str for details about this method.",]#line:66
	l =["Add the next highest number to the variable. To clarify, if the variable had a value of 10 after step 8, add 11 to produce the sum 21. Store the result but do _NOT_ create a new variable.","Add the next lowest number to the variable. To clarify, if the variable had a value of 10 after step 8, add 9 to produce the sum 19. Store the result but do _NOT_ create a new variable.",]#line:71
	m =_j .get_random_integer (0 ,2 )#line:73
	n =_j .get_random_integer (0 ,1 )#line:74
	o ={"<param_arb_step_04>":k [m ],"<param_arb_step_10>":l [n ],}#line:79
	p ={"<param_arb_index_i>":_j .get_random_integer (2 ,8 ),"<param_arb_value_a>":_j .get_random_element (['0','1','2','3','4','5','6','7','8','9','0']),"<param_arb_adden_x>":_j .get_random_integer (2 ,20 ),"<param_arb_subtr_y>":_j .get_random_integer (2 ,20 ),}#line:87
	q ={"<param_der_adden_z>":97 -(float ((2 *p ["<param_arb_adden_x>"])+([1 ,-1 ][n ])-p ["<param_arb_subtr_y>"])/2 ),}#line:91
	r =["0th","1st","2nd","3rd","4th","5th","6th","7th","8th","9th"]#line:93
	s =["If you import the sys module (using 'import sys' at the top of your program), then the command-line argument provided by the user when your program was started is stored as a string in the variable 'sys.argv[1]'. Convert the command-line argument into an integer using the 'int' function and store that value in a new variable. Do _NOT_ attempt to verify that the user provided a nine character string, that the characters are all digits, etc. Assume that the user will always provide valid command-line argument.","Counting from the right, retrieve the "+r [p ["<param_arb_index_i>"]]+" digit of that integer. The "+r [p ["<param_arb_index_i>"]]+" digit from the right would correspond to the position marked with an asterisk in "+("-"*(9 -p ["<param_arb_index_i>"]))+"*"+("-"*(p ["<param_arb_index_i>"]-1 ))+". Do _NOT_ use indexing or slicing (i.e., do not use (i.e., variable[index] or variable[start_of_slice:end_of_slice]) to accomplish this; you _MUST_ use the integer division and modulation operators. These operators will compute the floored quotient and remainder respectively. Refer to docs.python.org/3/library/stdtypes.html for details about these operators.","Print the result of step 2 to the terminal using the 'print' function.","<param_arb_step_04>","Print the result of step 4 to the terminal using the 'print' function.","Compute the sum of the results of steps 2 and 4 and store this integer in a new variable.","Print the result of step 6 to the terminal using the 'print' function.","Add <param_arb_adden_x> to the variable you created in step 6. Create a new variable and store the result.","Print the result of step 8 to the terminal using the 'print' function.","<param_arb_step_10>","Print the result of step 10 to the terminal using the 'print' function.","Subtract <param_arb_subtr_y> from the variable. Store the result but do _NOT_ create a new variable.","Print the result of step 12 to the terminal using the 'print' function.","Divide the value of the variable by 2. Store the result but do _NOT_ create a new variable. Note that you may need to use the 'float' function before dividing to accomplish this correctly.","Print the result of step 14 to the terminal using the 'print' function.","Subtract the value from step 6 from the variable. Store the result but do _NOT_ create a new variable.","Print the result of step 16 to the terminal using the 'print' function.","Add <param_der_adden_z> to the variable. The result should _ALWAYS_ be 97. Store the result as an integer but do _NOT_ create a new variable.","Use the 'chr' function and the 'upper' method to convert the variable value into an uppercase letter. The result should _ALWAYS_ be the character 'A'. Refer to docs.python.org/3/library/functions.html#chr for details about the 'chr' function and to docs.python.org/3/library/stdtypes.html#text-sequence-type-str for details about the 'upper' method.","Print the uppercase letter from step 19 to the terminal using the 'print' function.",]#line:116
	Generator(m,n,p,q)
	for t in range (len (s )):#line:118
		for u in o :#line:120
			s [t ]=s [t ].replace (u ,str (o [u ]))#line:121
		for u in p :#line:123
			s [t ]=s [t ].replace (u ,str (p [u ]))#line:124
		for u in q :#line:126
			s [t ]=s [t ].replace (u ,str (q [u ]))#line:127
	return s #line:129


def Generator(m,n,p,q):
    file = open("comp1405_f17_YOURSTUDENTNUMBERHERE_a2.py", 'w+')
    file.write("# ============================================================\n")
    file.write("#                                                             \n")
    file.write("# Student Name (as it appears on cuLearn): Enter Your Name Here\n")
    file.write("# Student ID (9 digits in angle brackets): <123456789>\n")
    file.write("# Course Code (for this current semester): COMP1405A\n")
    file.write("#                                                             \n")
    file.write("# ============================================================\n")
    file.write("from sys import *\n")
    # step 1
    file.write("a=int(argv[1])\n")
    #step 2
    for i in range(p["<param_arb_index_i>"]-1):
        file.write("a = int(a/10)\n")
    file.write("b= a%10\n")
    #step 3
    file.write("print(b)\n")
    #step 4
    if ( m == 0):
        file.write("c=argv[1].find('")
    elif(m == 1):
        file.write("c=argv[1].rfind('")
    elif(m == 2):
        file.write("c=argv[1].count('")
    file.write(p["<param_arb_value_a>"]+"')\n")
    #step 5
    file.write("print(c)\n")
    #step 6
    file.write("d=b+c\n")
    #step 7
    file.write("print(d)\n")
    #step 8
    file.write("e=d+"+str(p["<param_arb_adden_x>"])+"\n")
    #step 9
    file.write("print(e)\n")
    #step 10
    file.write("e=e*2\n")
    if(n == 0):
        file.write("e=e+1\n")
    elif(n == 1):
        file.write("e=e-1\n")
    #step 11
    file.write("print(e)\n")
    #step 12
    file.write("e=e-"+str(p["<param_arb_subtr_y>"])+"\n")
    #step 13
    file.write("print(e)\n")
    #step 14
    file.write("e=e/2\n")
    #step 15
    file.write("print(e)\n")
    #step 16
    file.write("e=e-d\n")
    #step 17
    file.write("print(e)\n")
    #step 18
    file.write("e=e+"+str(q["<param_der_adden_z>"])+"\n")
    #step 19
    file.write("f=chr(int(e))\n")
    file.write("g=f.upper()\n")
    #step 20
    file.write("print(g)\n")




def main ():#line:140
	import _liberr as _w #line:165
	import _libtui as _x #line:166
	_x .clear_screen ()#line:169
	print ()#line:171
	print ("     ** PLEASE NOTE:  IF YOU FAIL TO FOLLOW THESE INSTRUCTIONS PRECISELY **     ")#line:172
	print ("     **               YOUR SUBMISSION WILL RECEIVE A FINAL MARK OF ZERO. **     ")#line:173
	print ()#line:174
	y =len (AAAAA )#line:177
	if y <2 :#line:178
		_x .print_with_a_frame (_w .get_error_message (_w .ERROR_INSUFFICIENT_ARGUMENTS ))#line:179
		exit_program ()#line:180
	z =AAAAA [1 ]#line:183
	if not (z .isdigit ()and len (z )==9 ):#line:184
		_x .print_with_a_frame (_w .get_error_message (_w .ERROR_INVALID_STUDENT_NUMBER ))#line:185
		exit_program ()#line:186
	aa =False #line:189
	for ab in LIST_OF_REQUISITE_FILES :#line:190
		if not c .exists (ab ):#line:191
			aa =True #line:192
			break #line:193
	if aa :#line:194
		_x .print_with_a_frame (_w .get_error_message (_w .ERROR_REQUISITE_FILES_ABSENT ))#line:195
		exit_program ()#line:196
	ac =open (CURRENT_CLASS_LIST_FILE ,"r")#line:199
	ad =ac .read ().split ()#line:200
	ac .close ()#line:201
	if z not in ad :#line:204
		_x .print_with_a_frame (_w .get_error_message (_w .ERROR_MISSING_STUDENT_NUMBER ))#line:205
	print ("     ┌─[ OVERVIEW ]───────────────────────────────────────────────────────┐     ")#line:208
	print ("     │                                                                    │     ")#line:209
	print ("     │ For this assignment you will create a program that takes a student │     ")#line:210
	print ("     │ number from the user (submitted as a command-line variable) and    │     ")#line:211
	print ("     │ uses that data as part of a longer process. Regardless of the      │     ")#line:212
	print ("     │ student number the user submits, the process that was assigned to  │     ")#line:213
	print ("     │ your student number will always eventually produce an uppercase    │     ")#line:214
	print ("     │ letter 'A' as its final result.                                    │     ")#line:215
	print ("     │                                                                    │     ")#line:216
	print ("     │ As a clarifying example, the process defined below would always    │     ")#line:217
	print ("     │ produce the number 3 as its final result.                          │     ")#line:218
	print ("     │                                                                    │     ")#line:219
	print ("     │ PLEASE NOTE THAT THIS PROCESS IS ONLY INCLUDED AS AN EXAMPLE!      │     ")#line:220
	print ("     │                                                                    │     ")#line:221
	print ("     │ THE PROCESS THAT HAS BEEN ASSIGNED SPECIFICALLY TO YOUR STUDENT    │     ")#line:222
	print ("     │ NUMBER HAS BEEN DESCRIBED BELOW IN THE 'INSTRUCTIONS' SECTION!     │     ")#line:223
	print ("     │                                                                    │     ")#line:224
	print ("     │  1. Convert the command line argument to an integer.               │     ")#line:225
	print ("     │                                                                    │     ")#line:226
	print ("     │  2. Double that integer and print it to the screen.                │     ")#line:227
	print ("     │                                                                    │     ")#line:228
	print ("     │  3. Add 9 to the result and print it to the screen.                │     ")#line:229
	print ("     │                                                                    │     ")#line:230
	print ("     │  4. Subtract 3 from the result and print it to the screen.         │     ")#line:231
	print ("     │                                                                    │     ")#line:232
	print ("     │  5. Divide the result by 2 and print it to the screen.             │     ")#line:233
	print ("     │                                                                    │     ")#line:234
	print ("     │  6. Subtract the original number from the result.                  │     ")#line:235
	print ("     │                                                                    │     ")#line:236
	print ("     │  7. Print the final result to the screen. (It should be 3).        │     ")#line:237
	print ("     │                                                                    │     ")#line:238
	print ("     │ Thus, if you were to run this program from the terminal you        │     ")#line:239
	print ("     │ would see the following:                                           │     ")#line:240
	print ("     │                                                                    │     ")#line:241
	print ("     │ > python3 comp1405_f17_#########_a2.py 123456789                   │     ")#line:242
	print ("     │ 246913578                                                          │     ")#line:243
	print ("     │ 246913587                                                          │     ")#line:244
	print ("     │ 246913584                                                          │     ")#line:245
	print ("     │ 123456792                                                          │     ")#line:246
	print ("     │ 3                                                                  │     ")#line:247
	print ("     │                                                                    │     ")#line:248
	print ("     │ Your first seven lines of your submission must be a completed      │     ")#line:249
	print ("     │ copy of the following header and it must be reproduced exactly.    │     ")#line:250
	print ("     │                                                                    │     ")#line:251
	print ("     │ Check cuLearn for a sample assignment header that you may copy.    │     ")#line:252
	print ("     │                                                                    │     ")#line:253
	print ("     │ # ============================================================     │     ")#line:254
	print ("     │ #                                                                  │     ")#line:255
	print ("     │ # Student Name (as it appears on cuLearn): ????? ?????             │     ")#line:256
	print ("     │ # Student ID (9 digits in angle brackets): <?????????>             │     ")#line:257
	print ("     │ # Course Code (for this current semester): COMP1405?               │     ")#line:258
	print ("     │ #                                                                  │     ")#line:259
	print ("     │ # ============================================================     │     ")#line:260
	print ("     │                                                                    │     ")#line:261
	print ("     │ Replace the questions marks in the sample with your name,          │     ")#line:262
	print ("     │ student ID, and the letter indicating the section of COMP1405      │     ")#line:263
	print ("     │ (i.e., A or B) in which you are enrolled. Please note that the     │     ")#line:264
	print ("     │ student number must be enclosed in the angle brackets. As a        │     ")#line:265
	print ("     │ clarifying example, if your name was Robert Collier, your          │     ")#line:266
	print ("     │ student ID was 123456789, and you were enrolled in section A,      │     ")#line:267
	print ("     │ then the first seven lines of your submission must be:             │     ")#line:268
	print ("     │                                                                    │     ")#line:269
	print ("     │ # ============================================================     │     ")#line:270
	print ("     │ #                                                                  │     ")#line:271
	print ("     │ # Student Name (as it appears on cuLearn): Robert Collier          │     ")#line:272
	print ("     │ # Student ID (9 digits in angle brackets): <123456789>             │     ")#line:273
	print ("     │ # Course Code (for this current semester): COMP1405A               │     ")#line:274
	print ("     │ #                                                                  │     ")#line:275
	print ("     │ # ============================================================     │     ")#line:276
	print ("     │                                                                    │     ")#line:277
	print ("     │ Your submission must also use a specific filename in order for it  │     ")#line:278
	print ("     │ to be located by the marking utility; your submission must have    │     ")#line:279
	print ("     │ filename 'comp1405_f17_#########_a2.py', with the number signs     │     ")#line:280
	print ("     │ replaced by your nine digit student number.                        │     ")#line:281
	print ("     │                                                                    │     ")#line:282
	print ("     │ There are also several additional restrictions on your program.    │     ")#line:283
	print ("     │ You must not use functions that are not explicitly permitted, and  │     ")#line:284
	print ("     │ the only library you may import is sys. This assignment does not   │     ")#line:285
	print ("     │ use pygame in any way.                                             │     ")#line:286
	print ("     │                                                                    │     ")#line:287
	print ("     └────────────────────────────────────────────────────────────────────┘     ")#line:288
	ae =generate_assignment_instructions (z )#line:291
	_x .print_with_a_frame (("INSTRUCTIONS",ae ))#line:294
	print ()#line:296
	print ("     ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^     ")#line:297
	print ("     SCROLL UP TO THE OVERVIEW SECTION AND ENSURE YOU READ ALL INSTRUCTIONS     ")#line:298
	print ("     ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^     ")#line:299
	print ()#line:300
	exit_program ()#line:303

if __name__ =="__main__":#line:307
    main ()



#32 variable

上面是修改过的generator,在运行generator的同时会生成一个代码文件

总结:

相较于上一个assignment generator来说,这个generator可以直接获取到关键的数据,从而直接生成相应的code。总体来说难度较低。

Research on python assignment generator

生成器相关:

今天看到了一个assignment generator, 感觉有些意思,就打开来研究研究

import pygame as O00000O0OO00OOO0O #line:2
from pygame .locals import *#line:3
from os import getcwd as O0OO0O0OOO00000O0 ,listdir as OOOO0O0O0O0OOO0O0 ,path as OO000OO0OO0OO0OO0 ,remove as O000OO0O00O0O00OO #line:5
from sys import argv as OO00O0OO00OOO00O0 #line:6
from zipfile import ZipFile as O0O0O0O0000OOO00O #line:7
from time import sleep as O0O0000O0OOOOO0OO #line:8
CURRENT_CLASS_LIST_FILE ="initial_class_list.dat"#line:12
LIST_OF_REQUISITE_FILES =[CURRENT_CLASS_LIST_FILE ]+["supplementary_data.dat"]#line:13
LIST_OF_LIBRARY_MODULES =["_liberr.py","_libtui.py","_libprg.py"]#line:18
'''
This will remove all the files that were extracted from the companion

@params                      none
@return                      none
'''#line:26
def clean_current_working_directory ():#line:27
	OOO0O00O00O00000O =OOOO0O0O0O0OOO0O0 (O0OO0O0OOO00000O0 ())#line:29
	for OO0O00O0OOO00OOO0 in OOO0O00O00O00000O :#line:32
		OO0O000OOO00O0OOO =OO000OO0OO0OO0OO0 .join (O0OO0O0OOO00000O0 (),OO0O00O0OOO00OOO0 )#line:35
		if not OO000OO0OO0OO0OO0 .isdir (OO0O000OOO00O0OOO )and (OO0O00O0OOO00OOO0 in LIST_OF_REQUISITE_FILES or OO0O00O0OOO00OOO0 in LIST_OF_LIBRARY_MODULES ):#line:38
			O000OO0O00O0O00OO (OO0O00O0OOO00OOO0 )#line:40
'''
This is end the program after cleaning the current working directory

@params                      none
@return                      none
'''#line:48
def exit_program ():#line:49
	clean_current_working_directory ()#line:50
	exit ()#line:51
'''
This is the actual instruction generator that is specific to this assignment

@params                      none
@return                      none
'''#line:59
def generate_assignment_instructions (O0OOO00O000OO0OO0 ):#line:60
	import _libprg as _OOOOO0OO0O0O0O000 #line:62
	OO0OO000O0OO0OO00 =48 #line:64
	OO0O00O0OO0O00OOO =56 #line:65
	O00O0OOOO0OOO0OO0 =open ("initial_class_list.dat","r")#line:71
	OO00OOO0O000OO000 =0 #line:72
	while True :#line:73
		OO00O0O0OO000OOOO =O00O0OOOO0OOO0OO0 .readline ().strip ()#line:74
		OO00OOO0O000OO000 +=1 #line:75
		if not OO00O0O0OO000OOOO or OO00O0O0OO000OOOO ==O0OOO00O000OO0OO0 :#line:77
			break #line:78
	O00O0OOOO0OOO0OO0 .close ()#line:79
	if not OO00O0O0OO000OOOO :#line:81
		OO00OOO0O000OO000 =0 #line:82
	OOOO00O0O0000O0O0 =open ("supplementary_data.dat",encoding ='utf-8')#line:86
	OOO00OO0O00OO00OO =OO00OOO0O000OO000 *OO0OO000O0OO0OO00 *OO0O00O0OO0O00OOO #line:87
	for _O00O0O0O0O0O00O00 in range (OOO00OO0O00OO00OO ):#line:88
		_O00O0O0O0O0O00O00 =OOOO00O0O0000O0O0 .read (3 )#line:89
	O00000O0OO00OOO0O .init ()#line:91
	OOO0OOO0OOOO0O0O0 =O00000O0OO00OOO0O .display .set_mode ((OO0OO000O0OO0OO00 *5 ,OO0O00O0OO0O00OOO *5 ))#line:92
	O00O0O0OOOOO0OO0O =O00000O0OO00OOO0O .Surface ((OO0OO000O0OO0OO00 ,OO0O00O0OO0O00OOO ))#line:93
	O00O0O0OOOOO0OO0O .fill ((0 ,0 ,0 ))#line:94
	O00O0O0OOOOO0OO0O =O00O0O0OOOOO0OO0O .convert ()#line:95
	OO000O0OO0OO0000O =0 #line:97
	OOO0000O0O000O00O =0 #line:98
	OOOOO000OO0OO0O0O ="right"#line:100
	O00OOOO0O000O00O0 =0 #line:102
	O00OOO0O00OOOO000 =(OO0OO000O0OO0OO00 -1 )#line:103
	O00OOO00OO00OO000 =1 #line:104
	OO0O00O00O000OO00 =(OO0O00O0OO0O00OOO -1 )#line:105
	for OO0OOO00OOOO0O0OO in range (OO0OO000O0OO0OO00 *OO0O00O0OO0O00OOO ):#line:107
		OOOO0O000OOOO0OOO =OOOO00O0O0000O0O0 .read (3 )#line:109
		(OO0O0OOOOO00OO0O0 ,OO00OOO00O0O00O0O ,OOOO0O00OO00O0O00 )=[ord (OO0OOOOO0OOO000OO )for OO0OOOOO0OOO000OO in OOOO0O000OOOO0OOO ]#line:110
		O00O0O0OOOOO0OO0O .set_at ((OO000O0OO0OO0000O ,OOO0000O0O000O00O ),(OO0O0OOOOO00OO0O0 ,OO00OOO00O0O00O0O ,OOOO0O00OO00O0O00 ))#line:112
		if OOOOO000OO0OO0O0O =="right":#line:114
			OO000O0OO0OO0000O =OO000O0OO0OO0000O +1 #line:115
			if OO000O0OO0OO0000O ==O00OOO0O00OOOO000 :#line:116
				O00OOO0O00OOOO000 =O00OOO0O00OOOO000 -1 #line:117
				OOOOO000OO0OO0O0O ='down'#line:118
		elif OOOOO000OO0OO0O0O =="down":#line:119
			OOO0000O0O000O00O =OOO0000O0O000O00O +1 #line:120
			if OOO0000O0O000O00O ==OO0O00O00O000OO00 :#line:121
				OO0O00O00O000OO00 =OO0O00O00O000OO00 -1 #line:122
				OOOOO000OO0OO0O0O ='left'#line:123
		elif OOOOO000OO0OO0O0O =="left":#line:124
			OO000O0OO0OO0000O =OO000O0OO0OO0000O -1 #line:125
			if OO000O0OO0OO0000O ==O00OOOO0O000O00O0 :#line:126
				O00OOOO0O000O00O0 =O00OOOO0O000O00O0 +1 #line:127
				OOOOO000OO0OO0O0O ='up'#line:128
		elif OOOOO000OO0OO0O0O =="up":#line:129
			OOO0000O0O000O00O =OOO0000O0O000O00O -1 #line:130
			if OOO0000O0O000O00O ==O00OOO00OO00OO000 :#line:131
				O00OOO00OO00OO000 =O00OOO00OO00OO000 +1 #line:132
				OOOOO000OO0OO0O0O ='right'#line:133
		if OO0OOO00OOOO0O0OO %10 ==0 :#line:135
			OOO0OOO0OOOO0O0O0 .blit (O00O0O0OOOOO0OO0O ,(0 ,0 ))#line:136
			O00000O0OO00OOO0O .display .flip ()#line:137
	OOOO00O0O0000O0O0 .close ()#line:139
	O00000O0OO00OOO0O .image .save (O00O0O0OOOOO0OO0O ,"your-assigned-image.png")#line:140
	O00O0O0OOOOO0OO0O =O00000O0OO00OOO0O .transform .scale (O00O0O0OOOOO0OO0O ,(OO0OO000O0OO0OO00 *5 ,OO0O00O0OO0O00OOO *5 ))#line:141
	OOO0OOO0OOOO0O0O0 .blit (O00O0O0OOOOO0OO0O ,(0 ,0 ))#line:142
	O00000O0OO00OOO0O .display .update ()#line:143
	OOO0OOO00O00OO0OO =["You must import and use the pygame library and you are not permitted to use any other libraries in your submission.","You may use the init, fill, polygon, save, set_mode, and update functions to complete this assignment. No other functions are permitted.","You must create a surface that is 48 pixels wide by 56 pixels high. If your image is not the correct size your submission is invalid.","You must use four calls to the pygame.draw.polygon function to create your shapes. No other shape or pixel drawing functions are permitted.","You must use the pygame.image.save function to save your image as a png file. You must use your student number as the filename, so you must save your drawing surface using '"+O0OOO00O000OO0OO0 +".png' as the filename.","The file 'your-assigned-image.png' has been created. This is image you are expected to reproduce, actual size. A window has also appeared, showing you a magnified (5x) copy of your assigned image. Close this window to end this program. Good luck!"]#line:155
	return OOO0OOO00O00OO0OO #line:157
'''
This is the main function, primarily responsible for extracting files from the
companion archive and ensuring that the generator will actually able be able
to function with the arguments that have been provided

@params                      none
@return                      none
'''#line:167
def main ():#line:168
	clean_current_working_directory ()#line:171
	try :#line:174
		with O0O0O0O0000OOO00O (OO00O0OO00OOO00O0 [0 ].replace ("generator","companion").replace (".py","._z"),"r")as O000O0O0OO000OO00 :#line:175
			O000O0O0OO000OO00 .extractall ()#line:176
	except :#line:177
		print ("")#line:178
		print ("     ┌─[ ERROR 00 ]───────────────────────────────────────────────────────┐     ")#line:179
		print ("     │                                                                    │     ")#line:180
		print ("     │ One of the files required by this generator could not be found.    │     ")#line:181
		print ("     │ When you downloaded the generator from cuLearn it was part of a    │     ")#line:182
		print ("     │ zip archive of three files - the generator, the validator, and     │     ")#line:183
		print ("     │ the companion. The generator cannot proceed because it cannot      │     ")#line:184
		print ("     │ locate the companion file. Redownload the archive from cuLearn     │     ")#line:185
		print ("     │ and then try running the generator again.                          │     ")#line:186
		print ("     │                                                                    │     ")#line:187
		print ("     └────────────────────────────────────────────────────────────────────┘     ")#line:188
		print ("")#line:189
		exit_program ()#line:190
	import _liberr as _O0OOO0000000O0OO0 #line:193
	import _libtui as _O00OOOO00000O000O #line:194
	_O00OOOO00000O000O .clear_screen ()#line:197
	print ("     ** PLEASE NOTE:  IF YOU FAIL TO FOLLOW THESE INSTRUCTIONS PRECISELY **     ")#line:199
	print ("     **               YOUR SUBMISSION WILL RECEIVE A FINAL MARK OF ZERO. **     ")#line:200
	O000000000OOO0OOO =len (OO00O0OO00OOO00O0 )#line:203
	if O000000000OOO0OOO <2 :#line:204
		_O00OOOO00000O000O .print_with_a_frame (_O0OOO0000000O0OO0 .get_error_message (_O0OOO0000000O0OO0 .ERROR_INSUFFICIENT_ARGUMENTS ),False )#line:205
		exit_program ()#line:206
	O0OO0OO00OOOOOO0O =OO00O0OO00OOO00O0 [1 ]#line:209
	if not (O0OO0OO00OOOOOO0O .isdigit ()and len (O0OO0OO00OOOOOO0O )==9 ):#line:210
		_O00OOOO00000O000O .print_with_a_frame (_O0OOO0000000O0OO0 .get_error_message (_O0OOO0000000O0OO0 .ERROR_INVALID_STUDENT_NUMBER ),False )#line:211
		exit_program ()#line:212
	O00O0O00000O0OOOO =False #line:215
	for O0OO00O0O0OO0OOO0 in LIST_OF_REQUISITE_FILES +LIST_OF_LIBRARY_MODULES :#line:216
		if not OO000OO0OO0OO0OO0 .exists (O0OO00O0O0OO0OOO0 ):#line:217
			O00O0O00000O0OOOO =True #line:218
			break #line:219
	if O00O0O00000O0OOOO :#line:220
		_O00OOOO00000O000O .print_with_a_frame (_O0OOO0000000O0OO0 .get_error_message (_O0OOO0000000O0OO0 .ERROR_REQUISITE_FILES_ABSENT ),False )#line:221
		exit_program ()#line:222
	O0O000O0OO0OOO0O0 =open (CURRENT_CLASS_LIST_FILE ,"r")#line:225
	O0OO0O0O000000000 =O0O000O0OO0OOO0O0 .read ().split ()#line:226
	O0O000O0OO0OOO0O0 .close ()#line:227
	if O0OO0OO00OOOOOO0O not in O0OO0O0O000000000 :#line:230
		_O00OOOO00000O000O .print_with_a_frame (_O0OOO0000000O0OO0 .get_error_message (_O0OOO0000000O0OO0 .ERROR_MISSING_STUDENT_NUMBER ),False )#line:231
	print ("     ┌─[ OVERVIEW ]───────────────────────────────────────────────────────┐     ")#line:234
	print ("     │                                                                    │     ")#line:235
	print ("     │ For this assignment you will create a program that uses the        │     ")#line:236
	print ("     │ pygame library to reproduce the image that has been assigned to    │     ")#line:237
	print ("     │ you. This image has been magnified and made to appear on your      │     ")#line:238
	print ("     │ screen and it has also been saved to your computer as 'your-       │     ")#line:239
	print ("     │ assigned-image.png'. Your facsimile must use exactly the same      │     ")#line:240
	print ("     │ colours and fit on a surface that is 48 pixels wide and 56         │     ")#line:241
	print ("     │ pixels high. The mark you received on this assignment will be      │     ")#line:242
	print ("     │ determined by how accurately you have reproduced your assigned     │     ")#line:243
	print ("     │ image.                                                             │     ")#line:244
	print ("     │                                                                    │     ")#line:245
	print ("     │ Your first seven lines of your submission must be a completed      │     ")#line:246
	print ("     │ copy of the following header and it must be reproduced exactly.    │     ")#line:247
	print ("     │                                                                    │     ")#line:248
	print ("     │ # ============================================================     │     ")#line:249
	print ("     │ #                                                                  │     ")#line:250
	print ("     │ # Student Name (as it appears on cuLearn): ????? ?????             │     ")#line:251
	print ("     │ # Student ID (9 digits in angle brackets): <?????????>             │     ")#line:252
	print ("     │ # Course Code (for this current semester): COMP1405?               │     ")#line:253
	print ("     │ #                                                                  │     ")#line:254
	print ("     │ # ============================================================     │     ")#line:255
	print ("     │                                                                    │     ")#line:256
	print ("     │ Replace the questions marks in the sample with your name,          │     ")#line:257
	print ("     │ student ID, and the letter indicating the section of COMP1405      │     ")#line:258
	print ("     │ (i.e., A or B) in which you are enrolled. Please note that the     │     ")#line:259
	print ("     │ student number must be enclosed in the angle brackets. As a        │     ")#line:260
	print ("     │ clarifying example, if your name was Robert Collier, your          │     ")#line:261
	print ("     │ student ID was 123456789, and you were enrolled in section A,      │     ")#line:262
	print ("     │ then the first seven lines of your submission must be:             │     ")#line:263
	print ("     │                                                                    │     ")#line:264
	print ("     │ # ============================================================     │     ")#line:265
	print ("     │ #                                                                  │     ")#line:266
	print ("     │ # Student Name (as it appears on cuLearn): Robert Collier          │     ")#line:267
	print ("     │ # Student ID (9 digits in angle brackets): <123456789>             │     ")#line:268
	print ("     │ # Course Code (for this current semester): COMP1405A               │     ")#line:269
	print ("     │ #                                                                  │     ")#line:270
	print ("     │ # ============================================================     │     ")#line:271
	print ("     │                                                                    │     ")#line:272
	print ("     │ Your submission must also use a specific filename in order for it  │     ")#line:273
	print ("     │ to be located by the marking utility; your submission must have    │     ")#line:274
	print ("     │ filename 'comp1405_f17_#########_a1.py', with the number signs     │     ")#line:275
	print ("     │ replaced by your nine digit student number.                        │     ")#line:276
	print ("     │                                                                    │     ")#line:277
	print ("     │ There are also several additional restrictions on how you must     │     ")#line:278
	print ("     │ reproduce your assigned image. See the instructions listed below.  │     ")#line:279
	print ("     │                                                                    │     ")#line:280
	print ("     └────────────────────────────────────────────────────────────────────┘     ")#line:281
	OOOOOO00O0OOO0OO0 =generate_assignment_instructions (O0OO0OO00OOOOOO0O )#line:285
	_O00OOOO00000O000O .print_with_a_frame (("INSTRUCTIONS",OOOOOO00O0OOO0OO0 ))#line:288
	print ()#line:290
	print ("     ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^     ")#line:291
	print ("     SCROLL UP TO THE OVERVIEW SECTION AND ENSURE YOU READ ALL INSTRUCTIONS     ")#line:292
	print ("     ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^     ")#line:293
	print ()#line:294
	O00OOOOO0000OOO00 =False #line:296
	while not O00OOOOO0000OOO00 :#line:297
		for O0000OO000O000O00 in O00000O0OO00OOO0O .event .get ():#line:298
			if O0000OO000O000O00 .type ==QUIT :#line:299
				O00OOOOO0000OOO00 =True #line:300
	exit_program ()#line:303
''' the (only) "top-level" code in the generator for calling main() '''#line:306
if __name__ =="__main__":#line:307
    main ()

上面的code出自comp1405 assignment1 的generator

作者是Robert Collier

通过简单的浏览,我们可以看到几乎所有的变量都用数字0和字母O 来混淆

但python有自带的加密的code的方式,感觉用这种自带的加密方式比混淆代码效果好得多

 

经过简单的分析后,并把变量用字母重新命名后,得到:

import pygame as a #line:2
from pygame .locals import *#line:3
from os import getcwd as b ,listdir as c ,path as d ,remove as e #line:5
from sys import argv as f #line:6
from zipfile import ZipFile as g #line:7
from time import sleep as h #line:8
CURRENT_CLASS_LIST_FILE ="initial_class_list.dat"#line:12
LIST_OF_REQUISITE_FILES =[CURRENT_CLASS_LIST_FILE ]+["supplementary_data.dat"]#line:13
LIST_OF_LIBRARY_MODULES =["_liberr.py","_libtui.py","_libprg.py"]#line:18
'''
This will remove all the files that were extracted from the companion

@params                      none
@return                      none
'''#line:26
def clean_current_working_directory ():#line:27
	i =c (b ())#line:29
	for j in i :#line:32
		k =d .join (b (),j )#line:35
		if not d .isdir (k )and (j in LIST_OF_REQUISITE_FILES or j in LIST_OF_LIBRARY_MODULES ):#line:38
			e (j )#line:40
'''
This is end the program after cleaning the current working directory

@params                      none
@return                      none
'''#line:48
def exit_program ():#line:49
	clean_current_working_directory ()#line:50
	exit ()#line:51
'''
This is the actual instruction generator that is specific to this assignment

@params                      none
@return                      none
'''#line:59
def generate_assignment_instructions (l ):#line:60
	import _libprg as _m #line:62
	n =48 #line:64
	o =56 #line:65
	p =open ("initial_class_list.dat","r")#line:71
	q =0 #line:72
	while True :#line:73
		r =p .readline ().strip ()#line:74
		q +=1 #line:75
		if not r or r ==l :#line:77
			break #line:78
	p .close ()#line:79
	if not r :#line:81
		q =0 #line:82
	s =open ("supplementary_data.dat",encoding ='utf-8')#line:86
	t =q *n *o #line:87
	for _u in range (t ):#line:88
		_u =s .read (3 )#line:89
	a .init ()#line:91
	v =a .display .set_mode ((n *5 ,o *5 ))#line:92
	w =a .Surface ((n ,o ))#line:93
	w .fill ((0 ,0 ,0 ))#line:94
	w =w .convert ()#line:95
	x =0 #line:97
	y =0 #line:98
	z ="right"#line:100
	aa =0 #line:102
	ab =(n -1 )#line:103
	ac =1 #line:104
	ad =(o -1 )#line:105
	for ae in range (n *o ):#line:107
		af =s .read (3 )#line:109
		(ag ,ah ,ai )=[ord (aj )for aj in af ]#line:110
		w .set_at ((x ,y ),(ag ,ah ,ai ))#line:112
		if z =="right":#line:114
			x =x +1 #line:115
			if x ==ab :#line:116
				ab =ab -1 #line:117
				z ='down'#line:118
		elif z =="down":#line:119
			y =y +1 #line:120
			if y ==ad :#line:121
				ad =ad -1 #line:122
				z ='left'#line:123
		elif z =="left":#line:124
			x =x -1 #line:125
			if x ==aa :#line:126
				aa =aa +1 #line:127
				z ='up'#line:128
		elif z =="up":#line:129
			y =y -1 #line:130
			if y ==ac :#line:131
				ac =ac +1 #line:132
				z ='right'#line:133
		if ae %10 ==0 :#line:135
			v .blit (w ,(0 ,0 ))#line:136
			a .display .flip ()#line:137
	s .close ()#line:139
	a .image .save (w ,"your-assigned-image.png")#line:140
	w =a .transform .scale (w ,(n *5 ,o *5 ))#line:141
	v .blit (w ,(0 ,0 ))#line:142
	a .display .update ()#line:143
	ak =["You must import and use the pygame library and you are not permitted to use any other libraries in your submission.","You may use the init, fill, polygon, save, set_mode, and update functions to complete this assignment. No other functions are permitted.","You must create a surface that is 48 pixels wide by 56 pixels high. If your image is not the correct size your submission is invalid.","You must use four calls to the pygame.draw.polygon function to create your shapes. No other shape or pixel drawing functions are permitted.","You must use the pygame.image.save function to save your image as a png file. You must use your student number as the filename, so you must save your drawing surface using '"+l +".png' as the filename.","The file 'your-assigned-image.png' has been created. This is image you are expected to reproduce, actual size. A window has also appeared, showing you a magnified (5x) copy of your assigned image. Close this window to end this program. Good luck!"]#line:155
	return ak #line:157
'''
This is the main function, primarily responsible for extracting files from the
companion archive and ensuring that the generator will actually able be able
to function with the arguments that have been provided

@params                      none
@return                      none
'''#line:167
def main ():#line:168
	clean_current_working_directory ()#line:171
	try :#line:174
		with g (f [0 ].replace ("generator","companion").replace (".py","._z"),"r")as al :#line:175
			al .extractall ()#line:176
	except :#line:177
		print ("")#line:178
		print ("     ┌─[ ERROR 00 ]───────────────────────────────────────────────────────┐     ")#line:179
		print ("     │                                                                    │     ")#line:180
		print ("     │ One of the files required by this generator could not be found.    │     ")#line:181
		print ("     │ When you downloaded the generator from cuLearn it was part of a    │     ")#line:182
		print ("     │ zip archive of three files - the generator, the validator, and     │     ")#line:183
		print ("     │ the companion. The generator cannot proceed because it cannot      │     ")#line:184
		print ("     │ locate the companion file. Redownload the archive from cuLearn     │     ")#line:185
		print ("     │ and then try running the generator again.                          │     ")#line:186
		print ("     │                                                                    │     ")#line:187
		print ("     └────────────────────────────────────────────────────────────────────┘     ")#line:188
		print ("")#line:189
		exit_program ()#line:190
	import _liberr as _am #line:193
	import _libtui as _an #line:194
	_an .clear_screen ()#line:197
	print ("     ** PLEASE NOTE:  IF YOU FAIL TO FOLLOW THESE INSTRUCTIONS PRECISELY **     ")#line:199
	print ("     **               YOUR SUBMISSION WILL RECEIVE A FINAL MARK OF ZERO. **     ")#line:200
	ao =len (f )#line:203
	if ao <2 :#line:204
		_an .print_with_a_frame (_am .get_error_message (_am .ERROR_INSUFFICIENT_ARGUMENTS ),False )#line:205
		exit_program ()#line:206
	ap =f [1 ]#line:209
	if not (ap .isdigit ()and len (ap )==9 ):#line:210
		_an .print_with_a_frame (_am .get_error_message (_am .ERROR_INVALID_STUDENT_NUMBER ),False )#line:211
		exit_program ()#line:212
	aq =False #line:215
	for ar in LIST_OF_REQUISITE_FILES +LIST_OF_LIBRARY_MODULES :#line:216
		if not d .exists (ar ):#line:217
			aq =True #line:218
			break #line:219
	if aq :#line:220
		_an .print_with_a_frame (_am .get_error_message (_am .ERROR_REQUISITE_FILES_ABSENT ),False )#line:221
		exit_program ()#line:222
	at =open (CURRENT_CLASS_LIST_FILE ,"r")#line:225
	au =at .read ().split ()#line:226
	at .close ()#line:227
	if ap not in au :#line:230
		_an .print_with_a_frame (_am .get_error_message (_am .ERROR_MISSING_STUDENT_NUMBER ),False )#line:231
	print ("     ┌─[ OVERVIEW ]───────────────────────────────────────────────────────┐     ")#line:234
	print ("     │                                                                    │     ")#line:235
	print ("     │ For this assignment you will create a program that uses the        │     ")#line:236
	print ("     │ pygame library to reproduce the image that has been assigned to    │     ")#line:237
	print ("     │ you. This image has been magnified and made to appear on your      │     ")#line:238
	print ("     │ screen and it has also been saved to your computer as 'your-       │     ")#line:239
	print ("     │ assigned-image.png'. Your facsimile must use exactly the same      │     ")#line:240
	print ("     │ colours and fit on a surface that is 48 pixels wide and 56         │     ")#line:241
	print ("     │ pixels high. The mark you received on this assignment will be      │     ")#line:242
	print ("     │ determined by how accurately you have reproduced your assigned     │     ")#line:243
	print ("     │ image.                                                             │     ")#line:244
	print ("     │                                                                    │     ")#line:245
	print ("     │ Your first seven lines of your submission must be a completed      │     ")#line:246
	print ("     │ copy of the following header and it must be reproduced exactly.    │     ")#line:247
	print ("     │                                                                    │     ")#line:248
	print ("     │ # ============================================================     │     ")#line:249
	print ("     │ #                                                                  │     ")#line:250
	print ("     │ # Student Name (as it appears on cuLearn): ????? ?????             │     ")#line:251
	print ("     │ # Student ID (9 digits in angle brackets): <?????????>             │     ")#line:252
	print ("     │ # Course Code (for this current semester): COMP1405?               │     ")#line:253
	print ("     │ #                                                                  │     ")#line:254
	print ("     │ # ============================================================     │     ")#line:255
	print ("     │                                                                    │     ")#line:256
	print ("     │ Replace the questions marks in the sample with your name,          │     ")#line:257
	print ("     │ student ID, and the letter indicating the section of COMP1405      │     ")#line:258
	print ("     │ (i.e., A or B) in which you are enrolled. Please note that the     │     ")#line:259
	print ("     │ student number must be enclosed in the angle brackets. As a        │     ")#line:260
	print ("     │ clarifying example, if your name was Robert Collier, your          │     ")#line:261
	print ("     │ student ID was 123456789, and you were enrolled in section A,      │     ")#line:262
	print ("     │ then the first seven lines of your submission must be:             │     ")#line:263
	print ("     │                                                                    │     ")#line:264
	print ("     │ # ============================================================     │     ")#line:265
	print ("     │ #                                                                  │     ")#line:266
	print ("     │ # Student Name (as it appears on cuLearn): Robert Collier          │     ")#line:267
	print ("     │ # Student ID (9 digits in angle brackets): <123456789>             │     ")#line:268
	print ("     │ # Course Code (for this current semester): COMP1405A               │     ")#line:269
	print ("     │ #                                                                  │     ")#line:270
	print ("     │ # ============================================================     │     ")#line:271
	print ("     │                                                                    │     ")#line:272
	print ("     │ Your submission must also use a specific filename in order for it  │     ")#line:273
	print ("     │ to be located by the marking utility; your submission must have    │     ")#line:274
	print ("     │ filename 'comp1405_f17_#########_a1.py', with the number signs     │     ")#line:275
	print ("     │ replaced by your nine digit student number.                        │     ")#line:276
	print ("     │                                                                    │     ")#line:277
	print ("     │ There are also several additional restrictions on how you must     │     ")#line:278
	print ("     │ reproduce your assigned image. See the instructions listed below.  │     ")#line:279
	print ("     │                                                                    │     ")#line:280
	print ("     └────────────────────────────────────────────────────────────────────┘     ")#line:281
	av =generate_assignment_instructions (ap )#line:285
	_an .print_with_a_frame (("INSTRUCTIONS",av ))#line:288
	print ()#line:290
	print ("     ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^     ")#line:291
	print ("     SCROLL UP TO THE OVERVIEW SECTION AND ENSURE YOU READ ALL INSTRUCTIONS     ")#line:292
	print ("     ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^  ^     ")#line:293
	print ()#line:294
	aw =False #line:296
	while not aw :#line:297
		for ax in a .event .get ():#line:298
			if ax .type ==QUIT :#line:299
				aw =True #line:300
	exit_program ()#line:303
''' the (only) "top-level" code in the generator for calling main() '''#line:306
if __name__ =="__main__":#line:307
    main ()

核心功能在 generate_assignment_instructions这个函数中

 

这个函数先是定义了两个常数48 和 56,估计应该就是长和宽

之后的while 循环,通过传入的数据来进入学号列表中遍历

由此可以看出传入的数据为学号

 

这个while的功能非常简单

从前往后遍历学生号列表,并把每个学生号与传入的数据进行对比

如果不对就上面的变量就+1,如果相等就break

 

得到学生号的index后,可以根据index来生成相对来说的针对每个人的assignment

 

之后我们可以看到在这个函数中,几乎所有的功能都是围绕在变量w在进行相关操作, 尤其是56行到59行。 从这三行我们可以确定w就是drawing window。但在下面的for循环中,我们可以看到作者用了w.set_at()函数。 这个函数是把某个像素点来设置为相应的颜色。 这样的话我们就不能从generator来获得相关多边形的拐点的坐标。所以generator 的分析到此为止。

 

 

作弊器相关:

经过思考后,决定从生成的图片入手。

 

python自带的python image library 简称PIL是一个非常简单易用的图像操作软件

破解generator的思路如下:

1.运行generator来生成相应图片

2.用PIL来获得每个点RGB颜色信息。

3.通过相应算法来获得拐点的坐标

4.然后根据固定格式来生成代码文件

代码如下:

from PIL import Image

def FindUniqueColor(all_pixs):
    unique_color = []
    for x in range (0, len(all_pixs)):
        for y in range(0,len(all_pixs[x])):
            if unique_color.count(all_pixs[x][y]) == 0:
                unique_color.append(all_pixs[x][y])
    return unique_color


def FindEndPoint(allpixs,color):
    list =[]
    endpoints = []
    # 确定第一个端点
    for x in range(0,len(allpixs)):
        for y in range(0,len(allpixs[x])):
            if (allpixs[x][y] == color):
                list.append((x,y))
    endpoints.append(list[0])

    while True:
        twopix = FindConnectedPoint(allpixs,endpoints[len(endpoints) -1],color)
        if endpoints.count(twopix[0]) == 1 and endpoints.count(twopix[1]) == 1:
            break
        if endpoints.count(twopix[0]) == 0:
            endpoints.append(twopix[0])
        elif endpoints.count(twopix[1]) == 0:
            endpoints.append(twopix[1])
        else:
            break
    return endpoints

def FindConnectedPoint(allpixs,pix,color):
    #当我们已经知道一个端点后,找出他相邻的两个端点
    endpoint = []
    if allpixs[pix[0] + 1][pix[1]] == color and not InnerPointDector(allpixs,(pix[0] +1,pix[1]),color):
        #右
        p = (pix[0]+1,pix[1])
        while True:
            if InnerPointDector(allpixs,(p[0] +1,p[1]),color):
                endpoint.append(p)
                break
            if allpixs[p[0]+1][p[1]] != color:
                endpoint.append(p)
                break
            p = (p[0]+1,p[1])
    if allpixs[pix[0] + 1][pix[1] - 1] == color and not InnerPointDector(allpixs,(pix[0] + 1,pix[1] - 1),color):
        # 右下
        p = (pix[0] + 1,pix[1] -1)
        while True:
            if InnerPointDector(allpixs,(p[0] + 1,p[1] - 1),color):
                endpoint.append(p)
                break
            if allpixs[p[0]+1][p[1]-1] != color:
                endpoint.append(p)
                break
            p = (p[0] + 1, p[1] - 1)
    if allpixs[pix[0]][pix[1] - 1] == color and not InnerPointDector(allpixs,(pix[0],pix[1] - 1),color):
        #上
        p = (pix[0], pix[1] - 1)
        while True:
            if InnerPointDector(allpixs,(p[0],p[1] - 1),color):
                endpoint.append(p)
                break
            if allpixs[p[0]][p[1] - 1] != color:
                endpoint.append(p)
                break
            p = (p[0], p[1] - 1)
    if allpixs[pix[0] - 1][pix[1] - 1] == color and not InnerPointDector(allpixs,(pix[0] - 1,pix[1] - 1),color):
        #左上
        p = (pix[0] - 1, pix[1] - 1)
        while True:
            if InnerPointDector(allpixs,(p[0] - 1,p[1] - 1),color):
                endpoint.append(p)
                break
            if allpixs[p[0] - 1][p[1] - 1] != color:
                endpoint.append(p)
                break
            p = (p[0] - 1, p[1] -1)
    if allpixs[pix[0] - 1][pix[1]] == color and not InnerPointDector(allpixs,(pix[0] - 1,pix[1]),color):
        #左
        p = (pix[0] - 1,pix[1])
        while True:
            if InnerPointDector(allpixs,(p[0] - 1,p[1]),color):
                endpoint.append(p)
                break
            if allpixs[p[0] - 1][p[1]] != color:
                endpoint.append(p)
                break
            p = (p[0] - 1, p[1])
    if allpixs[pix[0] - 1][pix[1] + 1] == color and not InnerPointDector(allpixs,(pix[0] - 1,pix[1] + 1),color):
        #左下
        p = (pix[0] - 1, pix[1] + 1)
        while True:
            if InnerPointDector(allpixs,(p[0] - 1,p[1] + 1),color):
                endpoint.append(p)
                break
            if allpixs[p[0] - 1][p[1] + 1] != color:
                endpoint.append(p)
                break
            p = (p[0] -1, p[1] + 1)
    if allpixs[pix[0]][pix[1] + 1] == color and not InnerPointDector(allpixs,(pix[0],pix[1] + 1),color):
        #下
        p = (pix[0],pix[1] + 1)
        while True:
            if InnerPointDector(allpixs,(p[0],p[1] + 1),color):
                endpoint.append(p)
                break
            if allpixs[p[0]][p[1] + 1] != color:
                endpoint.append(p)
                break
            p = (p[0],p[1] + 1)
    if allpixs[pix[0] + 1][pix[1] + 1] == color and not InnerPointDector(allpixs,(pix[0] + 1,pix[1] + 1),color):
        #右下
        p = (pix[0] + 1, pix[1] + 1)
        while True:
            if InnerPointDector(allpixs,(p[0] + 1,p[1] + 1),color):
                endpoint.append(p)
                break
            if allpixs[p[0] + 1][p[1] + 1] != color:
                endpoint.append(p)
                break
            p = (p[0] + 1, p[1] + 1)

    return endpoint

def InnerPointDector (allpix, pix , color):
    #返回true说明这是一个内点
    #如果pix是一个内点的话,它的上下左右的点至少有一个是空的
    if allpix[pix[0] -1][pix[1]] == color:
        if allpix[pix[0] + 1][pix[1]] == color:
            if allpix[pix[0]][pix[1] - 1] == color:
                if allpix[pix[0]][pix[1] + 1] == color:
                    return True
    return False


def main():
    img_homework = Image.open("your-assigned-image.png")
    pix = img_homework.load()
    #pix is a 2d array contain all pixels
    pix_list = [[]]
    Endpointlist = [[]]
    # image size is 48*56

    # range is 0-47 and 0-55

    for x in range(0,48):
        for y in range(0,56):
            pix_list[x].append(pix[x,y])
        pix_list.append([])
    uniquecolors = FindUniqueColor(pix_list)
    for i in range(0,4):
        Endpointlist[i] = FindEndPoint(pix_list,uniquecolors[i+1])
        Endpointlist.append([])

    for i in range(0,4):
        for j in range(0,len(Endpointlist[i])):
            if pix_list[Endpointlist[i][j][0]][Endpointlist[i][j][1]] != uniquecolors[i+1]:
                Endpointlist[i].remove(Endpointlist[i][j])



    #图片识别部分完成,下面是文件生成部分
    print("hi")
    file = open("comp1405_f17_YOURSTUDENTNUMBERHERE_a1.py",'w+')
    file.write("# ============================================================\n")
    file.write("#                                                             \n")
    file.write("# Student Name (as it appears on cuLearn): Enter Your Name Here\n")
    file.write("# Student ID (9 digits in angle brackets): <123456789>\n")
    file.write("# Course Code (for this current semester): COMP1405A\n")
    file.write("#                                                             \n")
    file.write("# ============================================================\n")

    file.write("import pygame\n")
    file.write("pygame.init()\n")

    file.write("screen = pygame.display.set_mode((48,56))\n")
    file.write("screen.fill((255,255,255))\n")
    for i in range(0,4):
        file.write("pygame.draw.polygon(screen,")
        file.write(str(uniquecolors[i+1]))
        file.write(",(")
        for j in range(0,len(Endpointlist[i])):
            file.write(str(Endpointlist[i][j]))
            file.write(",")
        file.write("))\n")

    file.write("pygame.display.update()\n")
    file.write("pygame.image.save(screen,'YourStudentNumberHere.png')\n")
    print("DONE")


main()

 

第三点的算法部分思路如下:

1.遍历所有的像素点

2.获取背景颜色和四个图形的四种颜色

3.对于每种颜色来说,自左而右,自上而下,来遍历所有的点,一旦相等,那么这个点一定是顶点

4.找到第一个顶点后,在它的八个方向检查是否为空白点和内点(图形内部的点), 如果都不是的话,继续沿着那个方向走直到为空白点

5.把找到的两个内点中不在list中的点放入list中,

6.继续按照第四步的方法,把所有的拐点找到

 

验证器相关:

验证器其实非常简单,我们只要把通过generator生成的图片与我们用程序生成的图片的像素点的颜色进行比较,如果完全一样就是正确的。代码如下:

from PIL import Image

def main():
    img_original_name = "your-assigned-image.png";
    img_new_name = input("Please enter your generated image name. e.g. 101010123.png\n");

    img_original = Image.open(img_original_name)
    img_new = Image.open(img_new_name)

    pix_original = img_original.load()
    pix_new = img_new.load()

    not_good_point = []

    for x in range(0,48):
        for y in range(0,56):
            if pix_original[x,y] != pix_new[x,y]:
                not_good_point.append((x,y))
    if(len(not_good_point)==0):
        print("Good Work. All pixels are correct")
    else:
        for x in range(0,len(not_good_point)):
            string = "Point :("+ str(not_good_point[x][0]+1) + "," + str(not_good_point[x][1]+1) + "), color should be:"
            print(string,pix_original[not_good_point[x][0],not_good_point[x][1]],"instead of :", pix_new[not_good_point[x][0],not_good_point[x][1]])
            print("\n")


main()

 

总结:

这个generator的算法并不难懂,核心部分只有50多行代码,但由于generator的特性,实在没能想出直接通过generator来生成代码的作弊器。我做的这个作弊器在某些图形上会出现多扫点的情况,不过较为罕见。验证器也是十分简单,两个for循环来检查所有的像素点。

 

java连接mysql数据库通常方法

java连接mysql数据库一般由以下几个步骤组成:

  1. 导包,如
    Class.forName("com.mysql.jdbc.Driver");
  2. 创建connection:
    1. connection 一般从DriverManager.getConnection获取
    2. 参数一般由数据库地址和用户名密码(optional)组成
    3. 数据库地址的一般格式为:“jdbc:mysql://xxxxxxxx:3306/xxxx”
  3. 用PreparedStatement类来创建sql语句
    1. 从connection中获取PreparedStatement,并在参数中放入相应的sql语句
    2. sql语句中可以写入”?”作为占位符
    3. 可以用PreparedStatement的setString方法来填充占位符
  4. 用ResultSet类来接受PreparedStatement执行后的结果
    1. 用ResultSet类中的next()方法来步进到下一列
    2. 用getInt/getString/getFlost等方法来获取相应的数据,这些方法的参数为index of 列