COMP 250. Lecture 27. hashing. Nov. 10, 2017

Similar documents
COMP 250. Lecture 26. maps. Nov. 8/9, 2017

Test 2 Review. 1. (10 points) Timestamps and nonces are both used in security protocols to prevent replay attacks.

Test 2 Review. (b) Give one significant advantage of a nonce over a timestamp.

Questions. 6. Suppose we were to define a hash code on strings s by:

Collections Questions

Lecture 7: Efficient Collections via Hashing

Lecture 10: Introduction to Hash Tables

Strong Password Protocols

STANDARD ADTS Lecture 17 CS2110 Spring 2013

Introduction hashing: a technique used for storing and retrieving information as quickly as possible.

Assignment 9 / Cryptography

Passwords. CS 166: Introduction to Computer Systems Security. 3/1/18 Passwords J. Liebow-Feeser, B. Palazzi, R. Tamassia, CC BY-SA 2.

Data Structures. COMS W1007 Introduction to Computer Science. Christopher Conway 1 July 2003

Hash Tables. Hash Tables

CS 161 Computer Security

CS 161 Computer Security

1 / 22. Inf 2B: Hash Tables. Lecture 4 of ADS thread. Kyriakos Kalorkoti. School of Informatics University of Edinburgh

Standard ADTs. Lecture 19 CS2110 Summer 2009

1.00 Lecture 32. Hashing. Reading for next time: Big Java Motivation

Hashes, MACs & Passwords. Tom Chothia Computer Security Lecture 5

Assignment 4: Hashtables

Hash tables. hashing -- idea collision resolution. hash function Java hashcode() for HashMap and HashSet big-o time bounds applications

CRYPTOGRAPHY. Jakub Laszczyk. June 7th,

I certify that this DNS record set is correct Problem: how to certify a negative response, i.e. that a record doesn t exist?

Announcements. Hash Functions. Hash Functions 4/17/18 HASHING

Logic, Algorithms and Data Structures ADT:s & Hash tables. By: Jonas Öberg, Lars Pareto

Cryptographic Hash Functions

Sets and Maps. Part of the Collections Framework

CSE 143 Lecture 14 AnagramSolver and Hashing

Data Structures - CSCI 102. CS102 Hash Tables. Prof. Tejada. Copyright Sheila Tejada

Attacking Your Two-Factor Authentication (PS: Use Two-Factor Authentication)

1 Identification protocols

Tutorial #11 SFWR ENG / COMP SCI 2S03. Interfaces and Java Collections. Week of November 17, 2014

COMP 103 Introduction to Data Structures and Algorithms

CSCI 104 Hash Tables & Functions. Mark Redekopp David Kempe

Lecture 16. Reading: Weiss Ch. 5 CSE 100, UCSD: LEC 16. Page 1 of 40

Logistics. Next week, my OH will be vs HW6 (= writing + Monad.hs) counts! You HW grade = max of 5 HWs. CAPEs!

Abstract Data Types (ADTs) Queues & Priority Queues. Sets. Dictionaries. Stacks 6/15/2011

Kurose & Ross, Chapters (5 th ed.)

Fall 2017 Mentoring 9: October 23, Min-Heapify This. Level order, bubbling up. Level order, bubbling down. Reverse level order, bubbling up

The question paper contains 40 multiple choice questions with four choices and students will have to pick the correct one (each carrying ½ marks.).

MIDTERM EXAM THURSDAY MARCH

Homework 2. Out: 09/23/16 Due: 09/30/16 11:59pm UNIVERSITY OF MARYLAND DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING

CS2110: Software Development Methods. Maps and Sets in Java

Adam Blank Lecture 5 Winter 2019 CS 2. Introduction to Programming Methods

CS 241 Analysis of Algorithms

CS2 Algorithms and Data Structures Note 4

CS61B Lecture #24: Hashing. Last modified: Wed Oct 19 14:35: CS61B: Lecture #24 1

1.264 Lecture 28. Cryptography: Asymmetric keys

Encryption. INST 346, Section 0201 April 3, 2018

Lecture 3 - Passwords and Authentication

Cryptography (DES+RSA) by Amit Konar Dept. of Math and CS, UMSL

ח'/סיון/תשע "א. RSA: getting ready. Public Key Cryptography. Public key cryptography. Public key encryption algorithms

1 CSE 100: HASH TABLES

Authentication. Strong Password Protocol. IT352 Network Security Najwa AlGhamdi

Security: Cryptography

CSC 580 Cryptography and Computer Security

Hashes, MACs & Passwords. Tom Chothia Computer Security Lecture 5

P2_L8 - Hashes Page 1

CS Computer Networks 1: Authentication

1B1a Arrays. Arrays. Indexing. Naming arrays. Why? Using indexing. 1B1a Lecture Slides. Copyright 2003, Graham Roberts 1

Implementing Hash and AVL

Other Topics in Cryptography. Truong Tuan Anh

Outline. hash tables hash functions open addressing chained hashing

Lecture 17: Implementing HashTables 10:00 AM, Mar 5, 2018

Introduction to Security and User Authentication

CMSC 132: Object-Oriented Programming II. Hash Tables

HASH TABLES.

EXAMINATIONS 2005 END-YEAR. COMP 103 Introduction to Data Structures and Algorithms

Hash Tables. Gunnar Gotshalks. Maps 1

Lecture 3 - Passwords and Authentication

Hash Open Indexing. Data Structures and Algorithms CSE 373 SP 18 - KASEY CHAMPION 1

Hashing as a Dictionary Implementation

Computer Networks. Network Security and Ethics. Week 14. College of Information Science and Engineering Ritsumeikan University

Preview. A hash function is a function that:

PYTHIA SERVICE BY VIRGIL SECURITY WHITE PAPER

10/1/2015. Authentication. Outline. Authentication. Authentication Mechanisms. Authentication Mechanisms. Authentication Mechanisms

Bitcoin, Security for Cloud & Big Data

Lecture 6: Hashing Steven Skiena

CSCI 104. Rafael Ferreira da Silva. Slides adapted from: Mark Redekopp and David Kempe

Cryptography (Overview)

Introduction to Information Security Prof. V. Kamakoti Department of Computer Science and Engineering Indian Institute of Technology, Madras

Overview. CSC 580 Cryptography and Computer Security. Hash Function Basics and Terminology. March 28, Cryptographic Hash Functions (Chapter 11)

HASH TABLE BY AKARSH KUMAR

Introducing Hashing. Chapter 21. Copyright 2012 by Pearson Education, Inc. All rights reserved

ECE 435 Network Engineering Lecture 5

CS2110: Software Development Methods. Maps and Sets in Java

HashTable CISC5835, Computer Algorithms CIS, Fordham Univ. Instructor: X. Zhang Fall 2018

Assessment 1 Task 3 Explain the following security risks SQL Injection Cross Site Scripting XSS Brute Force Attack/Dictionary Attack

CPSC 467b: Cryptography and Computer Security

Programming Languages and Techniques (CIS120)

Installing the WinSCP Secure FTP Client

Math236 Discrete Maths with Applications

Intro to Public Key Cryptography Diffie & Hellman Key Exchange

CS 161 Computer Security

CNT4406/5412 Network Security

Kerberos V5. Raj Jain. Washington University in St. Louis

Lecture 19: cryptographic algorithms

Exercises: Disjoint Sets/ Union-find [updated Feb. 3]

CSC/ECE 774 Advanced Network Security

Transcription:

COMP 250 Lecture 27 hashing Nov. 10, 2017 1

RECALL Map keys (type K) values (type V) Each (key, value) pairs is an entry. For each key, there is at most one value. 2

RECALL Special Case keys are unique positive integers in small range 4 3 9 12 6 8 22 14 3

Java hashcode() keys K int (32 bits) 4

Today Map Composition hashcode 0 4 3 keys (K) int (32 bits) { 2 31, 0,, 2 31 1} 9 12 22 m-1 6 8 14 values (V) 5

hashcode compression 0 4 3 keys (K) int (32 bits) { 2 31, 0,, 2 31 1} 9 12 22 m-1 6 8 14 values (V) 6

compression i i mod m, where m is the length of the array. (many to 1) 0 3 int (32 bits) { 2 31, 0,, 2 31 1} 6 8 14 m-1 7

hash function hash values keys {0,, m-1} hashcode compression 0 4 3 9 12 6 8 keys (K) int 22 14 m-1 values (V) 8

hash function compression hashcode hash code hash value (hash code % 7) 41 16 25 21 36 35 53 6 2 4 0 1 0 4 9

Heads up! Values is used in two ways. hash function keys {0,, m-1} hash values hashcode() compression 0 4 3 9 12 6 8 keys (K) int (32 bits) 22 14 m-1 values (V) 10

Collision when two or more keys k map to the same hash value. hash values hashcode() compression 0 4 3 9 12 6 8 keys (K) int 22 14 m-1 11

Solution Hash Table (or Hash Map) each array slot holds a singly linked list of entries hash values hashcode() compression 0 4 3 9 12 6 8 keys (K) int 22 14 m-1 12

Each array slot + linked list is called a bucket. 0 4 9 12 3 6 8 Note simpler linked list notation here. 22 14 m-1 13

Why is it necessary to store (key, value) pairs in the linked list? Why not just the values? 14

Load factor of hash table number of key, value pairs in map number of buckets, m One typically keeps the load factor below 1. 15

https//en.oxforddictionaries.com/definition/hash#hash_noun_200 16

Good Hash 0 4 9 12 3 6 8 22 14 m-1 17

Bad Hash 0 9 3 6 8 22 14 m-1 18

Example h K {0, 1,, m-1} Example Suppose keys are McGill Student IDs, e.g. 260745918. How many buckets to choose? Good hash function? Bad hash function? 19

Example h K {0, 1,, m-1} Example Suppose keys are McGill Student IDs, e.g. 260745918. How many buckets to choose? (~number of entries) Good hash function? Bad hash function? (rightmost 5 digits) (leftmost 5 digits) 20

Performance of Hash Maps put(key, value) get(key) remove(key) If load factor is less than 1 and if hash function is good, then operations are O(1) in practice. Note we can use a different hash function if performance is poor. 21

Performance of Hash Maps put(key, value) get(key) remove(key) contains(value) 22

Performance of Hash Maps put(key, value) get(key) remove(key) contains(value) It will need to look at each bucket and check the list for that value. So we don t want too big an array. 23

Java HashMap <K, V> class In constructor, you can specify initial number of buckets, and maximum load factor How is hash function specified? 24

Java HashMap <K, V> class In constructor, you can specify initial number of buckets, and maximum load factor How is hash function specified? Use key s hashcode(), take absolute value, and compress it by taking mod of the number of buckets. 25

Java HashSet<E> class Similar to HashMap, but there are no values. Just use it to store a set of objects of some type. add(e) contains( e) remove( e) If hash function is good, then these operations are O(1). 26

Cryptographic Hashing e.g. h key (String) hash value (128 bits) online tool for computing md5 hash of a string 27

Cryptographic Hashing e.g. h key (String) hash value (128 bits) online tool for computing md5 hash of a string Displays 128 bit result in hexadecimal. 0101 0001 0011 1010 1111 1011 0010. 5 1 3 a f b 2 28

Cryptographic Hashing We want a hash function h( ) such that if is given a hash value, then one can infer almost nothing about the key. Small changes in the key give very different hash values. Many to one (scrambled) All strings 128 bit strings 29

Example Application (Sketch) Password Authentication e.g. Web server needs to authenticate users. Keys are usernames (String, number e.g. credit card) Values are passwords (String) { (usernames, passwords) } defines a map. 30

Password Authentication (unsecure) Suppose the {(username, password)} map is stored in a plain text file on the web server where user logs in. What would the user do to log in? What would the web server do? What could a mischievous hacker do? 31

Password Authentication (unsecure) Suppose the {(username, password)} map is stored in a plain text file on the web server where user logs in. What would the user do to log in? Enter username (key) and password (value). What would the web server do? Check if this entry matches what is stored in the map. What could a mischievous hacker do? Steal the password file, and login to user accounts. 32

Password Authentication (secure) Suppose the {(username, h(password) ) } map is stored in a file on the web server. What would the user do? What would the web server do? What could a mischievous hacker try to do? 33

Password Authentication (secure) Suppose the {(user name, h(password) ) } map is stored in a file on the web server. What would the user do? Enter a username and password. What would the web server do? Hash the password and compare to entry in map. What could a mischievous hacker try to do? Brute force or dictionary attack. 34

Brute force & dictionary attacks If hacker knows your user name, he can try logging in with many different passwords. (Brute force = try all, dictionary = try a chosen set e.g. hello123 ) To reduce the probability of a hacker finding your password, user should choose long passwords with lots of special characters. Note that hacker doesn t need your password. He just needs a password such that h(your pass) = h(his pass). 35

hashing password h(password) message encryption decryption encrypted message You will learn about RSA encryption in MATH 240. 36