CSCI 1133 - Midterm 1

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

substitution cypher weaknesses

1-1 mapping between letters gives away a lot of information >> most common letter is likely "e" (so letter frequency helps break cypher) >> single letter words >> 2-3 letter words guess one letter and know it everywhere

python

>> a programming language >> can be used to write algorithms >> industrial strength language commonly used in corporations by professional software developers

Variable naming Rules

>> can include any combo of letters >> must start with a letter or _ >> case matters >> Variables should have a descriptive name that describes their purpose >> can't use python reserved words such as def, if, else, not, etc.

functions

>> can only be used after they are defined

boolean

>> created by george boole who laid the foundation for computer science and digital computers, he wanted to mathematically encode operations on "truth" >> True / False variables >> python treats nonzero numbers and nonempty strings as True >> python treats 0 or "" (empty string) the same as False >> can only compare objects who share an ordering (type)

General purpose computer

>> fixed purpose computer whose "fixed" program is reading an arbitrary algorithm and following its instructions >> inventions of this type of machine was the turning point in the history of (theoretical) computer science >ie turing machine, lambda calculus > hardware = general purpose computer > software that does this = interpreter

+

>> for int and float adds the values >> for string compiles it, ie adds to the string

*

>> for int and float multiplies the values >> expects and integer or a float

-

>> for int and float subtracts the values

exploiting bad randomness

>> if someone can guess your seed they can guess every subsequent random number best practices: >>choose truly unguessable seed >> system temp, bits downloaded, harddrive state, mouse position....

variables and lists

>> multiple variables can point to the same list example: a = [42, "cat", 3.1] b = a b[2] = "hat" print(a) changing b changes a (because b and a reference the same list)

variables

>> place to store results >> named items that store some values >> values can be overwritten >> two types temp and name

python language

>> set of commands/instructions understood by the python interpreter

Early computers

>> type of computer that operated only fixed processes meaning they implemented some form of imperative (description of a process) knowledge in circuits

scripts

>> used for writing an actual program >> can run more than one line or block of code at a time >> type all code in one text file (Aka _______) and run all the code at once

vigenere cypher

>> widely thought to be very strong >> compute offsets number using "abc...".find() >> offset number from key (loop thru each character in key, loop if over key's length) >> offset number from plaintext >>new character = (plainoffset + keyoffset)%26, then convert back to text >>> weakness: cypher still repeats (shorter keys repeat very quickly), key length is known you can use frequency analysis >> has rotating key

random module

>>random.random() returns float number from 0-1 >>random.seed(arg) initializes random sequence with arg >>random.seed() uses current time (in miliseconds) as seed >>random.randint(a,b) random integer from [a,b] >>random.uniform(a,b) random float from [a,b] to set it to a select number range use int (its inclusive): random.randint(start,stop)

while loops

A control structure that allows a piece of code to repeated until a certain condition is false >> unknown when loop will end while 'condition': statement statement break = special command that immediately stop the while loop

ASCII

American Standard Code for Information Interchange >> mapping between numbers and letters, use ord() and chr() to switch back and forth >> shows characters and their corresponding numbers >> lower case letter is uppercase number + 32

programming language

a formalized language for writing algorithms

.append()

adds arg to the end of a list a = [1,2] a.append(7) -- [1,2,7] can also use += : a += [7] -- [1,2,7]

logical operators

and, or, not a and b --> true if both a and b are true a or b --> true if either a or b are true not b --> true if b is false a or not b --> true if a is true or be is false

parameters

automatically passed to the functions when you call them >> specify the value of some variables when you call the function ex. def funcName(x, y): what x and y are called >> multi-parameter functions

turtle()

basic graphical library >> module after a robotic toy, pen shows the path >> creates a virtual "turtle" robot which carries a pen >> create a turtle: var = turtle.Turtle() >> can move forward(fd()), backward(), left(lt()), right(rt()), lift pen up(), place it down(), draw a dot(), change the color(), goto() specified point, etc

range()

can take 1, 2, or 3 arguements (all int) range(stop) >> sequence from zero to stop range(start,stop) >> sequence from start to stop range(start, stop, step) >> sequence of num from start to stop in increments of step >> creates a sequence of integers

modules

combine several pre-written functions you may need ex. time (access system clock), timeit(measure how long code takes to run), string, turtle, math, etc

+= , -=

compound operators a = 3 a += 5 equivalent to a = a + 5 a = 3 a -= 5 equivalent to a = a - 5 does math and then assigns the new number to the variable

if statements

conditional operators if condition: statement statement else: happens whenever the above condition is false if condition: statement statement else: statement statement elif: combines else and a new if-statement can be followed by a new elif statement or else if condition: statement statement elif condition: statement statement else: statement statement >> can be modified and joined with and, or and not >> code only moves onto elif statement if the first if isn't true as soon as one is true it runs that one

strings

consecutive series of characters >> to convert to type string use str() >> sequence of characters >> a in b --- return stru if string a is inside string b >> len(arg) -- number of characters in a string >> [n] -- returns nth character in a string IMMUTABLE (can't edit) to make new version you overwrite old version

decoding

decryption converting from cypher text back to plain text

slicing

defined range of characters string[start:end:step] >> think of it as end - start (ie end is not included) [start:end] -- all items from start thru end-1 [:end] -- items from beginning thru end-1 [start:] -- items from start thru rest [start:end:n] -- every nth item start to end-1

del with lists

del alist[index] >> removes element at index from a list

in operator

determines if a STRING contains another string >> tests if string on left is in string on right >> returns a boolean >> inverse is not in

atanasoff-berry computer

early fixed function computer used for linear equations

turnings bombe

early fixed function computer used to determine daily settings of enigma code

encoding

encryption converting from plain text to cypher text

return()

ends the function and returns a value >> terminates a function and returns that value to the calling function >> ends a loop

**

exponential form aka repeated multiplication ie 2^2, 7^6, etc.

format(value, spec)

formatting output >> makes a new string out of a value formatted according to the specification > spec = magic string total-chars.decimal-chars_type Type: f = float, d = integer

list

generic sequence that can hold a collection of data types (any type; int, float, functions, strings, lists...) created using [,,,] MUTABLE (values can be changed) >> access is similar to a string (use indexes) >> ordered, heterogeneous collections of python objects + concatenates two lists len() returns the length of a list

chr()

goes from number (integer representation) back to the corresponding character

syntax

grammar for how to use functions

nested if

if function within an if function >> be sure to keep consistent indentation

program

implementation of some algorithm in a programming language

index(arg)

index function >> returns the index of the first time the string arg appears >> complement of [] ex. "abc".index("b") -> 1 "abc"[1] -> "b" .index() shows location of a given character [] shows character at a given location returns error if arg is not in string

int

integer >> whole numbers ex. -3, -2, -1, 0, 1, 2, 3 >> to convert to type int use int()

//

integer divide divides 2 numbers, rounds down to int ex. 104 // 50 => 2

eval()

interprets a string as code (if string of int ('1') converts it to an int) often used with input() function >> lets python program run python code within itself

key

knowledge needed to decode a message

for loop

lets you run code repeatedly, used for repetition, has a known end (count) >> iterates over each statement in a sequence for i in range(n): statement... statement... runs the indented statements n times for i in sequence: iterates i over each element in a sequence

substitution cypher

letters plain text correspond to other letters that are used in the cypher text >> key -- what each letter corresponds to >> spaces in text make guessing easier (gives away a lot of info) so remove those >> used by washington and ceasar

list()

makes new lists from other types ex. list('hello') -- ['h', 'e', 'l', 'l', 'o']

%

modular division divides two numbers and returns the remainder ex. 104 // 50 => 4

plain-text

original message to communicate

multiply-with-carry (MWC)

pick: max, a, c change c each step to be "left over" from previous modulus on top of changing old to the remainder >> more robust, longer periods (still very fast)

linear congruential generators

pick: max, a, c > generate random numbers from [0, max) new = (a*old+c)%max >> issues: choice of parameters is very important, can have small 'periods' (repeat numbers quickly), hyper planes (doesn't appear random) >> slightly faster (1 less operation), many languages use this as default

print()

prints an arguement to the screen

python interpreter

program which follows instructions written in python language and outputs results

import string

python module >> some string helper functions

float

rational numbers >> fractional ex. 2.71828, 3.14159, -3.0 >> to convert to type float use float()

ord()

returns a character's integer representation (the # that corresponds to the character)

.split()

returns a list

.lower()

returns a new string of all lower case

string.replace(s1,s2)

returns a new string with all instances of s1's replaced with s2

input()

returns a user's input >> returns a string

.upper()

returns new string of all uppercase

len()

returns the length of a string (number of characters)

type()

returns the type of a variable

round(float, int)

rounds a floating point number to a specified number of digits >>int represents the specified number of digits

( )

sets operator evaluation precedence

string.find(arg)

similar to index, searches a string returns index where arg is and if arg is NOT in string returns -1

operators

special functions built into the language with fixed, important meaning + , - , * , / , // , % , ** , ()

pseudorandom

start with initial number, use previous number to generate next number >> sequence should be "unpredictable" apparently random list of numbers initialized with a seed

name variable

storing a list of characters (string)

temp variable

storing a number (int)

indexing operator

string[index] >> returns the character at the offset from the start of the string >> index starts at 0 >> when index = -1 returns last character

cypher-text

text containing a hidden version of the plain text (encrypted)

interpreter

type of software where program follows instructions directly

compiler

type of software where programming language is translated into simple hardware instructions

kama sutra cypher

type of substitution cypher letters are grouped into pairs, opposite letter of pair is used

def

used for creating functions (keyword to define new functions) ___ functionName(parameter1, parameter 2): statement1 statement2 >> each statement must have the same indentation >> know where a function ends based on the indentation

=

used to assign variables

#

used to make notes (comments) to yourself and others in code >> used to clarify what code does and to remind yourself what's going on when you look at it at a later date

short circuiting logical expression

using the wrong type, etc. x=3 y='hi' if x > 0 and y < 0: print("running")

in with lists

value in alist >> returns true if value is in alist

algorithm

well-defined series of instructions to solve a problem


Set pelajaran terkait

Office Management Midterm (quizzes)

View Set