Presentation is loading. Please wait.

Presentation is loading. Please wait.

CMPT 120 Lecture 10 – Unit 2 – Cryptography and Encryption –

Similar presentations


Presentation on theme: "CMPT 120 Lecture 10 – Unit 2 – Cryptography and Encryption –"— Presentation transcript:

1 CMPT 120 Lecture 10 – Unit 2 – Cryptography and Encryption –
The realm of secret codes Python – Range function

2 Last Lecture, we did …

3 Let’s implement our program now!
Problem Statement: Write a program that encrypts messages using a transposition algorithm called “odd&even” odd&even transposition algorithm: Create a cypher that is made of 2 strings String 1 contains the characters in odd positions String 2 contains the characters in even positions

4 Let’s decrypt our message!
Problem Statement: Write a program that decrypts messages that have been encrypted using the transposition algorithm odd&even

5 Our first decryption algorithm
In order to implement our first decryption algorithm, we need to know … String concatenation Arithmetic operator Indexing Slicing len( ) function range( ) function

6 Reading Review String Indexing: "Hello World!"[6] ->
message = "slicing" message[ ] -> String Slicing: message[ : ] -> message[ : : ] -> " "[2:8:3] ->

7 Reading Review range( ) function
What will we see printed on the Python Interpreter shell window if : range(10) range(1, 11) range(0, 30, 5) range(0, 10, -3) range(0, -10, -1) range(0) To see the sequence produced by the function range( ) on the Python Interpreter shell window : list(range(...))

8 Review - Syntax of a for loop
Can be a string <statement outside (before) the loop> for <iterating variable> in <sequence> : <first statement to be repeated> <second statement to be repeated> ... <last statement to be repeated> <statement outside (after) the loop> Can be a list Can be produced using range(…)

9 Review - Syntax of a for loop
<statement outside (before) the loop> for <iterating variable> in <sequence> : <first statement to be repeated> <second statement to be repeated> ... <last statement to be repeated> <statement outside (after) the loop> Important – About Indentation Statements inside the loop (i.e., statements executed at each iteration of the loop) are the statements indented with respect to the for keyword Statements outside the loop (before and after the loop) are the statements that are not indented with respect to the for keyword – these statements are considered to be at the same level of indentation as the for loop

10 Review - range( ) function
Very useful in for loop Syntax: range([start,] stop [,step])) Produces a list of integers How does it work? If theLength = 5 Then range(theLength) produces [0, 1, 2, 3, 4]

11 Next Lecture Let’s practice what we have learnt so far
Practice Exam 2 -> paper-based


Download ppt "CMPT 120 Lecture 10 – Unit 2 – Cryptography and Encryption –"

Similar presentations


Ads by Google