Lab 07: Caesar Cypher Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.

Slides:



Advertisements
Similar presentations
Relations, Functions, and Matrices Mathematical Structures for Computer Science Chapter 4 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesThe Mighty Mod.
Advertisements

Computer Science 101 Data Encryption And Computer Networks.
Section 4.1: The Basics of Counting As we have seen, one way to count the number of objects in a finite set S is to produce a one-to-one correspondence.
 Caesar used to encrypt his messages using a very simple algorithm, which could be easily decrypted if you know the key.  He would take each letter.
Section 3.6: An Introduction to Cryptography
Cryptography Programming Lab
Introduction to Functions Intro to Computer Science CS1510 Dr. Sarah Diesburg.
CATHERINE AND ANNIE Python: Part 4. Strings  Strings are interesting creatures. Although words are strings, anything contained within a set of quotes.
More on Functions (Part 2) Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Encryption: A Brief History Author: Margery Waldron.
Lab 07: Caesar Cypher Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Numerical Representation Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg 1.
CSCI 391: Practical Cryptology Substitution Monoalphabetic Ciphers.
Intro to Nested Looping Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Intro to Nested Looping Intro to Computer Science CS1510 Dr. Sarah Diesburg.
MAT 1000 Mathematics in Today's World Winter 2015.
Introduction to Strings Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg 1.
More on Functions Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Introduction to Files Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg 1.
Cryptography Cryptography is the use of mathematics to encode messages and prevent them from being read by anyone who doesn’t know the code. One way that.
Problem Solving Intro to Computer Science CS1510 Dr. Sarah Diesburg 1.
Encryption. LEARNING OBJECTIVES: BY THE END OF THE LESSON YOU SHOULD KNOW. What encryption is and why it is important The basics of encryption techniques.
More String Manipulation. Programming Challenge Define a function that accepts two arguments: a string literal and a single character. Have the function.
More on Functions Intro to Computer Science CS1510 Dr. Sarah Diesburg.
More on Functions (Part 2) Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Intelligent Data Systems Lab. Department of Computer Science & Engineering Practices 컴퓨터의 개념 및 실습 4 월 11 일.
 Type Called bool  Bool has only two possible values: True and False.
Numerical Representation
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
More Repetition While and For Loops Sentinel-Controlled Loops
Introduction to Strings
Introduction to Strings
Intro to Computer Science CS1510
More Nested Loops and Lab 5
Lists – Indexing and Sorting
Intro to Nested Looping
String Encodings and Penny Math
Intro to Nested Looping
Types, Truth, and Expressions (Part 2)
Intro to Computer Science CS1510 Dr. Sarah Diesburg
What is an equation? An equation is a mathematical statement that two expressions are equal. For example, = 7 is an equation. Note: An equation.
Intro to Computer Science CS1510
Reactive Android Development
Thinking about Strings
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
Simple Encryption- Lesson 5
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
More on Functions (Part 2)
Lists – Indexing and Sorting
Intro to Nested Looping
Numerical Representation
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
Introduction to Strings
functions: argument, return value
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Thinking about programming
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
Introduction to Strings
Intro to Nested Looping
Lists – Indexing and Sorting
String Encodings and Penny Math
Types, Truth, and Expressions
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Introduction to Strings
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Presentation transcript:

Lab 07: Caesar Cypher Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg

Caesar Cypher Method named after Julius Caesar  Used in his private correspondence One of the simplest and most widely-known encryption techniques

Caesar Cypher We can start understanding the Caesar Cypher by writing out each letter of the alphabet 3

Caesar Cypher To encode, we apply a rotation value to the alphabet Before encoding with rotation of 3: “hello” After encoding (shift 3 to right): “khoor” After decoding (shift 3 to left): “hello” 4

Caesar Cypher Two ways to solve the problem  Mathematically using ord() and chr() functions  Create a shifted string, use the str.find() method 5

Mathematical Solution This solution hinges around knowing the ASCII/Unicode values of letters We only encode lowercase letters and leave all other letters the same 6

Mathematical Solution ‘a’=97 ‘z’=122 As we go through the string to encrypt, each ord() of each character must be >= 97 and <= 122 for us to apply a shift We then add the rotation value (say 3) to the ord() of each character to create a shifted character We can then take the chr() of the shifted character to get the encoded character 8

Mathematical Solution But what if shifting the character brings us beyond our bound of z?  ord(y) + 3 = 124  chr(124) = “|” We must check that’s not the case by using an “if” statement if shiftedChar > 122: shiftedChar = shiftedChar

Mathematical Solution Let’s create the solution 10

Shifted String Solution The other solution involves using two strings Alphabet Shifted alphabet, based on rotation value (say 3) 11

Shifted String Solution We can go through the string to be encoded character by character For each character, we use the str.find() method to get the index of the character in the regular alphabet origIndex = input.find(“h”)  Is 7 12

Shifted String Solution Once we have the index of the character in the alphabet, we can look up what character is at that index in the shifted alphabet shiftedChar = shiftedAlphabet[7]  Remember, origIndex = 7  shiftedChar is now “k” 13

Shifted String Solution Let’s create the solution 14

Cracking the Code We don’t know the rotation value, but we do know one word in the decoded string We need to start decoding with all possible rotation values, starting at 1  If we can find the one word we know in the decoded string, we are done  Otherwise, we keep decoding with different rotation values (2,3,4,…) 15