cs 111: program design i...the apple/fbi debate n on 12/5/15, syed rizwan farook and tashfeen malik...

39
CS 111: Program Design I Lecture 3: 5 th Am., a bit about computers, Python Basics Cont. Robert H. Sloan & Richard Warner University of Illinois at Chicago August 30, 2016

Upload: others

Post on 30-Jun-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS 111: Program Design I...The Apple/FBI Debate n On 12/5/15, Syed Rizwan Farook and Tashfeen Malik attacked a San Bernardino County Department of Public Health Christmas party. The

CS 111: Program Design I Lecture 3: 5th Am., a bit about computers, Python Basics Cont.

Robert H. Sloan & Richard Warner University of Illinois at Chicago August 30, 2016

Page 2: CS 111: Program Design I...The Apple/FBI Debate n On 12/5/15, Syed Rizwan Farook and Tashfeen Malik attacked a San Bernardino County Department of Public Health Christmas party. The

ENCRYPTION, PRIVACY, & GOVERNMENT POWER (CONT.)

Page 3: CS 111: Program Design I...The Apple/FBI Debate n On 12/5/15, Syed Rizwan Farook and Tashfeen Malik attacked a San Bernardino County Department of Public Health Christmas party. The

The Fifth Amendment

n  5th Amendment: “No person . . shall be compelled in any criminal case to be a witness against himself . . .”

n  You need to show three things: q  (1) “I am being asked to testify.” q  (2) “I am being compelled to do so.” q  (3) “The testimony could incriminate me.”

n  Is being required to decrypt encrypted data being compelled to testify?

Page 4: CS 111: Program Design I...The Apple/FBI Debate n On 12/5/15, Syed Rizwan Farook and Tashfeen Malik attacked a San Bernardino County Department of Public Health Christmas party. The

Testifying?

n  The Doe court held producing the key was testifying.

n  Producing the key says, q  “I know the files exist,” q  “I can access them,’ q  “I can decrypt them.”

n  Other courts hold the opposite.

Page 5: CS 111: Program Design I...The Apple/FBI Debate n On 12/5/15, Syed Rizwan Farook and Tashfeen Malik attacked a San Bernardino County Department of Public Health Christmas party. The

Background

The government thinks you may have the documents.

Documents (including digital files)

The government thinks someone else may have the documents.

Page 6: CS 111: Program Design I...The Apple/FBI Debate n On 12/5/15, Syed Rizwan Farook and Tashfeen Malik attacked a San Bernardino County Department of Public Health Christmas party. The

The Court’s Distinctions

The government thinks you may have certain documents.

The government knows the documents exist and where they are

The government does not know the documents exist nor where they are

The court in US v. Doe decides that the case is a “do not know” situation. On that basis it says that having to produce the key would violate Doe’s 5th Amendment protection.

Page 7: CS 111: Program Design I...The Apple/FBI Debate n On 12/5/15, Syed Rizwan Farook and Tashfeen Malik attacked a San Bernardino County Department of Public Health Christmas party. The

A Witness Against Himself

n  Producing the key would tell the government something it does not know. Doe would be telling the government “I know certain files are on my hard drives, and I know where there are on those drives. I can decrypt them and access them.”

n  That—on the court’s view—is more than the government knows.

n  So if Doe told them that, he would be testifying, he would be a witness against himself. The 5th Amendment bars that.

Page 8: CS 111: Program Design I...The Apple/FBI Debate n On 12/5/15, Syed Rizwan Farook and Tashfeen Malik attacked a San Bernardino County Department of Public Health Christmas party. The

The Government Wants to Search

n  On the court’s view, the government wants to go looking for what it suspects—but does not know—is on the hard drives.

n  To go looking is to search, and government searches are subject to the 4th Amendment, which imposes significant restrictions on searches.

n  The government has not shown it meets the 4th Amendment standards.

Page 9: CS 111: Program Design I...The Apple/FBI Debate n On 12/5/15, Syed Rizwan Farook and Tashfeen Malik attacked a San Bernardino County Department of Public Health Christmas party. The

Two Features

n  The debate revolves around a rule—the Fifth Amendment.

n  The rule by itself provides no answer to the question.

n  So why the obsession with the rule?

Page 10: CS 111: Program Design I...The Apple/FBI Debate n On 12/5/15, Syed Rizwan Farook and Tashfeen Malik attacked a San Bernardino County Department of Public Health Christmas party. The

The Role of Rules

n  We insist on decisions based on rules to ensure that we are governed by principles we all accept instead of someone’s personal perspective.

n  But general rules often do not determine their application to particular cases.

n  To apply them we need to make tradeoffs.

Page 11: CS 111: Program Design I...The Apple/FBI Debate n On 12/5/15, Syed Rizwan Farook and Tashfeen Malik attacked a San Bernardino County Department of Public Health Christmas party. The

The Fifth Amendment Tradeoff

n  Adequate enforcement of laws requires adequate information about wrong doing.

n  So: we need to balance the value of privacy against the needs of law enforcement.

n  So: how much encryption of what kind should be legal when?

n  That is the question underlying the encryption debate.

Page 12: CS 111: Program Design I...The Apple/FBI Debate n On 12/5/15, Syed Rizwan Farook and Tashfeen Malik attacked a San Bernardino County Department of Public Health Christmas party. The

The Apple/FBI Debate

n  On 12/5/15, Syed Rizwan Farook and Tashfeen Malik attacked a San Bernardino County Department of Public Health Christmas party. The police recovered Rizwan’s cell phone. The police wanted to examine the data on the phone, but it was an iPhone 5C and the data was encrypted.

n  The FBI asked Apple to ensure that they could access the information. This raises a lot of issues. We will start with the backdoor issue, and discuss others another time.

n  A backdoor is a secret way into either the computer itself or into a particular piece of software that was left behind by the software developers.

Page 13: CS 111: Program Design I...The Apple/FBI Debate n On 12/5/15, Syed Rizwan Farook and Tashfeen Malik attacked a San Bernardino County Department of Public Health Christmas party. The

A Very Simple Backdoor

n  Suppose you buy an encryption program using a Caesar cypher. The installation program secretly creates an empty text file, key.txt, on your hard drive.

n  The program asks the use to type in your secret key: q  a = input('Input your key:' )

n  The program also has this code hidden in it. q  f = open('key.txt','w') # Open the file key.txt. q  f.write(a) # Write the key to the file key.txt. q  f.close() # Close the file.

Page 14: CS 111: Program Design I...The Apple/FBI Debate n On 12/5/15, Syed Rizwan Farook and Tashfeen Malik attacked a San Bernardino County Department of Public Health Christmas party. The

Questions

n  Would you object to having this code hidden in your software?

n  The government has for years attempted to get software developers to install government backdoors in encryption software. Do you think this is a good idea?

n  It seems fairly clear that the NSA installed secret backdoors in various types of software. Do you think that is a good idea?

Page 15: CS 111: Program Design I...The Apple/FBI Debate n On 12/5/15, Syed Rizwan Farook and Tashfeen Malik attacked a San Bernardino County Department of Public Health Christmas party. The

COMPUTERS, DATA, SIZES

Page 16: CS 111: Program Design I...The Apple/FBI Debate n On 12/5/15, Syed Rizwan Farook and Tashfeen Malik attacked a San Bernardino County Department of Public Health Christmas party. The

16

Did you register your clicker?

Page 17: CS 111: Program Design I...The Apple/FBI Debate n On 12/5/15, Syed Rizwan Farook and Tashfeen Malik attacked a San Bernardino County Department of Public Health Christmas party. The

What computers understand

n  0’s and 1’s. q  Everything is 0’s and 1’s

n  Computers are exceedingly stupid q  The only data they understand is 0’s and 1’s q  They can only do the most simple things with those 0’s

and 1’s n  Move this value here n  Add, multiply, subtract, divide these values n  Compare these values, and if one is less than the other,

go follow this step rather than that one.

Page 18: CS 111: Program Design I...The Apple/FBI Debate n On 12/5/15, Syed Rizwan Farook and Tashfeen Malik attacked a San Bernardino County Department of Public Health Christmas party. The

Key Concept: Encodings

n  But we can interpret these numbers any way we want. q  We can encode

information in those numbers

n  Even the notion that the computer understands numbers is an interpretation q  We encode the voltages

on wires as 0’s and 1’s q  Which we can, in turn,

interpret as a decimal number

Page 19: CS 111: Program Design I...The Apple/FBI Debate n On 12/5/15, Syed Rizwan Farook and Tashfeen Malik attacked a San Bernardino County Department of Public Health Christmas party. The

Useful terminology

n  8 bit byte is fundamental unit of memory n  1 byte is really tiny unit. More often see:

q  N.B. 210, 220, 230, 240, instead of powers of 10 (e.g., 1024 byte kB) also used! See, e.g., https://support.apple.com/en-us/HT201402

1 kilobyte 1 kB 103 bytes 1000 bytes

1 megabyte 1 MB 106 bytes 1,000,000 bytes

1 gigabyte 1 GB 109 bytes 1 billion bytes

1 terabyte 1 TB 1012 bytes 1 trillion bytes

Page 20: CS 111: Program Design I...The Apple/FBI Debate n On 12/5/15, Syed Rizwan Farook and Tashfeen Malik attacked a San Bernardino County Department of Public Health Christmas party. The

Units to data amounts

n  1GB can hold about q  250 photos (Based on 12 Megapixel camera, e.g.,

new iPhone, and JPEG 100% quality) q  7–30 minutes of video (depending on quality,

frames per second, and 720–1080p) q  40,000 pages of simple Word docs

n  So 1 TB hard drive can hold 200 hours of video and 10,000 photos with room left over (assuming video is high-quality 720p @ 30fps)

Page 21: CS 111: Program Design I...The Apple/FBI Debate n On 12/5/15, Syed Rizwan Farook and Tashfeen Malik attacked a San Bernardino County Department of Public Health Christmas party. The

Units to Fall 2016 $ @ amazon

Seagate Expansion 1TB Portable External Hard Drive USB 3.0 (STEA1000400) n  by Seagate n  $49.99| Prime FREE One-Day

Page 22: CS 111: Program Design I...The Apple/FBI Debate n On 12/5/15, Syed Rizwan Farook and Tashfeen Malik attacked a San Bernardino County Department of Public Health Christmas party. The

What is a computer?

n  A device that executes a stored program (sequence of instructions).

n  A program is a particular writing of a recipe in some particular language. (Recipe is likely to be in English or French or Arabic or Hindi; program in a programming language such as C, Java, Visual Basic, or Python)

Page 23: CS 111: Program Design I...The Apple/FBI Debate n On 12/5/15, Syed Rizwan Farook and Tashfeen Malik attacked a San Bernardino County Department of Public Health Christmas party. The

All computers consist of 3 components

n  Memory–stores program and data (information) q  Primary: RAM (Random Access Memory) “memory” q  Secondary: hard drive “storage”

n  Central Processing Unit (CPU) q  Control–fetch next instruction, decode it, execute it q  Arithmetic Logic Unit–perform simple operations on

data (add, compare two for equality, etc.)

n  Input/Output

Page 24: CS 111: Program Design I...The Apple/FBI Debate n On 12/5/15, Syed Rizwan Farook and Tashfeen Malik attacked a San Bernardino County Department of Public Health Christmas party. The

Detour: Specs for a computer

n  Ads for computers typically give: q  Speed of the CPU (in GHz, say 1.0-3.25) q  Amount of RAM in GB q  Size of hard drive in GB or TB q  Which “nice” I/O devices (e.g., retina display)

n  Interestingly, perceived speed today often depends heavily on amount of RAM

Page 25: CS 111: Program Design I...The Apple/FBI Debate n On 12/5/15, Syed Rizwan Farook and Tashfeen Malik attacked a San Bernardino County Department of Public Health Christmas party. The

Moore’s Law

n  Gordon Moore, one of founders of Intel, made claim that (essentially) computer power doubles for the same dollar every 18 months.

n  This has held true for over 40 years. q  (Note: some think the end is finally near.)

n  Go ahead! Make your computer do the same thing to encrypt all 500,000 characters of the book you wrote! It doesn’t care! And it won’t take much time either!

Page 26: CS 111: Program Design I...The Apple/FBI Debate n On 12/5/15, Syed Rizwan Farook and Tashfeen Malik attacked a San Bernardino County Department of Public Health Christmas party. The

PYTHON BASICS

Page 27: CS 111: Program Design I...The Apple/FBI Debate n On 12/5/15, Syed Rizwan Farook and Tashfeen Malik attacked a San Bernardino County Department of Public Health Christmas party. The

To build encryption and decryption need at least n  variables n  functions n  strings n  Let’s start with very light look at variables and

functions that may help with Lab & HW 1

Page 28: CS 111: Program Design I...The Apple/FBI Debate n On 12/5/15, Syed Rizwan Farook and Tashfeen Malik attacked a San Bernardino County Department of Public Health Christmas party. The

Defining your own functions

deftriple(x):return3*xn  Notice the indentation n  Done using “tab” and

absolutely necessary!

triple x 3 * x

Page 29: CS 111: Program Design I...The Apple/FBI Debate n On 12/5/15, Syed Rizwan Farook and Tashfeen Malik attacked a San Bernardino County Department of Public Health Christmas party. The

Functions can have more than one line

deftriple(x):return3*x

deftriple(x):

myAnswer=3*xreturnmyAnswer

triple x

Page 30: CS 111: Program Design I...The Apple/FBI Debate n On 12/5/15, Syed Rizwan Farook and Tashfeen Malik attacked a San Bernardino County Department of Public Health Christmas party. The

Docstrings

deftriple(x):'''Inputisnumberx,returns3*x'''return3*x

n  Teaching your program to talk to you n  Can access via help(triple); then type q to get back to

main Python prompt n  3 single or double quotes just fine (but watch out for

editor trying to give you an even number like 4 marks!) n  Use docstrings!

Page 31: CS 111: Program Design I...The Apple/FBI Debate n On 12/5/15, Syed Rizwan Farook and Tashfeen Malik attacked a San Bernardino County Department of Public Health Christmas party. The

Comments

#Triplingprogram#Authors:RichardandBob#Date:August52,2016deftriple(x):

'''Inputisnumberx,returns3*x'''#Commentsbeginwithahashmark…return3*x

Page 32: CS 111: Program Design I...The Apple/FBI Debate n On 12/5/15, Syed Rizwan Farook and Tashfeen Malik attacked a San Bernardino County Department of Public Health Christmas party. The

Which of these Python 3 programs will print out an "A"?

defprintA():'''IclaimtoprintA'''print"A"

defprintA():'''IclaimtoprintA'''print("A")

defprintA():'''IclaimtoprintA'''print("B")

D. None of the above

A B

C

Page 33: CS 111: Program Design I...The Apple/FBI Debate n On 12/5/15, Syed Rizwan Farook and Tashfeen Malik attacked a San Bernardino County Department of Public Health Christmas party. The

VARIABLES

Page 34: CS 111: Program Design I...The Apple/FBI Debate n On 12/5/15, Syed Rizwan Farook and Tashfeen Malik attacked a San Bernardino County Department of Public Health Christmas party. The

Variables: Simple example

>>>justice1='JohnMarshall'>>>justice1>>>'JohnMarshall'>>>justice2="SandraDayO'Connor">>>justice2>>>"SandraDayO'Connor">>>print(justice2)>>>SandraDayO'Connor

Page 35: CS 111: Program Design I...The Apple/FBI Debate n On 12/5/15, Syed Rizwan Farook and Tashfeen Malik attacked a San Bernardino County Department of Public Health Christmas party. The

Variables

n  We want to tell computer to use specific value we put into its memory q  (To print out a word, to add 2 numbers together,

etc.) n  Much easier for us as humans to give these

things names than to remember addresses

Page 36: CS 111: Program Design I...The Apple/FBI Debate n On 12/5/15, Syed Rizwan Farook and Tashfeen Malik attacked a San Bernardino County Department of Public Health Christmas party. The

A box that holds a value

n  Think of variable as box that holds a value (Pythonistas will say value or object more or less interchangeably), and variable's name as sticky note on the box

"John Marshall"

"Sandra Day O'Connor"

justice1

justice2

Page 37: CS 111: Program Design I...The Apple/FBI Debate n On 12/5/15, Syed Rizwan Farook and Tashfeen Malik attacked a San Bernardino County Department of Public Health Christmas party. The

Types

n  Objects come in few different types. q  E.g., strings vs. numbers

n  In Python computer (i.e., interpreter) generally figures it out for us, but we still need to know little bit about this since, e.g.,

>>>justice1+justice2"SandraDayO'ConnorJohnMarshall"

Page 38: CS 111: Program Design I...The Apple/FBI Debate n On 12/5/15, Syed Rizwan Farook and Tashfeen Malik attacked a San Bernardino County Department of Public Health Christmas party. The

Types

n  Objects come in few different types. q  E.g., strings vs. numbers

n  In Python computer (i.e., interpreter) generally figures it out for us, but we still need to know little bit about this since, e.g.,

>>>justice2+justice1"SandraDayO'ConnorJohnMarshall">>>3+justice1Traceback(mostrecentcalllast):File"<stdin>",line1,in<module>TypeError:unsupportedoperandtype(s)for+:'int'and'str'

Page 39: CS 111: Program Design I...The Apple/FBI Debate n On 12/5/15, Syed Rizwan Farook and Tashfeen Malik attacked a San Bernardino County Department of Public Health Christmas party. The

Some Python Types

Python Type Example(s) String String "argle-bargle" Integer (whole number) Integer 3, 0, 17, 42, -21, 100001 Decimal number Float 3.14159 Boolean (true/false) Boolean True, False