SlideShare a Scribd company logo
1 of 39
Class 29:
Inheritance



cs1120 Fall 2011
David Evans
31 October 2011
But first…
”Trick-or-Treat”
   Protocols!
“Trick
or Treat”
Protocols
What’s a Protocol?


A protocol is an
algorithm that
involves two or
more parties.



                              4
What’s an Algorithm?

An algorithm is a   A procedure is a well
procedure that      defined sequence of
always              steps that can be
finishes, and       followed
produces the        mechanically.
correct output.

                                            5
“Trick or Treat” Protocols
Two parties:
  Tricker: initiates the protocol by demanding
            tribute
  Victim: either pays tribute (usually in the
            form of sugary snack) or risks trick

     Tricker must convince Victim that she poses a
     credible threat: prove she is a qualified tricker
Trick-or-Treat

            “Trick or Treat?”
                                             Victim


             “Prove it!”
Trickers?
              “The magic word is: shazam!”


                                     Any problems
                                      with this?
Authentication

How can the tricker
prove their
trickability, without
allowing the victim to
now impersonate a
tricker?

                          8
One-Way Functions
f is a one-way function if it is a function y = f(x)
     that satisfies these two properties:

Invertible: there exists an f -1 such that,
  for all x in range: f -1 (f (x)) = x
One-way: it is much, much, much easier to
    compute f (x) than to compute f -1 (y)
Example One-Way-ish Function:
            Factoring
 Forward: given p and q are 200-digit prime
    numbers, output n = pq
 Backward: given n, output (p, q)
Forward: (p, q) easy to calculate f (p, q).
    Easy means we know is an algorithm with running
    time in O(N2) where N is number of digits
Backward: given n = f (p, q): hard to find p and q.
    Hard means (we hope) the fastest possible
    procedure has running time in (2N) .
Is Factoring Hard?




                     11
Factors from Exam 1 (Solutions)

  (define (factors n)
    (list-reverse (factors-helper (- n 1) n)))
  (define (factors-helper t n)
    (if (< t 2) null
        (if (is-divisible? n t)
            (cons t (factors-helper (- t 1) n))
            (factors-helper (- t 1) n))))



                                                  12
Factors
(define (factors n)
  (list-reverse (factors-helper (- n 1) n)))
(define (factors-helper t n)
  (if (< t 2) null
      (if (is-divisible? n t)
          (cons t (factors-helper (- t 1) n))
          (factors-helper (- t 1) n))))




                                                13
(define (factors n)
  (list-reverse                                def factors(n):
     (factors-helper (- n 1) n)))               res = []
(define (factors-helper t n)
                                                for d in range(2, n):
  (if (< t 2) null
      (if (is-divisible? n t)                     if n % d == 0:
          (cons t                                    res.append(d)
                 (factors-helper (- t 1) n))    return res
          (factors-helper (- t 1) n))))




                                                                        14
(define (factors n)
  (list-reverse                                def factors(n):
     (factors-helper (- n 1) n)))               res = []
(define (factors-helper t n)
                                                for d in range(2, n):
  (if (< t 2) null
      (if (is-divisible? n t)                     if n % d == 0:
          (cons t                                    res.append(d)
                 (factors-helper (- t 1) n))    return res
          (factors-helper (- t 1) n))))


    Assuming (aggressively!) that is-divisible? (or %) is constant
    time, running time is in (V) where V is the value of n.

            But, this is in    (2N) where N is the size of n.

                                                                        15
Does this prove that
 factoring is hard?




                       16
Best Known Factoring Algorithm
General Number Field Sieve: running time is in
                        1                         2
            (log N ) £ (log log N )
                        3                         3
       O(e                                            )
where N is the number of bits in input.

              Note: unless you have a big quantum computer!
              Then the running time is in
                                              3
                       O((logN ) )

                                                              17
Checks the
           factors
         multiple to
         produce n



Problems with this?
Tricker Needs to Solve
Trap-Door One-Way Function:
  One-way function that can be quickly
  inverted, but only if you have a secret!




                                             19
RSA Encryption System
      E(M) = Me mod n
      D(C) = Cd mod n
n = pq              p, q are prime
d is relatively prime to (p – 1)(q – 1)
ed 1 (mod (p – 1)(q – 1))
              d is the trap-door secret:
              if you have it, you can invert Me mod n

                                                        20
Checks that
                D(x)e mod n = x




How does victim know e and n?
Help me verify
“tricker@virginia.edu”

             Trickers
             Bureau



        Checks that
  D(x)eT@V mod n
                 T@V = x
Except on Halloween, this is called a
  public-key challenge-response
     authentication protocol.




                                        23
On the web, it is called “TLS” or “SSL” and the
“Tricker’s Bureau” is called a “Certificate Authority”.

                                                          24
Do One-Way Functions Exist?
                          This is the most important open question
                          in Computer Science (and Mathematics)!
Same question as:
• Are they problems where it is hard to find a
  solution, but easy to check it?
• Can a computer that can always guess right
  between two choices better than one that can’t?
• Is the class of problems that a Turing Machine can
  solve in polynomial time (O(nk)) smaller than the
  class of problems an always-guessing-right TM
  can solve in polynomial time? (P = NP)
                                                                     25
Inheritance
Making a Dog
   class Dog:
     def bark(self):
        print "wuff wuff wuff wuff"

spot = Dog()
There are many kinds of Dogs…
class Dog:
  def __init__(self, n):
     self.name = n
  def bark(self):
     print “wuff wuff wuff wuff”

class TalkingDog (Dog):
  def speak(self, stuff):
     print stuff
Subclasses
ClassDefinition ::= class SubClassName ( SuperClassName ) :
                          FunctionDefinitions


     class TalkingDog (Dog):
       def speak(self, stuff):
          print stuff
                    TalkingDog is a subclass of Dog.
                    Dog is the superclass of TalkingDog.
Every Dog has its Day
                                      class Dog:
                                        def __init__(self, n):
                                           self.name = n
>>> bo = Dog('Bo')                      def bark(self):
>>> scooby = TalkingDog('Scooby Doo')      print “wuff wuff wuff wuff”
>>> scooby.speak('Ta-da!')
Ta-da!
                                                   class TalkingDog (Dog):
>>> bo.speak('Ta-da!')
Traceback (most recent call last):                   def speak(self, stuff):
 File "<pyshell#11>", line 1, in <module>               print stuff
  bo.speak('Ta-da!')
AttributeError: Dog instance has no attribute 'speak‘
>>> scooby.bark()
wuff wuff wuff wuff
Speaking about Inheritance

             Inheritance is using the definition of
   Dog         one class to define another class.

             TalkingDog inherits from Dog.
TalkingDog
             TalkingDog is a subclass of Dog.
             The superclass of TalkingDog is Dog.
             These all mean the same thing.
PS6

     Make an adventure game
    programming with objects:
  Many objects in our game have
similar properties and behaviors, so
    we use inheritance to reuse
          implementations.
PS6 Classes            SimObject

           PhysicalObject             Place

         MobileObject

OwnableObject         Person

                Student      PoliceOfficer
class SimObject:
  def __init__(self, name):
     self.name = name
  def note(self, msg):
                                                      SimObject
     print "%s: %s" % (self, msg)


                             PhysicalObject                                Place
class PhysicalObject (SimObject):
                        MobileObject
  def __init__(self, name):
     SimObject.__init__(self, name)
     self.location = None
  def install(self, loc):
OwnableObject
     self.note ("Installing at " + str(loc))
     self.location = loc
                                                 Person
     loc.add_thing(self)          class MobileObject (PhysicalObject):
                                     def change_location(self, loc):
                                        self.location.remove_thing(self)
                                 Studentloc.add_thing(self)
                                        self.location = loc
                                                                PoliceOfficer
SimObject
class MobileObject (PhysicalObject):
  def change_location(self, loc):
                          PhysicalObject
     self.location.remove_thing(self)
     loc.add_thing(self)
                                                        Place
     self.location = loc

                     MobileObject

OwnableObject                              Person
  class OwnableObject (MobileObject):
    def __init__(self, name):
       MobileObject.__init__(self, name)
       self.owner = None      Student           PoliceOfficer
    def is_ownable(self): return True
PS6 Objects                              SimObject

                    PhysicalObject                         Place

               MobileObject                       Place(‘Noodles Hall’)


                                                  An object that is an
                                                  instance of the Place class.
OwnableObject                            Person

                        Student               PoliceOfficer
     aph = Student(‘Alyssa P. Hacker’)
Does the “real world” have
inheritance hierarchies like this, or
       only the fake world of
         Charlottansville?



                                        37
RotationPathInterpolator
                                    PathInterpolator
                                Interpolator
        Node
                          Selector

                Leaf



  SceneGraphObject




                                                                           Not at all uncommon to have
                                                                           class hierarchies like this!

Java 3D Class Hierarchy Diagram
http://java.sun.com/products/java-media/3D/collateral/j3dclass.html
                                                                      CS 201J Fall 2003       7 October 2003
Try not to make any
                                       kids cry by asking them
                  Summary              to factor large
                                       numbers!
An object packages state and procedures.
  A class provides procedures for making and
  manipulating a type of object.
  The procedures for manipulating objects are
  called methods. We invoke a method on an
  object.
Inheritance allows one class to refine and reuse
  the behavior of another.
Wednesday: Excursion on Exponential Growth
  Please ready Tyson essay before class Wednesday!

More Related Content

What's hot

Decorated Attribute Grammars (CC 2009)
Decorated Attribute Grammars (CC 2009)Decorated Attribute Grammars (CC 2009)
Decorated Attribute Grammars (CC 2009)lennartkats
 
Pharo, an innovative and open-source Smalltalk
Pharo, an innovative and open-source SmalltalkPharo, an innovative and open-source Smalltalk
Pharo, an innovative and open-source SmalltalkSerge Stinckwich
 
Cryptanalysis Project Report
Cryptanalysis Project ReportCryptanalysis Project Report
Cryptanalysis Project Reportshahparin
 
Js in js
Js in jsJs in js
Js in jsAlipay
 
JSUG - Effective Java Puzzlers by Christoph Pickl
JSUG - Effective Java Puzzlers by Christoph PicklJSUG - Effective Java Puzzlers by Christoph Pickl
JSUG - Effective Java Puzzlers by Christoph PicklChristoph Pickl
 
Programmation fonctionnelle Scala
Programmation fonctionnelle ScalaProgrammation fonctionnelle Scala
Programmation fonctionnelle ScalaSlim Ouertani
 
The finite element method theory implementation and applications
The finite element method theory  implementation  and applicationsThe finite element method theory  implementation  and applications
The finite element method theory implementation and applicationsSpringer
 
Lesson19 Maximum And Minimum Values 034 Slides
Lesson19   Maximum And Minimum Values 034 SlidesLesson19   Maximum And Minimum Values 034 Slides
Lesson19 Maximum And Minimum Values 034 SlidesMatthew Leingang
 
Joe Bew - Apprendi un nuovo linguaggio sfruttando il TDD e il Clean Code - Co...
Joe Bew - Apprendi un nuovo linguaggio sfruttando il TDD e il Clean Code - Co...Joe Bew - Apprendi un nuovo linguaggio sfruttando il TDD e il Clean Code - Co...
Joe Bew - Apprendi un nuovo linguaggio sfruttando il TDD e il Clean Code - Co...Codemotion
 
Structure and interpretation of computer programs modularity, objects, and ...
Structure and interpretation of computer programs   modularity, objects, and ...Structure and interpretation of computer programs   modularity, objects, and ...
Structure and interpretation of computer programs modularity, objects, and ...bdemchak
 
Unit3 java
Unit3 javaUnit3 java
Unit3 javamrecedu
 
MATHEON Center Days: Index determination and structural analysis using Algori...
MATHEON Center Days: Index determination and structural analysis using Algori...MATHEON Center Days: Index determination and structural analysis using Algori...
MATHEON Center Days: Index determination and structural analysis using Algori...Dagmar Monett
 
Scale Up with Lock-Free Algorithms @ JavaOne
Scale Up with Lock-Free Algorithms @ JavaOneScale Up with Lock-Free Algorithms @ JavaOne
Scale Up with Lock-Free Algorithms @ JavaOneRoman Elizarov
 

What's hot (20)

Decorated Attribute Grammars (CC 2009)
Decorated Attribute Grammars (CC 2009)Decorated Attribute Grammars (CC 2009)
Decorated Attribute Grammars (CC 2009)
 
Pharo, an innovative and open-source Smalltalk
Pharo, an innovative and open-source SmalltalkPharo, an innovative and open-source Smalltalk
Pharo, an innovative and open-source Smalltalk
 
Cryptanalysis Project Report
Cryptanalysis Project ReportCryptanalysis Project Report
Cryptanalysis Project Report
 
Js in js
Js in jsJs in js
Js in js
 
JSUG - Effective Java Puzzlers by Christoph Pickl
JSUG - Effective Java Puzzlers by Christoph PicklJSUG - Effective Java Puzzlers by Christoph Pickl
JSUG - Effective Java Puzzlers by Christoph Pickl
 
Programmation fonctionnelle Scala
Programmation fonctionnelle ScalaProgrammation fonctionnelle Scala
Programmation fonctionnelle Scala
 
The finite element method theory implementation and applications
The finite element method theory  implementation  and applicationsThe finite element method theory  implementation  and applications
The finite element method theory implementation and applications
 
104 Icdcit05
104 Icdcit05104 Icdcit05
104 Icdcit05
 
Lesson19 Maximum And Minimum Values 034 Slides
Lesson19   Maximum And Minimum Values 034 SlidesLesson19   Maximum And Minimum Values 034 Slides
Lesson19 Maximum And Minimum Values 034 Slides
 
Joe Bew - Apprendi un nuovo linguaggio sfruttando il TDD e il Clean Code - Co...
Joe Bew - Apprendi un nuovo linguaggio sfruttando il TDD e il Clean Code - Co...Joe Bew - Apprendi un nuovo linguaggio sfruttando il TDD e il Clean Code - Co...
Joe Bew - Apprendi un nuovo linguaggio sfruttando il TDD e il Clean Code - Co...
 
C Language Unit-6
C Language Unit-6C Language Unit-6
C Language Unit-6
 
Lecture4
Lecture4Lecture4
Lecture4
 
Lecture4
Lecture4Lecture4
Lecture4
 
Flat
FlatFlat
Flat
 
3
33
3
 
Manual specialization
Manual specializationManual specialization
Manual specialization
 
Structure and interpretation of computer programs modularity, objects, and ...
Structure and interpretation of computer programs   modularity, objects, and ...Structure and interpretation of computer programs   modularity, objects, and ...
Structure and interpretation of computer programs modularity, objects, and ...
 
Unit3 java
Unit3 javaUnit3 java
Unit3 java
 
MATHEON Center Days: Index determination and structural analysis using Algori...
MATHEON Center Days: Index determination and structural analysis using Algori...MATHEON Center Days: Index determination and structural analysis using Algori...
MATHEON Center Days: Index determination and structural analysis using Algori...
 
Scale Up with Lock-Free Algorithms @ JavaOne
Scale Up with Lock-Free Algorithms @ JavaOneScale Up with Lock-Free Algorithms @ JavaOne
Scale Up with Lock-Free Algorithms @ JavaOne
 

Similar to Class 29: Inheritance

Pydiomatic
PydiomaticPydiomatic
Pydiomaticrik0
 
Analysis of Short RSA Secret Exponent d
Analysis of Short RSA Secret Exponent dAnalysis of Short RSA Secret Exponent d
Analysis of Short RSA Secret Exponent dDharmalingam Ganesan
 
Recursion - Computer Algorithms
Recursion - Computer AlgorithmsRecursion - Computer Algorithms
Recursion - Computer AlgorithmsAlaa Al-Makhzoomy
 
20101017 program analysis_for_security_livshits_lecture02_compilers
20101017 program analysis_for_security_livshits_lecture02_compilers20101017 program analysis_for_security_livshits_lecture02_compilers
20101017 program analysis_for_security_livshits_lecture02_compilersComputer Science Club
 
Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1Deepak John
 
The TclQuadcode Compiler
The TclQuadcode CompilerThe TclQuadcode Compiler
The TclQuadcode CompilerDonal Fellows
 
Class 18: Measuring Cost
Class 18: Measuring CostClass 18: Measuring Cost
Class 18: Measuring CostDavid Evans
 
Tip Top Typing - A Look at Python Typing
Tip Top Typing - A Look at Python TypingTip Top Typing - A Look at Python Typing
Tip Top Typing - A Look at Python TypingPatrick Viafore
 
03 truncation errors
03 truncation errors03 truncation errors
03 truncation errorsmaheej
 
TensorFlow for IITians
TensorFlow for IITiansTensorFlow for IITians
TensorFlow for IITiansAshish Bansal
 
Python 2.5 reference card (2009)
Python 2.5 reference card (2009)Python 2.5 reference card (2009)
Python 2.5 reference card (2009)gekiaruj
 
Cuckoo Search Algorithm: An Introduction
Cuckoo Search Algorithm: An IntroductionCuckoo Search Algorithm: An Introduction
Cuckoo Search Algorithm: An IntroductionXin-She Yang
 
Introducción al Análisis y diseño de algoritmos
Introducción al Análisis y diseño de algoritmosIntroducción al Análisis y diseño de algoritmos
Introducción al Análisis y diseño de algoritmosluzenith_g
 
05 history of cv a machine learning (theory) perspective on computer vision
05  history of cv a machine learning (theory) perspective on computer vision05  history of cv a machine learning (theory) perspective on computer vision
05 history of cv a machine learning (theory) perspective on computer visionzukun
 
FLATMAP ZAT SHIT : les monades expliquées aux geeks (Devoxx France 2013)
FLATMAP ZAT SHIT : les monades expliquées aux geeks (Devoxx France 2013)FLATMAP ZAT SHIT : les monades expliquées aux geeks (Devoxx France 2013)
FLATMAP ZAT SHIT : les monades expliquées aux geeks (Devoxx France 2013)François Sarradin
 

Similar to Class 29: Inheritance (20)

Pydiomatic
PydiomaticPydiomatic
Pydiomatic
 
Python idiomatico
Python idiomaticoPython idiomatico
Python idiomatico
 
Analysis of Short RSA Secret Exponent d
Analysis of Short RSA Secret Exponent dAnalysis of Short RSA Secret Exponent d
Analysis of Short RSA Secret Exponent d
 
Recursion - Computer Algorithms
Recursion - Computer AlgorithmsRecursion - Computer Algorithms
Recursion - Computer Algorithms
 
20101017 program analysis_for_security_livshits_lecture02_compilers
20101017 program analysis_for_security_livshits_lecture02_compilers20101017 program analysis_for_security_livshits_lecture02_compilers
20101017 program analysis_for_security_livshits_lecture02_compilers
 
Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1Anlysis and design of algorithms part 1
Anlysis and design of algorithms part 1
 
The TclQuadcode Compiler
The TclQuadcode CompilerThe TclQuadcode Compiler
The TclQuadcode Compiler
 
Class 18: Measuring Cost
Class 18: Measuring CostClass 18: Measuring Cost
Class 18: Measuring Cost
 
Tip Top Typing - A Look at Python Typing
Tip Top Typing - A Look at Python TypingTip Top Typing - A Look at Python Typing
Tip Top Typing - A Look at Python Typing
 
03 truncation errors
03 truncation errors03 truncation errors
03 truncation errors
 
TensorFlow for IITians
TensorFlow for IITiansTensorFlow for IITians
TensorFlow for IITians
 
Daa notes 2
Daa notes 2Daa notes 2
Daa notes 2
 
The Perceptron (D1L2 Deep Learning for Speech and Language)
The Perceptron (D1L2 Deep Learning for Speech and Language)The Perceptron (D1L2 Deep Learning for Speech and Language)
The Perceptron (D1L2 Deep Learning for Speech and Language)
 
Python 2.5 reference card (2009)
Python 2.5 reference card (2009)Python 2.5 reference card (2009)
Python 2.5 reference card (2009)
 
Cuckoo Search Algorithm: An Introduction
Cuckoo Search Algorithm: An IntroductionCuckoo Search Algorithm: An Introduction
Cuckoo Search Algorithm: An Introduction
 
Alg1
Alg1Alg1
Alg1
 
Introducción al Análisis y diseño de algoritmos
Introducción al Análisis y diseño de algoritmosIntroducción al Análisis y diseño de algoritmos
Introducción al Análisis y diseño de algoritmos
 
05 history of cv a machine learning (theory) perspective on computer vision
05  history of cv a machine learning (theory) perspective on computer vision05  history of cv a machine learning (theory) perspective on computer vision
05 history of cv a machine learning (theory) perspective on computer vision
 
FLATMAP ZAT SHIT : les monades expliquées aux geeks (Devoxx France 2013)
FLATMAP ZAT SHIT : les monades expliquées aux geeks (Devoxx France 2013)FLATMAP ZAT SHIT : les monades expliquées aux geeks (Devoxx France 2013)
FLATMAP ZAT SHIT : les monades expliquées aux geeks (Devoxx France 2013)
 
Taylor problem
Taylor problemTaylor problem
Taylor problem
 

More from David Evans

Cryptocurrency Jeopardy!
Cryptocurrency Jeopardy!Cryptocurrency Jeopardy!
Cryptocurrency Jeopardy!David Evans
 
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for CypherpunksTrick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for CypherpunksDavid Evans
 
Hidden Services, Zero Knowledge
Hidden Services, Zero KnowledgeHidden Services, Zero Knowledge
Hidden Services, Zero KnowledgeDavid Evans
 
Anonymity in Bitcoin
Anonymity in BitcoinAnonymity in Bitcoin
Anonymity in BitcoinDavid Evans
 
Midterm Confirmations
Midterm ConfirmationsMidterm Confirmations
Midterm ConfirmationsDavid Evans
 
Scripting Transactions
Scripting TransactionsScripting Transactions
Scripting TransactionsDavid Evans
 
How to Live in Paradise
How to Live in ParadiseHow to Live in Paradise
How to Live in ParadiseDavid Evans
 
Mining Economics
Mining EconomicsMining Economics
Mining EconomicsDavid Evans
 
Becoming More Paranoid
Becoming More ParanoidBecoming More Paranoid
Becoming More ParanoidDavid Evans
 
Asymmetric Key Signatures
Asymmetric Key SignaturesAsymmetric Key Signatures
Asymmetric Key SignaturesDavid Evans
 
Introduction to Cryptography
Introduction to CryptographyIntroduction to Cryptography
Introduction to CryptographyDavid Evans
 
Class 1: What is Money?
Class 1: What is Money?Class 1: What is Money?
Class 1: What is Money?David Evans
 
Multi-Party Computation for the Masses
Multi-Party Computation for the MassesMulti-Party Computation for the Masses
Multi-Party Computation for the MassesDavid Evans
 
Proof of Reserve
Proof of ReserveProof of Reserve
Proof of ReserveDavid Evans
 
Blooming Sidechains!
Blooming Sidechains!Blooming Sidechains!
Blooming Sidechains!David Evans
 
Useful Proofs of Work, Permacoin
Useful Proofs of Work, PermacoinUseful Proofs of Work, Permacoin
Useful Proofs of Work, PermacoinDavid Evans
 

More from David Evans (20)

Cryptocurrency Jeopardy!
Cryptocurrency Jeopardy!Cryptocurrency Jeopardy!
Cryptocurrency Jeopardy!
 
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for CypherpunksTrick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
 
Hidden Services, Zero Knowledge
Hidden Services, Zero KnowledgeHidden Services, Zero Knowledge
Hidden Services, Zero Knowledge
 
Anonymity in Bitcoin
Anonymity in BitcoinAnonymity in Bitcoin
Anonymity in Bitcoin
 
Midterm Confirmations
Midterm ConfirmationsMidterm Confirmations
Midterm Confirmations
 
Scripting Transactions
Scripting TransactionsScripting Transactions
Scripting Transactions
 
How to Live in Paradise
How to Live in ParadiseHow to Live in Paradise
How to Live in Paradise
 
Bitcoin Script
Bitcoin ScriptBitcoin Script
Bitcoin Script
 
Mining Economics
Mining EconomicsMining Economics
Mining Economics
 
Mining
MiningMining
Mining
 
The Blockchain
The BlockchainThe Blockchain
The Blockchain
 
Becoming More Paranoid
Becoming More ParanoidBecoming More Paranoid
Becoming More Paranoid
 
Asymmetric Key Signatures
Asymmetric Key SignaturesAsymmetric Key Signatures
Asymmetric Key Signatures
 
Introduction to Cryptography
Introduction to CryptographyIntroduction to Cryptography
Introduction to Cryptography
 
Class 1: What is Money?
Class 1: What is Money?Class 1: What is Money?
Class 1: What is Money?
 
Multi-Party Computation for the Masses
Multi-Party Computation for the MassesMulti-Party Computation for the Masses
Multi-Party Computation for the Masses
 
Proof of Reserve
Proof of ReserveProof of Reserve
Proof of Reserve
 
Silk Road
Silk RoadSilk Road
Silk Road
 
Blooming Sidechains!
Blooming Sidechains!Blooming Sidechains!
Blooming Sidechains!
 
Useful Proofs of Work, Permacoin
Useful Proofs of Work, PermacoinUseful Proofs of Work, Permacoin
Useful Proofs of Work, Permacoin
 

Recently uploaded

Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 

Recently uploaded (20)

Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 

Class 29: Inheritance

  • 1. Class 29: Inheritance cs1120 Fall 2011 David Evans 31 October 2011
  • 4. What’s a Protocol? A protocol is an algorithm that involves two or more parties. 4
  • 5. What’s an Algorithm? An algorithm is a A procedure is a well procedure that defined sequence of always steps that can be finishes, and followed produces the mechanically. correct output. 5
  • 6. “Trick or Treat” Protocols Two parties: Tricker: initiates the protocol by demanding tribute Victim: either pays tribute (usually in the form of sugary snack) or risks trick Tricker must convince Victim that she poses a credible threat: prove she is a qualified tricker
  • 7. Trick-or-Treat “Trick or Treat?” Victim “Prove it!” Trickers? “The magic word is: shazam!” Any problems with this?
  • 8. Authentication How can the tricker prove their trickability, without allowing the victim to now impersonate a tricker? 8
  • 9. One-Way Functions f is a one-way function if it is a function y = f(x) that satisfies these two properties: Invertible: there exists an f -1 such that, for all x in range: f -1 (f (x)) = x One-way: it is much, much, much easier to compute f (x) than to compute f -1 (y)
  • 10. Example One-Way-ish Function: Factoring Forward: given p and q are 200-digit prime numbers, output n = pq Backward: given n, output (p, q) Forward: (p, q) easy to calculate f (p, q). Easy means we know is an algorithm with running time in O(N2) where N is number of digits Backward: given n = f (p, q): hard to find p and q. Hard means (we hope) the fastest possible procedure has running time in (2N) .
  • 12. Factors from Exam 1 (Solutions) (define (factors n) (list-reverse (factors-helper (- n 1) n))) (define (factors-helper t n) (if (< t 2) null (if (is-divisible? n t) (cons t (factors-helper (- t 1) n)) (factors-helper (- t 1) n)))) 12
  • 13. Factors (define (factors n) (list-reverse (factors-helper (- n 1) n))) (define (factors-helper t n) (if (< t 2) null (if (is-divisible? n t) (cons t (factors-helper (- t 1) n)) (factors-helper (- t 1) n)))) 13
  • 14. (define (factors n) (list-reverse def factors(n): (factors-helper (- n 1) n))) res = [] (define (factors-helper t n) for d in range(2, n): (if (< t 2) null (if (is-divisible? n t) if n % d == 0: (cons t res.append(d) (factors-helper (- t 1) n)) return res (factors-helper (- t 1) n)))) 14
  • 15. (define (factors n) (list-reverse def factors(n): (factors-helper (- n 1) n))) res = [] (define (factors-helper t n) for d in range(2, n): (if (< t 2) null (if (is-divisible? n t) if n % d == 0: (cons t res.append(d) (factors-helper (- t 1) n)) return res (factors-helper (- t 1) n)))) Assuming (aggressively!) that is-divisible? (or %) is constant time, running time is in (V) where V is the value of n. But, this is in (2N) where N is the size of n. 15
  • 16. Does this prove that factoring is hard? 16
  • 17. Best Known Factoring Algorithm General Number Field Sieve: running time is in 1 2 (log N ) £ (log log N ) 3 3 O(e ) where N is the number of bits in input. Note: unless you have a big quantum computer! Then the running time is in 3 O((logN ) ) 17
  • 18. Checks the factors multiple to produce n Problems with this?
  • 19. Tricker Needs to Solve Trap-Door One-Way Function: One-way function that can be quickly inverted, but only if you have a secret! 19
  • 20. RSA Encryption System E(M) = Me mod n D(C) = Cd mod n n = pq p, q are prime d is relatively prime to (p – 1)(q – 1) ed 1 (mod (p – 1)(q – 1)) d is the trap-door secret: if you have it, you can invert Me mod n 20
  • 21. Checks that D(x)e mod n = x How does victim know e and n?
  • 22. Help me verify “tricker@virginia.edu” Trickers Bureau Checks that D(x)eT@V mod n T@V = x
  • 23. Except on Halloween, this is called a public-key challenge-response authentication protocol. 23
  • 24. On the web, it is called “TLS” or “SSL” and the “Tricker’s Bureau” is called a “Certificate Authority”. 24
  • 25. Do One-Way Functions Exist? This is the most important open question in Computer Science (and Mathematics)! Same question as: • Are they problems where it is hard to find a solution, but easy to check it? • Can a computer that can always guess right between two choices better than one that can’t? • Is the class of problems that a Turing Machine can solve in polynomial time (O(nk)) smaller than the class of problems an always-guessing-right TM can solve in polynomial time? (P = NP) 25
  • 27. Making a Dog class Dog: def bark(self): print "wuff wuff wuff wuff" spot = Dog()
  • 28. There are many kinds of Dogs… class Dog: def __init__(self, n): self.name = n def bark(self): print “wuff wuff wuff wuff” class TalkingDog (Dog): def speak(self, stuff): print stuff
  • 29. Subclasses ClassDefinition ::= class SubClassName ( SuperClassName ) : FunctionDefinitions class TalkingDog (Dog): def speak(self, stuff): print stuff TalkingDog is a subclass of Dog. Dog is the superclass of TalkingDog.
  • 30. Every Dog has its Day class Dog: def __init__(self, n): self.name = n >>> bo = Dog('Bo') def bark(self): >>> scooby = TalkingDog('Scooby Doo') print “wuff wuff wuff wuff” >>> scooby.speak('Ta-da!') Ta-da! class TalkingDog (Dog): >>> bo.speak('Ta-da!') Traceback (most recent call last): def speak(self, stuff): File "<pyshell#11>", line 1, in <module> print stuff bo.speak('Ta-da!') AttributeError: Dog instance has no attribute 'speak‘ >>> scooby.bark() wuff wuff wuff wuff
  • 31. Speaking about Inheritance Inheritance is using the definition of Dog one class to define another class. TalkingDog inherits from Dog. TalkingDog TalkingDog is a subclass of Dog. The superclass of TalkingDog is Dog. These all mean the same thing.
  • 32. PS6 Make an adventure game programming with objects: Many objects in our game have similar properties and behaviors, so we use inheritance to reuse implementations.
  • 33. PS6 Classes SimObject PhysicalObject Place MobileObject OwnableObject Person Student PoliceOfficer
  • 34. class SimObject: def __init__(self, name): self.name = name def note(self, msg): SimObject print "%s: %s" % (self, msg) PhysicalObject Place class PhysicalObject (SimObject): MobileObject def __init__(self, name): SimObject.__init__(self, name) self.location = None def install(self, loc): OwnableObject self.note ("Installing at " + str(loc)) self.location = loc Person loc.add_thing(self) class MobileObject (PhysicalObject): def change_location(self, loc): self.location.remove_thing(self) Studentloc.add_thing(self) self.location = loc PoliceOfficer
  • 35. SimObject class MobileObject (PhysicalObject): def change_location(self, loc): PhysicalObject self.location.remove_thing(self) loc.add_thing(self) Place self.location = loc MobileObject OwnableObject Person class OwnableObject (MobileObject): def __init__(self, name): MobileObject.__init__(self, name) self.owner = None Student PoliceOfficer def is_ownable(self): return True
  • 36. PS6 Objects SimObject PhysicalObject Place MobileObject Place(‘Noodles Hall’) An object that is an instance of the Place class. OwnableObject Person Student PoliceOfficer aph = Student(‘Alyssa P. Hacker’)
  • 37. Does the “real world” have inheritance hierarchies like this, or only the fake world of Charlottansville? 37
  • 38. RotationPathInterpolator PathInterpolator Interpolator Node Selector Leaf SceneGraphObject Not at all uncommon to have class hierarchies like this! Java 3D Class Hierarchy Diagram http://java.sun.com/products/java-media/3D/collateral/j3dclass.html CS 201J Fall 2003 7 October 2003
  • 39. Try not to make any kids cry by asking them Summary to factor large numbers! An object packages state and procedures. A class provides procedures for making and manipulating a type of object. The procedures for manipulating objects are called methods. We invoke a method on an object. Inheritance allows one class to refine and reuse the behavior of another. Wednesday: Excursion on Exponential Growth Please ready Tyson essay before class Wednesday!