






Studia grazie alle numerose risorse presenti su Docsity
Guadagna punti aiutando altri studenti oppure acquistali con un piano Premium
Questa pagina non è visibile nell’anteprima
Non perderti parti importanti!







1
Computational thinking The processes involved in formulating problems and their solutions so that the solutions are represented in a form that can be effectively carried out by an automated information-processing system. What is not?
2
4 created the packages and you just have to use the combining properly what they offer. Languages used to this end are Python, R, Perl, Javascript, etc. The learning curve is very soft. Program unit (Python function) Program unit is an abstract concept using algorithm description. In many programming languages, program unit has the same meaning as function. A function is a block of organised, reusable code that is used to perform a single, related action. It allows us to define new reusable abstract tool. Cut and paste a code is not a good idea because if we realise that the code has some problem, we will have to fix in all the positions. On the contrary, define and call the function for solving the problem, once the function is fixed, all the code using the function will apply the corrected version of it. A function is a block of code which only runs when it’s called. Open a file (read/write) The first step consists of declaring to Python interpreter what you want to do with a file (write/append it or read it). From a Python perspective, this corresponds to open the file in a way or the other. Each time you open a file in one of these three ways (write, append or read), Python returns a handle, which is a unique reference to a specific file open in a particular way. Once you have a handle, you can use it to perform the intended operation (write, append or read). Finally, since you have opened a file, you must close it (forgetting the last step might cause problems with the file). Packages Functions are usually collected in a library, named packages. Packages can be imported in your Python environment to add abstract tools (already coded functions) so we can just use them without the need of defining them. For example, mathematical functions. List Sometimes I have to consider collections of elements. Lists are ordered collections of elements. Ordered mean that we have a position for each element. The declaration syntax uses [ ] for defining the begin and the end of the list. The first element is called head and the last is called tail. Lists can contain duplicates. Also, they are heterogeneous, so they are not limited to contain elements of the same data type. Lists can also be empty so not containing elements. Lists are mutable. If we imagine a lists as a collection of boxes, each one associated with a variable and box size is related to the amount of information stored in the box itself, we could need an operator to access to individual elements inside the list. This is called slice operators. They allow the access to the individual box inside the list. Slice operator syntax is to use listName[position] so the name of the variable in the list and the square brackets to identify its position. The position is an integer ranging from 0 up to the n - 1. Methods Methods are object-oriented concepts. Lists are stored as objects in Python. Methods are functions applied to given data structures. Syntax: name.methodName(optional params), here I am saying I want to apply some special function just to this object. This concept comes from object-oriented paradigm. The presence of optional parameters changes the actions executed by the method itself (this behaviour is named polymorphism). List methods A = [‘a’, ’b’, ‘c’, ’d’]
5
1. Append: will add an additional element to the tail of the list. 2. Pop (): will remove the last element of the list. 3. Pop (n): remove the element in position n. 4. Insert (element, n): add an element in position n. 5. Extend (otherList): will provide a list adding it to the first one. 6. Clear (): remove all the elements from the list. Tuples They are a convenient way to regroup the primitive values we already know (booleans, strings). A tuple is an abstract data structure composed of heterogenous elements. Properties of all tuples:
7 depend on the algorithm we are considering. In other words, the number of operations depends on some properties of dataset. Most common properties of data set are:
8 the core of other packages. With NumPy you can calculate the solution of system of two equations with two incognitos, but also a polynomial (poly1d). The abstract data structure offered by Numpy is the array. The core of NumPy is well-optimised C code. That is why they provide very good performances. Usually interpreted languages like python suffer of poor performance because every time the interpreter has to process everything before executing and the idea is just that we have optimised libraries where there are some functions that call other functions written in different programming languages. So, we can call easily those function from python, and those functions provide very good performances. Array performance An array is a collection of homogeneous data items stored in contiguous memory locations. An array can also be defined as an ordered collection of homogeneous items indexed by contiguous integers. Arrays grant better performance by indexing because they exploit homogeneous data (each element requires the same amount of memory). Many programming languages provide array as native data type, but python doesn’t. They are implemented in a package called NumPy and it’s used at the basis of many other packages. Array vs list Arrays need to be declared. Lists don't, since they are built into Python. Creating an array, on the other hand, requires a specific function from NumPy package (numpy.array()). Because of this, lists are used more often than arrays. Arrays can store data very compactly and are more efficient for storing large amounts of data. Arrays are great for numerical operations. Lists cannot directly handle math operations. For example, you can divide each element of an array by the same number with just one line of code. If you try the same with a list, you'll get an error. You cannot change the size of an array. If you want to, you need to copy your array inside another one of a different size. You can’t insert elements inside of an array because they are contagious. So, they are less flexible than lists and tuples but provide a better performance. They are very efficient as the number of elements is increased. Array shapes There are different ways to organise an array. The syntax is similar to the syntax used for lists [ ], but another popular way to organise data are matrix. Matrix is a two-dimensional structure in which data are organised like in a table, and when we need to pick up some elements, we need to specify the index of the row and the index of the column. Using Numpy, we can specify as many dimensions as we need. The number of dimensions and items in an array is defined by its shape, which is a tuple of N non-negative integers that specify the sizes of each dimension. Very popular NumPy functions they provide the most common needs of a programmer:
10 strong encryption system. Brute force decryption (try each key) taking 1 sec on DES, takes 149 trillion years for AES 256 bit. Session key Session key is used to exploit the advantages of both symmetric and public key cryptography techniques. We restrict the use of public key cryptography to exchange only the value of the symmetric key that we use for encrypting large messages. We take advantages of both techniques: public key cryptography doesn’t require sharing secrets so we can securely communicate and transmit the value of a key, and symmetric key which is a session key because for each message is randomly generated. RSA: Creating public/private key pair The idea is that we need to choose large prime numbers p and q. Then we compute the product and then compute other quantities related to p and q. The important property is that we have a couple of numbers (n and e, public encryption key) and another couple (n and d, private key) that are mathematically related by the previous relationships. Prime numbers factorisation is an incredible time-consuming activity that has an exponential computational complexity. We have two important properties:
11 provides a digital certificate stating that this public key is associated with some identity. Every time we want to verify a certificate, you don’t need to contact the authority. The authority basically signs the private key of them. There are different checking that the CA can do, and usually the CA will guarantee that the association is correct and if it’s not they will pay you money: this is the security level of the digital certificate. The public key certification prevents situations like ap 5.0. How can we be sure that a third person is not able to forge the public key certification? The idea is to use the session key as much as possible because the direct application of public key cryptography requires a lot of computation, and we want to save computation while preserving strong cryptographic guarantee. Symmetric key presents the same guarantee as public key. So, in this scenario we have three keys: