… Caesar Cipher: encipher encipher( 'gv vw dtwvg', 0 ) encipher( 'gv vw dtwvg', 1 ) encipher( 'gv vw dtwvg', 2 ) encipher( 'gv vw dtwvg', 3 ) encipher(

Slides:



Advertisements
Similar presentations
3-5 Slopes of Lines Warm Up Lesson Presentation Lesson Quiz
Advertisements

23-Apr-15 Abstract Data Types. 2 Data types I We type data--classify it into various categories-- such as int, boolean, String, Applet A data type represents.
1 Lecture-2 CSIT-120 Spring 2001 Revision of Lecture-1 Introducing Computer Architecture The FOUR Main Elements Fetch-Execute Cycle A Look Under the Hood.
HW 3: Problems 2&3. HW 3 Prob 2:Encipher encipher( S, n ) takes as input a string S and a non-negative integer n between 0 and 25. This function returns.
Introduction to Computers and Programming Lecture 7:
1 Lecture-2 CS-120 Fall 2000 Revision of Lecture-1 Introducing Computer Architecture The FOUR Main Elements Fetch-Execute Cycle A Look Under the Hood.
ab c d ef g a chat e lele deux neuf f chef b c d g.
Intersecting & Parallel Lines, Line Segments, and Rays! By: Ms. Castela.
Introduction to Computing Using Python Chapter 6  Encoding of String Characters  Randomness and Random Sampling.
IS 313 Today What's ahead? I see I'm not the only one loopy around here… 10/7 Lec 5 ~ today, now! HMC standings!? 10/8 homework 3 due 10/14 Lec 6 ~ "dictionaries"
LING 408/508: Programming for Linguists Lecture 2 August 28 th.
Introduction to Python Lecture 1. CS 484 – Artificial Intelligence2 Big Picture Language Features Python is interpreted Not compiled Object-oriented language.
Hands on Projects Dr. Bernard Chen Ph.D. University of Central Arkansas July 9 th 2012
Handling Lists F. Duveau 16/12/11 Chapter 9.2. Objectives of the session: Tools: Everything will be done with the Python interpreter in the Terminal Learning.
Use Proportions to Solve Geometric Problems 6.2. Proportion Properties The Reciprocal Property: – If two ratios are equal, then their reciprocal is also.
EECS 110: Lec 8: Lists of Lists Aleksandar Kuzmanovic Northwestern University
Fill in the blanks: (1) _________ has only two possible values 0 and 1. (2) There are __________bits in a byte. (3) 1 kilobyte of memory space can store.
Objective: Find and simplify the ratio of two numbers.
Strings CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
8.7 Warm Up Warm Up Lesson Quiz Lesson Quiz Lesson Presentation Lesson Presentation Coordinate Proof with Quadrilaterals.
Now String theory To Do: Lists This stuff hurts my brane. when you learn string theory from google images… Goal: Thinking like a machine You should now.
CS50 Week 2. RESOURCES Office hours ( Lecture videos, slides, source code, and notes (
Unit 1 Going to School.
Priority Queues, Trees, and Huffman Encoding CS 244 This presentation requires Audio Enabled Brent M. Dingle, Ph.D. Game Design and Development Program.
Computing Science 1P Large Group Tutorial: Lab Exam & Class Test Simon Gay Department of Computing Science University of Glasgow 2006/07.
The character data type char. Character type char is used to represent alpha-numerical information (characters) inside the computer uses 2 bytes of memory.
EECS 110: Lec 8: Lists of Lists Aleksandar Kuzmanovic Northwestern University
Radix search trie (RST) R-way trie (RT) De la Briandias trie (DLB)
8.3 Similar Polygons Geometry.
EECS 110: Lec 3: Data Aleksandar Kuzmanovic Northwestern University
Fall 2015, Kevin Quinn CSE373: Data Structures & Algorithms Lecture 25: Problem Solving CSE373: Data Structures and algorithms1.
EECS 110: Lec 7: Program Planning Aleksandar Kuzmanovic Northwestern University
CHARM Lecture 1 Outline of the Problem. The Maltese Alphabet A aB bĊ ċD dE eF fĠ ġG gGħ għH h abeċedeeefġegeajnakka Ħ ħI iIe ieJ jK kL lM mN nO oP p ħeiiejekeelleemmeenneope.
EECS 110: Lec 8: Lists of Lists Aleksandar Kuzmanovic Northwestern University
7.2 Similar Polygons. Objectives  Identify similar polygons  Use similar polygons to solve real-life problems, such as making an enlargement similar.
Strings CSE 1310 – Introduction to Computers and Programming Alexandra Stefan University of Texas at Arlington 1.
Strings CSE 1310 – Introduction to Computers and Programming Alexandra Stefan University of Texas at Arlington 1.
Search Radix search trie (RST) R-way trie (RT) De la Briandias trie (DLB)
EECS 110: Lec 8: Lists of Lists
IGCSE 4 Cambridge Data types and arrays Computer Science Section 2
8.3 Similar Polygons Geometry.
Numerical Representation
Data Transfer ASCII FILES.
Caesar Cipher: encipher
Whatcha doin'? Aims: To understand the Caesar Cipher.
Homework 3 Problem 0 If you liked the article on the DNA computer, check the following: Biocomputer and Memory Built Inside Living Bacteria IEEE Spectrum,
Data Encoding Characters.
LING 388: Computers and Language
Length of a Segment Let A and B be points on a number line, with coordinates a and b. Then the measure of segment AB is.
Polygons whose corresponding angles are congruent and
8.4 Similar Polygons Sec Math 2.
Using files Taken from notes by Dr. Neil Moore
Encryption and Decryption
8.3 Similar Polygons.
CSC 221: Introduction to Programming Fall 2018
Rate of Change and Slope
8.3 Similar Polygons Geometry Mr. Qayumi 2010.
Numerical Representation
Your questions from last session
8.4 Similar Polygons Sec Math 2.
3-5 Slopes of Lines Warm Up Lesson Presentation Lesson Quiz
functions: argument, return value
Drill Find x, if the semicircle arc of a circle is 3x + 30 degrees.
Learning Intention I will learn how computers store text.
Symmetry and Congruence
8.3 Similar Polygons.
COMPUTER PROGRAMMING SKILLS
Data Types Every variable has a given data type. The most common data types are: String - Text made up of numbers, letters and characters. Integer - Whole.
Data Types and Maths Programming Guides.
Random numbers What does it mean for a number to be random?
Presentation transcript:

… Caesar Cipher: encipher encipher( 'gv vw dtwvg', 0 ) encipher( 'gv vw dtwvg', 1 ) encipher( 'gv vw dtwvg', 2 ) encipher( 'gv vw dtwvg', 3 ) encipher( 'gv vw dtwvg', 4 ) encipher( 'gv vw dtwvg', 5 ) encipher( 'gv vw dtwvg', 25 ) returns 'gv vw dtwvg' 'hw wx euxwh' 'ix xy fvyxi' 'jy yz gwzyj' 'kz za hxazk' 'la ab iybal' 'fu uv csvuf' encipher( S, n ) should return the string s with each alphabetic character shifted/wrapped by n places in the alphabet

ASCII ASCII is a table that tells the computer how to represent characters as bits! 8 bits = 1 byte The SAME bits represent integers, if the variable has type int instead of str American Standard Code for Information Interchange type: str type: int bits name: value: '*' 42 Identical bits are stored in each variable! The types determine how to interpret the bits; the names don't matter at all…

ASCII ASCII is a table that tells the computer how to represent characters as #s American Standard Code for Information Interchange chr ord convert to number convert to char.

chr and ord chr( n ) ord( c ) Input: an integer in range(255) Input: a string of one character, c abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ ASCII VALUES Output: a one-char. string of that ASCII value Output: an integer, the ASCII value of c CONVERTERS [ [i,chr(i)] for i in range(128) ] [ ord(i) for i in '**** CS! ****' ] try these!

chr and ord chr(66) is 'B' ord('a') is 97 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 90 ASCII VALUES What is chr( ord('i')+ 13 ) ? What is chr( ord('P')+ 13 ) ? How can we wrap this around?

Rot 13 def adv13( c ): """ rotates c by 13 chars, "wrapping" as needed NON-LETTERS DO NOT CHANGE! """ if 'a' <= c <= 'z': neword = ord(c) + 13 if neword <= ord('z'): return chr(neword) # no wrapping else: return elif else: How would you rotate an entire string?

Caesar Cipher: decipher >>> decipher('Bzdrzq bhogdq? H oqdedq Bzdrzq rzkzc.') 'Caesar cipher? I prefer Caesar salad.' >>> decipher('Hu lkbjhapvu pz doha ylthpuz hmaly dl mvynla '\ 'lclyfaopun dl ohcl slhyulk.') 'An education is what remains after we forget everything we have learned.' But how ? >>> decipher('Uifz xpsl ju pvu xjui b qfodjm!') >>> decipher('gv vw dtwvg')

Caesar Cipher: decipher >>> decipher('gv vw dtwvg') CaesarBrutus Strategy using max : (1) consider all possible answers (2) give them each a score (3) use builtin function max to select a best answer gv vw dtwvg hw wx euxwh ix xy fvyxi jy yz gwzyj kz za hxazk la ab iybal mb bc jzcbm nc cd kadcn od de lbedo pe ef mcfep qf fg ndgfq rg gh oehgr sh hi pfihs ti ij qgjit uj jk rhkju vk kl silkv wl lm tjmlw xm mn uknmx yn no vlony zo op wmpoz ap pq xnqpa bq qr yorqb cr rs zpsrc ds st aqtsd et tu brute fu uv csvuf all 26 possibilities Score for "Englishness"? up to you…

Caesar Cipher: decipher >>> decipher('gv vw dtwvg') 'od de lbedo' CaesarBrutus Strategy using max : (1) consider all possible answers (2) give them each a score (3) use built-in function max to select a best answer [0, 'cr rs zpsrc'] [0, 'gv vw dtwvg'] [0, 'jy yz gwzyj'] [0, 'mb bc jzcbm'] [0, 'qf fg ndgfq'] [0, 'wl lm tjmlw'] [1, 'bq qr yorqb'] [1, 'ds st aqtsd'] [1, 'nc cd kadcn'] [1, 'vk kl silkv'] [1, 'xm mn uknmx'] [2, 'ap pq xnqpa'] [2, 'hw wx euxwh'] [2, 'ix xy fvyxi'] [2, 'kz za hxazk'] [2, 'rg gh oehgr'] [2, 'sh hi pfihs'] [2, 'uj jk rhkju'] [2, 'yn no vlony'] [3, 'fu uv csvuf'] [3, 'pe ef mcfep'] [3, 'ti ij qgjit'] [3, 'zo op wmpoz'] [4, 'et tu brute'] [4, 'la ab iybal'] [4, 'od de lbedo'] all 26 possibilities won't always be correct! number-of-vowels score

Caesar Cipher: decipher >>> decipher('gv vw dtwvg') 'et tu brute' CaesarBrutus Strategy using max : (1) consider all possible answers (2) give them each a score (3) use built-in function max to select a best answer [0.4680, 'jy yz gwzyj'] [0.4960, 'mb bc jzcbm'] [0.5420, 'uj jk rhkju'] [0.5567, 'ix xy fvyxi'] [0.5597, 'qf fg ndgfq'] [0.5718, 'fu uv csvuf'] [0.5753, 'bq qr yorqb'] [0.5833, 'kz za hxazk'] [0.5859, 'xm mn uknmx'] [0.5880, 'gv vw dtwvg'] [0.5902, 'vk kl silkv'] [0.6110, 'ap pq xnqpa'] [0.6304, 'zo op wmpoz'] [0.6318, 'wl lm tjmlw'] [0.6717, 'cr rs zpsrc'] [0.6735, 'hw wx euxwh'] [0.6963, 'nc cd kadcn'] [0.7153, 'ti ij qgjit'] [0.7398, 'la ab iybal'] [0.7442, 'yn no vlony'] [0.7867, 'pe ef mcfep'] [0.7880, 'sh hi pfihs'] [0.7918, 'rg gh oehgr'] [0.8213, 'ds st aqtsd'] [0.8609, 'od de lbedo'] [0.9082, 'et tu brute'] all 26 possibilities letter- probability score not always correct, but better!

Binary Storage / Representation 8 bits = 1 byte = 1 box The SAME bits represent integers, if the variable has type int instead of str type: str type: int bits name: value: '*' 42 Identical bits are stored in each variable! The types determine how to interpret the bits; the names don't matter at all… 1 bit 1 byte = 8 bits

Sorting returns a list which has the same elements as L, but in sorted order! def sort(L)

Sorting returns a list which has the same elements as L, but in sorted order! def sort(L) What is sorting doing? What is one piece?

Random sorting… def randSort( L ): """ crazy sorting """ newL = random.sample( L, len(L) ) if isSorted(newL): return newL else: return randSort(L) # try again… this function is totally random, dude! A random permutation of L ! Mmmm… sorting!

Random sorting… returns True if s is in order, False otherwise isSorted('BART') returns False isSorted('BERT') returns True isSorted('BEGIN') returns True def isSorted(s) isSorted([3,1,4]) returns False isSorted([1,3,4]) returns True Six-letter word? isSorted('LOOPY') returns ??

Random sorting… returns True if s is in order, False otherwise def isSorted(s): Six-letter word? """ see the description in this box """ if len(s) < 2: return elif s[0] > s[1]: return else: return

Random sorting… returns True if s is in order, False otherwise def isSorted(s): Six-letter word? """ see the description in this box """ if len(s) < 2: return True elif s[0] > s[1]: return False else: return isSorted( s[1:] )

Almost the end… returns a list which has the same elements as L, but in sorted order! def sort(L) Let e be the max element in L Where should e go? and what helper function might we want… ?

removeOne def removeOne( e, L ): """ this function removes one e from L if L is a list, e is an element if L is a string, e is a one-char. string """ if len(L) == 0: return L # L is empty elif e == L[0]: return L[1:] # the element e is now gone else: return L[0:1] + removeOne( e, L[1:] ) # keep going