Learning to be a code alchemist, one experiment at a time.

Cryptography Week 2: Limitations of the One Time Pad

|

A real world application of the 1timepad is the Red Phone of the 1980’s, with suitcases full of bits flown between moscow and DC


Limitations:

Key is as long as message Only secure if each key is used only once Therefore total length of keys shared must = total length of all messages ever want to send


Break if 2 messages to encrypt using one key

m1 -> &1 m2 -> &2

&1 XOR &2 = m1 XOR m2

Although it might not be useful, it rules out perfect secrecy

However it is useful

this reveals where m1 and m2 differ If plaintext are long can apply frequency analysis All letters begin with 01 Space is 00 XOR of 2 letters, get a byte with 00 prefix XOR of letter and space, get a byte with 01 prefix XOR of 2 spaces, get 00, but not common Therefore, can guess what is in each location Punctuation can mess this up but its uncommon so don’t worry about it

Using this method letters are guessable

not just 1 time pad, but inherent to many schemes One time pad is optimal as far as length of key goes Now relax the definition of perfect secrecy, obtain much more applicable ideas

What is OpenCV?

|

What is OpenCV?

  • Open source computer vision library in C/C++. Wrappers are provided for languages including Python.
  • Optimized and intended for real-time applications.

What is it used for?

  • Image data manipulation
  • Image and video I/O
  • Matrix and vector manipulation and linear algebra routines (products, solvers, eigenvalues, SVD).
  • Basic image processing (filtering, edge detection, corner detection, sampling and interpolation, color conversion, morphological operations, histograms, image pyramids).
  • Structural analysis (connected components, contour processing, distance transform, various moments, template matching, Hough transform, polygonal approximation, line fitting, ellipse fitting, Delaunay triangulation).
  • Motion analysis (optical flow, motion segmentation, tracking).
  • Object recognition (eigen-methods, HMM).

Rest Principles

|

What is a REST API?

A way of thinking about how a web server responds to your requests It doesn’t just respond with data, it responds with resources

Resource? Think about it as OOP and each server as having resources that interact with the request

For example, GET/POST/PUT/DELETE /item/chair its the chair in the item resource and our requests interact with it in different ways


REST is supposed to be stateless:

One request cannot depend on any other request For example, logging into a website is not remembered (stateless) so the application must send enough information in every request to identify the user


Use Json: essentially a dictionary, or more technically a string of a dictionary


Test First API Design:

Design the endpoints first Lets you make design decisions first, like name or ID, etc. Figure out what you actually need for your API

HTTP Verbs

|

What is a web server?

A piece of software designed to accept incoming web requests

Consider google.com; what does the google web server see when you navigate to google.com?

GET / HTTP/1.1 Host: www.google.com

GET: Its the HTTP Verb / : Its the path HTTP/1.1: HTTP protocol


GET, POST, DELETE, PUT, OPTIONS, HEAD

GET: retrieve some data POST: Receive some data and do something with it PUT: Make sure something exists; if it doesnt, make it DELETE: Remove something

Python: What are *args and **kwargs?

|

*args is something you pass into a function when it might be a variable number of inputs:

for example, the following function only works for 2 variables:

def sum(a,b): return(a+b)

what if you want more variables?

def sum(*args): sum=0 for number in args: sum+=number return(sum)

^^The above function will add any number of inputted variables together

A real example:

def my_three(a, b, c): print(a, b, c) a = [1,2,3]

here list is broken into three elements

my_three(*a)


**kwargs allows us to pass variable number of keyword arguments:

def my_func(**kwargs): for i, j in kwargs.items(): print(i, j)

my_func(name=’neil’, language=’python’, year=2)

language python year 2 name neil