Month: April 2015

python 答疑

问:

Python 2.7.6 (default, Sep  9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type “help”, “copyright”, “credits” or “license” for more information.
>>> s=”01234″
>>> s[0:1]
‘0’
>>>
字符串[:] 这种形式,也是左闭右开的区间吗?
所以
range(x,y) = [x,y] 等于数学上的 [ x, y)
答:
一般而言,无论是在python里还是其它的编程语言,range一般都是左闭右开。
不局限地python中的s[x:y],range(x,y)
像c++ STL中的begin(),end()等都是这样,end()-1才是最后一个元素。“
问:
python import copy中有 shallow copy 和 deep (recursive) copy
import copy

newobj = copy.copy(oldobj) # shallow copy
newobj = copy.deepcopy(oldobj) # deep (recursive) copy

对于dict={“string”:”string”, …} 这样的dict
shallow copy和deep (recursive) copy的结果是相同的, 都cop

polish to BNF via recrusive

  1. Implement a recursive function evalPolish(expression) that shall evaluate (calculate) an expression written in the prefix (“Polish”) notation. The expression shall be defined recursively in the Backus-Naur form (BNF):

    1. expression ::= integer_or_floating_point_number # A number is an expression; its value is the number itself
    2. expression ::= (operator, expression, expression) # A 3-element tuple of an operator and another two expressions is also an expression; its value is the operator applied to the values of the expressions
    3. operator ::= “+” | “-” | “*” | “/” # The list of supported operators; feel free to extend it

    Here is a sample expression and its evaluation:

    >>> good = ("+", ("-", 3, 1), ("*", ("/", 3, 4), 7)) # Same as

bmp manipulation

// ~ Overview ~ //

This exercise will familiarize you with structures, dynamic memory allocation, and
file operations.

// ~ Learning Goals ~ //

(1) To learn to read and write a structure into a file
(2) To learn to manipulate arrays

// ~ Submitting Your Assignment ~ //

You must submit one zip file to blackboard. This zip file must
contain:

(1) pe07.c
(2) bmp.c

You create the zip file using the following command.

> zip pe07.zip pe07.c bmp.c

// ~ Overview ~ //

The main purpose of this exercise is to familiarize you with
structures. It will also give you more practice with file operations
and memory allocation.

This exercise (and the next one) will gear you up for PA04, which
deals with an image format called BMP, which is commonly used in the Windows
operating system. Most web browsers are also able to read and display BMP files.
It is a modification of the exercise that Prof. Yung-Hsiang Lu gave to
his class.

In this exercise, you will read in a BMP file, and depending on the option
given, outpu

python questions

1.What is the value of the following expression:

sеt (rаngе (0, 20, 3)) & sеt (rangе (0, 20, 2))

{0, 6, 12, 18}

{0, 2, 3, 4, 6, 8, 9, 10, 12, 14, 15, 16, 18}

{3, 9, 15}

{2, 3, 4, 8, 9, 10, 14, 15, 16}

. 2.

Which operators are applicable to sets? (Check all that apply.)

+

*

&

|

^

/

in

. 3.

Which expression correctly changes the tail (the last element) of the middle item in the following

tuple:

foo=(12, [“a”, “n”, “d”, “y”], set (“andy”))

foo[1][-1] = “a”

foo[0][0] = “a”

Tuples are immutable and cannot be changed.

The tuple foo has items of different data types and is illegal.

. 4.

Which data type cannot be used as a key in a dictionary?

list

int

float

string

. 5.

Which data structures could be used instead of the following dictionary without any loss of

information and functionality, including possible modifications both of element names and their

weights?

elements = {“H” : 1, “He” : 4, “Li” : 7, “Be” : 9}

names = [“H”, “He”, “Li”, “Be”]

weights =

mfb21 solution

作业要求:

http://www.sussex.ac.uk/Users/mfb21/net/ex2/index.html

对于task1:
代码很少,主要功能就是输入一个URL,返回该网页的Status Code
CompilationTesterTask1.java就是直接给的样板测试文件 没做修改‍
住:    httpResultCode.get ( “www.mit.edu/” ); //在代码中改变URL可以得到不同测试结果
控制台命令:
Javac *.java (先编译)
Java Task1(执行main函数:看输出结果)
对于task2
共有五个java文件:
其中Class.java是事先给的,其中有函数的signature,抽象类等,其中Server和Client为两个接口
我在MyClient.java与MyServer.java里面继承了这两个抽象类,核心代码都在这里面
MyServer单独开了个线程作为服务器,通过start()函数开启线程,这样才能满足他给的测试代码的逻辑
其中CompilationTesterTask2.java就是事先给的测试代码,没做修改,但是测试代码的逻辑很奇怪:
You can use this code to check if your code compiles properly by compiling it t

python csv assignment

  • Write a command-line program that reads a comma-separated (CSV) file and reports some basic statistics of the data in the file.

    The program must have the comment at the top of the program file: “I certify this submission as my own original work completed in accordance with the Suffolk University Academic Integrity Policy. ZZZ”, where ZZZ is the full name of the student.

    The program shall ask the user to enter the name of a CSV file. If the file does not exist, the program shall print the error message: “File XXX does not exist.” where XXX is the file name, as entered by the user, and exit. Use the attached file grades.csv for testing.

    The program shall read the file contents. Assume that the file has a perfect rectangular structure: each uncommented row has the same number of columns, and each column has the same number of rows. A row that begins with a pound sign # is commented and shall be i

syr cis341 缓存区溢出漏洞利用实现

这个作业很刺激。。。

syr cis341 solution

Project 2: Buffer Overflow

1. Objective

Buffer overflows have been the most common form of security vulnerability in the

last ten years. Moreover, buffer overflow vulnerabilities dominate in the area of

remote network penetration vulnerabilities, where an anonymous Internet user seeks

to gain partial or total control of a host. These kinds of attacks enable anyone to take

total control of a host and thus represent one of the most serious security threats. [1]

Definition of buffer overflow from Wikipedia [2]: A buffer overflow, or buffer

overrun, is an anomaly where a program, while writing data to a buffer, overruns the

buffer’s boundary and overwrites adjacent memory. This is a special case of violation

of memory safety.

The goal of this lab is to get intimately familiar with the layout and use of data section,

code section and, particularly, call stacks, as well as MIPS machine language,

assembly and disassembly, debugging, and reverse engineering. As a side ben