diff --git a/A1/tp-spa/.Rhistory b/A1/tp-spa/.Rhistory new file mode 100644 index 0000000..e69de29 diff --git a/A1/tp-spa/.gitignore b/A1/tp-spa/.gitignore new file mode 100644 index 0000000..3522fc9 --- /dev/null +++ b/A1/tp-spa/.gitignore @@ -0,0 +1,2 @@ +*.ipynb_checkpoints +*~ diff --git a/A1/tp-spa/README.md b/A1/tp-spa/README.md new file mode 100644 index 0000000..7a33ae8 --- /dev/null +++ b/A1/tp-spa/README.md @@ -0,0 +1,13 @@ +# Simple Power Analysis to Extract a Password + +Exercise with ChipWhisperer boards to find a password by simple power analysis. + +Start the jupyter serve with the following command: + + jupyter notebook + +If this doesn't work, you might need to install some dependencies: + + pip3 install -r requirements.txt + +and try again. diff --git a/A1/tp-spa/SPA.ipynb b/A1/tp-spa/SPA.ipynb new file mode 100644 index 0000000..5816e75 --- /dev/null +++ b/A1/tp-spa/SPA.ipynb @@ -0,0 +1,4495 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Simple Power Analysis for Password Bypass" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "---\n", + "NOTE: This lab references some training material on [ChipWhisperer.io](https://www.ChipWhisperer.io). You can freely execute and use the lab per the open-source license (including using it in your own courses if you distribute similarly), but you must maintain notice about this source location. \n", + "\n", + "---" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**SUMMARY:** *This tutorial will introduce you to breaking devices by determining when a device is performing certain operations. Our target device will be performing a simple password check, and we will demonstrate how to perform a basic power analysis.*\n", + "\n", + "**LEARNING OUTCOMES:**\n", + "\n", + "* How power can be used to determine timing information.\n", + "* Plotting multiple iterations while varying input data to find interesting locations.\n", + "* Using difference of waveforms to find interesting locations.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Setup" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "First, we will need to do some basic setup for the ChipWhisperer hardware (or software). This exercise works either with real hardware (the ChipWhisperer Nano board) or by simulating the measurements using pre-recorded power traces. Just execute the following cell in order to pull in the needed function definitions, according to your setup:" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "(ChipWhisperer Other WARNING|File __init__.py:50) Old pip version: 20.3.4, unable to do CW version check\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "INFO: Found ChipWhisperer😍\n", + "Detected known STMF32: STM32F04xxx\n", + "Extended erase (0x44), this can take ten seconds or more\n", + "Attempting to program 4775 bytes at 0x8000000\n", + "STM32F Programming flash...\n", + "STM32F Reading flash...\n", + "Verified flash OK, 4775 bytes\n" + ] + } + ], + "source": [ + "# Use this script for a simulated version\n", + "#%run \"traces/password_sim.ipynb\" \n", + "\n", + "# Use this script with the ChipWhisperer Nano board:\n", + "%run \"traces/password_hw.ipynb\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## The Victim Code" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The complete victim code can be inspected in the file `passwdcheck.c` or [here in your browser](img/passwdcheck.c.html). Below you can find a screenshot of the main function:\n", + "\n", + "\"Main\n", + "\n", + "What it does (after some initializations) is the following:\n", + "\n", + "* Print out a scary message to the user (over the serial interface)\n", + "* Wait for the user to send a password\n", + "* Compare the sent password with the correct one\n", + "* Send an appropriate response to the user" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The most interesting part is the for loop between lines 20 and 26. Note that the loop quits once it encounters an incorrect character in the password provided by the user. This is the leakage that we will try to exploit: The number of iterations depends on the number of correct characters from the beginning of the password. This means that there is a *timing side-channel*. Unfortunately, it turns out that this side-channel is difficult to exploit directly: Before sending the reply (line 31), the system waits for several milliseconds. Adding to this the timing noise from the serial communication (on both ends of the interface), the slight variation in execution time cannot be detected reliably by timing the response of the system. \n", + "\n", + "What we will do instead is using *another side-channel* that will allow us to detect the different execution paths taken by the program. It is based on the fact that the *power consumption* of the processor differs depending on the type of instruction executed. With a bit of luck, looking at captured power traces will do the trick.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Power Trace Gathering" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We have provided a function that simulates sending of passwords to the device and the capturing of power traces. On the real hardware, this comprises the following steps:\n", + "\n", + "* Reset the target\n", + "* Read the welcome message (and discard it)\n", + "* Send the password guess (with added newline) to the target\n", + "* Capture a power trace of 1000 samples\n", + "* Read the target's response (and discard it)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Let's test the function with a single letter password:" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "✔️ OK to continue!\n" + ] + } + ], + "source": [ + "trace_test = cap_pass_trace(\"foo\\n\")\n", + "\n", + "#Basic sanity check\n", + "assert(len(trace_test) == 1000)\n", + "print(\"✔️ OK to continue!\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Another function can be used to obtain the response of the target system when sending it a password:" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "PASSWORD FAIL\n", + "\n" + ] + } + ], + "source": [ + "resp = pass_response(\"foo\\n\")\n", + "print (resp)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exploration" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "So what can we do with this? While first off - I'm going to cheat, and tell you that we have a preset password that starts with `h`, and it's 5 characters long. But that's the only hint so far - what can you do? While first off, let's try plotting a comparison of `h` to something else." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "WARNING:matplotlib.font_manager:Matplotlib is building the font cache; this may take a moment.\n" + ] + }, + { + "data": { + "application/javascript": [ + "/* Put everything inside the global mpl namespace */\n", + "/* global mpl */\n", + "window.mpl = {};\n", + "\n", + "mpl.get_websocket_type = function () {\n", + " if (typeof WebSocket !== 'undefined') {\n", + " return WebSocket;\n", + " } else if (typeof MozWebSocket !== 'undefined') {\n", + " return MozWebSocket;\n", + " } else {\n", + " alert(\n", + " 'Your browser does not have WebSocket support. ' +\n", + " 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n", + " 'Firefox 4 and 5 are also supported but you ' +\n", + " 'have to enable WebSockets in about:config.'\n", + " );\n", + " }\n", + "};\n", + "\n", + "mpl.figure = function (figure_id, websocket, ondownload, parent_element) {\n", + " this.id = figure_id;\n", + "\n", + " this.ws = websocket;\n", + "\n", + " this.supports_binary = this.ws.binaryType !== undefined;\n", + "\n", + " if (!this.supports_binary) {\n", + " var warnings = document.getElementById('mpl-warnings');\n", + " if (warnings) {\n", + " warnings.style.display = 'block';\n", + " warnings.textContent =\n", + " 'This browser does not support binary websocket messages. ' +\n", + " 'Performance may be slow.';\n", + " }\n", + " }\n", + "\n", + " this.imageObj = new Image();\n", + "\n", + " this.context = undefined;\n", + " this.message = undefined;\n", + " this.canvas = undefined;\n", + " this.rubberband_canvas = undefined;\n", + " this.rubberband_context = undefined;\n", + " this.format_dropdown = undefined;\n", + "\n", + " this.image_mode = 'full';\n", + "\n", + " this.root = document.createElement('div');\n", + " this.root.setAttribute('style', 'display: inline-block');\n", + " this._root_extra_style(this.root);\n", + "\n", + " parent_element.appendChild(this.root);\n", + "\n", + " this._init_header(this);\n", + " this._init_canvas(this);\n", + " this._init_toolbar(this);\n", + "\n", + " var fig = this;\n", + "\n", + " this.waiting = false;\n", + "\n", + " this.ws.onopen = function () {\n", + " fig.send_message('supports_binary', { value: fig.supports_binary });\n", + " fig.send_message('send_image_mode', {});\n", + " if (fig.ratio !== 1) {\n", + " fig.send_message('set_dpi_ratio', { dpi_ratio: fig.ratio });\n", + " }\n", + " fig.send_message('refresh', {});\n", + " };\n", + "\n", + " this.imageObj.onload = function () {\n", + " if (fig.image_mode === 'full') {\n", + " // Full images could contain transparency (where diff images\n", + " // almost always do), so we need to clear the canvas so that\n", + " // there is no ghosting.\n", + " fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n", + " }\n", + " fig.context.drawImage(fig.imageObj, 0, 0);\n", + " };\n", + "\n", + " this.imageObj.onunload = function () {\n", + " fig.ws.close();\n", + " };\n", + "\n", + " this.ws.onmessage = this._make_on_message_function(this);\n", + "\n", + " this.ondownload = ondownload;\n", + "};\n", + "\n", + "mpl.figure.prototype._init_header = function () {\n", + " var titlebar = document.createElement('div');\n", + " titlebar.classList =\n", + " 'ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix';\n", + " var titletext = document.createElement('div');\n", + " titletext.classList = 'ui-dialog-title';\n", + " titletext.setAttribute(\n", + " 'style',\n", + " 'width: 100%; text-align: center; padding: 3px;'\n", + " );\n", + " titlebar.appendChild(titletext);\n", + " this.root.appendChild(titlebar);\n", + " this.header = titletext;\n", + "};\n", + "\n", + "mpl.figure.prototype._canvas_extra_style = function (_canvas_div) {};\n", + "\n", + "mpl.figure.prototype._root_extra_style = function (_canvas_div) {};\n", + "\n", + "mpl.figure.prototype._init_canvas = function () {\n", + " var fig = this;\n", + "\n", + " var canvas_div = (this.canvas_div = document.createElement('div'));\n", + " canvas_div.setAttribute(\n", + " 'style',\n", + " 'border: 1px solid #ddd;' +\n", + " 'box-sizing: content-box;' +\n", + " 'clear: both;' +\n", + " 'min-height: 1px;' +\n", + " 'min-width: 1px;' +\n", + " 'outline: 0;' +\n", + " 'overflow: hidden;' +\n", + " 'position: relative;' +\n", + " 'resize: both;'\n", + " );\n", + "\n", + " function on_keyboard_event_closure(name) {\n", + " return function (event) {\n", + " return fig.key_event(event, name);\n", + " };\n", + " }\n", + "\n", + " canvas_div.addEventListener(\n", + " 'keydown',\n", + " on_keyboard_event_closure('key_press')\n", + " );\n", + " canvas_div.addEventListener(\n", + " 'keyup',\n", + " on_keyboard_event_closure('key_release')\n", + " );\n", + "\n", + " this._canvas_extra_style(canvas_div);\n", + " this.root.appendChild(canvas_div);\n", + "\n", + " var canvas = (this.canvas = document.createElement('canvas'));\n", + " canvas.classList.add('mpl-canvas');\n", + " canvas.setAttribute('style', 'box-sizing: content-box;');\n", + "\n", + " this.context = canvas.getContext('2d');\n", + "\n", + " var backingStore =\n", + " this.context.backingStorePixelRatio ||\n", + " this.context.webkitBackingStorePixelRatio ||\n", + " this.context.mozBackingStorePixelRatio ||\n", + " this.context.msBackingStorePixelRatio ||\n", + " this.context.oBackingStorePixelRatio ||\n", + " this.context.backingStorePixelRatio ||\n", + " 1;\n", + "\n", + " this.ratio = (window.devicePixelRatio || 1) / backingStore;\n", + "\n", + " var rubberband_canvas = (this.rubberband_canvas = document.createElement(\n", + " 'canvas'\n", + " ));\n", + " rubberband_canvas.setAttribute(\n", + " 'style',\n", + " 'box-sizing: content-box; position: absolute; left: 0; top: 0; z-index: 1;'\n", + " );\n", + "\n", + " // Apply a ponyfill if ResizeObserver is not implemented by browser.\n", + " if (this.ResizeObserver === undefined) {\n", + " if (window.ResizeObserver !== undefined) {\n", + " this.ResizeObserver = window.ResizeObserver;\n", + " } else {\n", + " var obs = _JSXTOOLS_RESIZE_OBSERVER({});\n", + " this.ResizeObserver = obs.ResizeObserver;\n", + " }\n", + " }\n", + "\n", + " this.resizeObserverInstance = new this.ResizeObserver(function (entries) {\n", + " var nentries = entries.length;\n", + " for (var i = 0; i < nentries; i++) {\n", + " var entry = entries[i];\n", + " var width, height;\n", + " if (entry.contentBoxSize) {\n", + " if (entry.contentBoxSize instanceof Array) {\n", + " // Chrome 84 implements new version of spec.\n", + " width = entry.contentBoxSize[0].inlineSize;\n", + " height = entry.contentBoxSize[0].blockSize;\n", + " } else {\n", + " // Firefox implements old version of spec.\n", + " width = entry.contentBoxSize.inlineSize;\n", + " height = entry.contentBoxSize.blockSize;\n", + " }\n", + " } else {\n", + " // Chrome <84 implements even older version of spec.\n", + " width = entry.contentRect.width;\n", + " height = entry.contentRect.height;\n", + " }\n", + "\n", + " // Keep the size of the canvas and rubber band canvas in sync with\n", + " // the canvas container.\n", + " if (entry.devicePixelContentBoxSize) {\n", + " // Chrome 84 implements new version of spec.\n", + " canvas.setAttribute(\n", + " 'width',\n", + " entry.devicePixelContentBoxSize[0].inlineSize\n", + " );\n", + " canvas.setAttribute(\n", + " 'height',\n", + " entry.devicePixelContentBoxSize[0].blockSize\n", + " );\n", + " } else {\n", + " canvas.setAttribute('width', width * fig.ratio);\n", + " canvas.setAttribute('height', height * fig.ratio);\n", + " }\n", + " canvas.setAttribute(\n", + " 'style',\n", + " 'width: ' + width + 'px; height: ' + height + 'px;'\n", + " );\n", + "\n", + " rubberband_canvas.setAttribute('width', width);\n", + " rubberband_canvas.setAttribute('height', height);\n", + "\n", + " // And update the size in Python. We ignore the initial 0/0 size\n", + " // that occurs as the element is placed into the DOM, which should\n", + " // otherwise not happen due to the minimum size styling.\n", + " if (fig.ws.readyState == 1 && width != 0 && height != 0) {\n", + " fig.request_resize(width, height);\n", + " }\n", + " }\n", + " });\n", + " this.resizeObserverInstance.observe(canvas_div);\n", + "\n", + " function on_mouse_event_closure(name) {\n", + " return function (event) {\n", + " return fig.mouse_event(event, name);\n", + " };\n", + " }\n", + "\n", + " rubberband_canvas.addEventListener(\n", + " 'mousedown',\n", + " on_mouse_event_closure('button_press')\n", + " );\n", + " rubberband_canvas.addEventListener(\n", + " 'mouseup',\n", + " on_mouse_event_closure('button_release')\n", + " );\n", + " // Throttle sequential mouse events to 1 every 20ms.\n", + " rubberband_canvas.addEventListener(\n", + " 'mousemove',\n", + " on_mouse_event_closure('motion_notify')\n", + " );\n", + "\n", + " rubberband_canvas.addEventListener(\n", + " 'mouseenter',\n", + " on_mouse_event_closure('figure_enter')\n", + " );\n", + " rubberband_canvas.addEventListener(\n", + " 'mouseleave',\n", + " on_mouse_event_closure('figure_leave')\n", + " );\n", + "\n", + " canvas_div.addEventListener('wheel', function (event) {\n", + " if (event.deltaY < 0) {\n", + " event.step = 1;\n", + " } else {\n", + " event.step = -1;\n", + " }\n", + " on_mouse_event_closure('scroll')(event);\n", + " });\n", + "\n", + " canvas_div.appendChild(canvas);\n", + " canvas_div.appendChild(rubberband_canvas);\n", + "\n", + " this.rubberband_context = rubberband_canvas.getContext('2d');\n", + " this.rubberband_context.strokeStyle = '#000000';\n", + "\n", + " this._resize_canvas = function (width, height, forward) {\n", + " if (forward) {\n", + " canvas_div.style.width = width + 'px';\n", + " canvas_div.style.height = height + 'px';\n", + " }\n", + " };\n", + "\n", + " // Disable right mouse context menu.\n", + " this.rubberband_canvas.addEventListener('contextmenu', function (_e) {\n", + " event.preventDefault();\n", + " return false;\n", + " });\n", + "\n", + " function set_focus() {\n", + " canvas.focus();\n", + " canvas_div.focus();\n", + " }\n", + "\n", + " window.setTimeout(set_focus, 100);\n", + "};\n", + "\n", + "mpl.figure.prototype._init_toolbar = function () {\n", + " var fig = this;\n", + "\n", + " var toolbar = document.createElement('div');\n", + " toolbar.classList = 'mpl-toolbar';\n", + " this.root.appendChild(toolbar);\n", + "\n", + " function on_click_closure(name) {\n", + " return function (_event) {\n", + " return fig.toolbar_button_onclick(name);\n", + " };\n", + " }\n", + "\n", + " function on_mouseover_closure(tooltip) {\n", + " return function (event) {\n", + " if (!event.currentTarget.disabled) {\n", + " return fig.toolbar_button_onmouseover(tooltip);\n", + " }\n", + " };\n", + " }\n", + "\n", + " fig.buttons = {};\n", + " var buttonGroup = document.createElement('div');\n", + " buttonGroup.classList = 'mpl-button-group';\n", + " for (var toolbar_ind in mpl.toolbar_items) {\n", + " var name = mpl.toolbar_items[toolbar_ind][0];\n", + " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n", + " var image = mpl.toolbar_items[toolbar_ind][2];\n", + " var method_name = mpl.toolbar_items[toolbar_ind][3];\n", + "\n", + " if (!name) {\n", + " /* Instead of a spacer, we start a new button group. */\n", + " if (buttonGroup.hasChildNodes()) {\n", + " toolbar.appendChild(buttonGroup);\n", + " }\n", + " buttonGroup = document.createElement('div');\n", + " buttonGroup.classList = 'mpl-button-group';\n", + " continue;\n", + " }\n", + "\n", + " var button = (fig.buttons[name] = document.createElement('button'));\n", + " button.classList = 'mpl-widget';\n", + " button.setAttribute('role', 'button');\n", + " button.setAttribute('aria-disabled', 'false');\n", + " button.addEventListener('click', on_click_closure(method_name));\n", + " button.addEventListener('mouseover', on_mouseover_closure(tooltip));\n", + "\n", + " var icon_img = document.createElement('img');\n", + " icon_img.src = '_images/' + image + '.png';\n", + " icon_img.srcset = '_images/' + image + '_large.png 2x';\n", + " icon_img.alt = tooltip;\n", + " button.appendChild(icon_img);\n", + "\n", + " buttonGroup.appendChild(button);\n", + " }\n", + "\n", + " if (buttonGroup.hasChildNodes()) {\n", + " toolbar.appendChild(buttonGroup);\n", + " }\n", + "\n", + " var fmt_picker = document.createElement('select');\n", + " fmt_picker.classList = 'mpl-widget';\n", + " toolbar.appendChild(fmt_picker);\n", + " this.format_dropdown = fmt_picker;\n", + "\n", + " for (var ind in mpl.extensions) {\n", + " var fmt = mpl.extensions[ind];\n", + " var option = document.createElement('option');\n", + " option.selected = fmt === mpl.default_extension;\n", + " option.innerHTML = fmt;\n", + " fmt_picker.appendChild(option);\n", + " }\n", + "\n", + " var status_bar = document.createElement('span');\n", + " status_bar.classList = 'mpl-message';\n", + " toolbar.appendChild(status_bar);\n", + " this.message = status_bar;\n", + "};\n", + "\n", + "mpl.figure.prototype.request_resize = function (x_pixels, y_pixels) {\n", + " // Request matplotlib to resize the figure. Matplotlib will then trigger a resize in the client,\n", + " // which will in turn request a refresh of the image.\n", + " this.send_message('resize', { width: x_pixels, height: y_pixels });\n", + "};\n", + "\n", + "mpl.figure.prototype.send_message = function (type, properties) {\n", + " properties['type'] = type;\n", + " properties['figure_id'] = this.id;\n", + " this.ws.send(JSON.stringify(properties));\n", + "};\n", + "\n", + "mpl.figure.prototype.send_draw_message = function () {\n", + " if (!this.waiting) {\n", + " this.waiting = true;\n", + " this.ws.send(JSON.stringify({ type: 'draw', figure_id: this.id }));\n", + " }\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_save = function (fig, _msg) {\n", + " var format_dropdown = fig.format_dropdown;\n", + " var format = format_dropdown.options[format_dropdown.selectedIndex].value;\n", + " fig.ondownload(fig, format);\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_resize = function (fig, msg) {\n", + " var size = msg['size'];\n", + " if (size[0] !== fig.canvas.width || size[1] !== fig.canvas.height) {\n", + " fig._resize_canvas(size[0], size[1], msg['forward']);\n", + " fig.send_message('refresh', {});\n", + " }\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_rubberband = function (fig, msg) {\n", + " var x0 = msg['x0'] / fig.ratio;\n", + " var y0 = (fig.canvas.height - msg['y0']) / fig.ratio;\n", + " var x1 = msg['x1'] / fig.ratio;\n", + " var y1 = (fig.canvas.height - msg['y1']) / fig.ratio;\n", + " x0 = Math.floor(x0) + 0.5;\n", + " y0 = Math.floor(y0) + 0.5;\n", + " x1 = Math.floor(x1) + 0.5;\n", + " y1 = Math.floor(y1) + 0.5;\n", + " var min_x = Math.min(x0, x1);\n", + " var min_y = Math.min(y0, y1);\n", + " var width = Math.abs(x1 - x0);\n", + " var height = Math.abs(y1 - y0);\n", + "\n", + " fig.rubberband_context.clearRect(\n", + " 0,\n", + " 0,\n", + " fig.canvas.width / fig.ratio,\n", + " fig.canvas.height / fig.ratio\n", + " );\n", + "\n", + " fig.rubberband_context.strokeRect(min_x, min_y, width, height);\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_figure_label = function (fig, msg) {\n", + " // Updates the figure title.\n", + " fig.header.textContent = msg['label'];\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_cursor = function (fig, msg) {\n", + " var cursor = msg['cursor'];\n", + " switch (cursor) {\n", + " case 0:\n", + " cursor = 'pointer';\n", + " break;\n", + " case 1:\n", + " cursor = 'default';\n", + " break;\n", + " case 2:\n", + " cursor = 'crosshair';\n", + " break;\n", + " case 3:\n", + " cursor = 'move';\n", + " break;\n", + " }\n", + " fig.rubberband_canvas.style.cursor = cursor;\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_message = function (fig, msg) {\n", + " fig.message.textContent = msg['message'];\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_draw = function (fig, _msg) {\n", + " // Request the server to send over a new figure.\n", + " fig.send_draw_message();\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_image_mode = function (fig, msg) {\n", + " fig.image_mode = msg['mode'];\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_history_buttons = function (fig, msg) {\n", + " for (var key in msg) {\n", + " if (!(key in fig.buttons)) {\n", + " continue;\n", + " }\n", + " fig.buttons[key].disabled = !msg[key];\n", + " fig.buttons[key].setAttribute('aria-disabled', !msg[key]);\n", + " }\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_navigate_mode = function (fig, msg) {\n", + " if (msg['mode'] === 'PAN') {\n", + " fig.buttons['Pan'].classList.add('active');\n", + " fig.buttons['Zoom'].classList.remove('active');\n", + " } else if (msg['mode'] === 'ZOOM') {\n", + " fig.buttons['Pan'].classList.remove('active');\n", + " fig.buttons['Zoom'].classList.add('active');\n", + " } else {\n", + " fig.buttons['Pan'].classList.remove('active');\n", + " fig.buttons['Zoom'].classList.remove('active');\n", + " }\n", + "};\n", + "\n", + "mpl.figure.prototype.updated_canvas_event = function () {\n", + " // Called whenever the canvas gets updated.\n", + " this.send_message('ack', {});\n", + "};\n", + "\n", + "// A function to construct a web socket function for onmessage handling.\n", + "// Called in the figure constructor.\n", + "mpl.figure.prototype._make_on_message_function = function (fig) {\n", + " return function socket_on_message(evt) {\n", + " if (evt.data instanceof Blob) {\n", + " /* FIXME: We get \"Resource interpreted as Image but\n", + " * transferred with MIME type text/plain:\" errors on\n", + " * Chrome. But how to set the MIME type? It doesn't seem\n", + " * to be part of the websocket stream */\n", + " evt.data.type = 'image/png';\n", + "\n", + " /* Free the memory for the previous frames */\n", + " if (fig.imageObj.src) {\n", + " (window.URL || window.webkitURL).revokeObjectURL(\n", + " fig.imageObj.src\n", + " );\n", + " }\n", + "\n", + " fig.imageObj.src = (window.URL || window.webkitURL).createObjectURL(\n", + " evt.data\n", + " );\n", + " fig.updated_canvas_event();\n", + " fig.waiting = false;\n", + " return;\n", + " } else if (\n", + " typeof evt.data === 'string' &&\n", + " evt.data.slice(0, 21) === 'data:image/png;base64'\n", + " ) {\n", + " fig.imageObj.src = evt.data;\n", + " fig.updated_canvas_event();\n", + " fig.waiting = false;\n", + " return;\n", + " }\n", + "\n", + " var msg = JSON.parse(evt.data);\n", + " var msg_type = msg['type'];\n", + "\n", + " // Call the \"handle_{type}\" callback, which takes\n", + " // the figure and JSON message as its only arguments.\n", + " try {\n", + " var callback = fig['handle_' + msg_type];\n", + " } catch (e) {\n", + " console.log(\n", + " \"No handler for the '\" + msg_type + \"' message type: \",\n", + " msg\n", + " );\n", + " return;\n", + " }\n", + "\n", + " if (callback) {\n", + " try {\n", + " // console.log(\"Handling '\" + msg_type + \"' message: \", msg);\n", + " callback(fig, msg);\n", + " } catch (e) {\n", + " console.log(\n", + " \"Exception inside the 'handler_\" + msg_type + \"' callback:\",\n", + " e,\n", + " e.stack,\n", + " msg\n", + " );\n", + " }\n", + " }\n", + " };\n", + "};\n", + "\n", + "// from http://stackoverflow.com/questions/1114465/getting-mouse-location-in-canvas\n", + "mpl.findpos = function (e) {\n", + " //this section is from http://www.quirksmode.org/js/events_properties.html\n", + " var targ;\n", + " if (!e) {\n", + " e = window.event;\n", + " }\n", + " if (e.target) {\n", + " targ = e.target;\n", + " } else if (e.srcElement) {\n", + " targ = e.srcElement;\n", + " }\n", + " if (targ.nodeType === 3) {\n", + " // defeat Safari bug\n", + " targ = targ.parentNode;\n", + " }\n", + "\n", + " // pageX,Y are the mouse positions relative to the document\n", + " var boundingRect = targ.getBoundingClientRect();\n", + " var x = e.pageX - (boundingRect.left + document.body.scrollLeft);\n", + " var y = e.pageY - (boundingRect.top + document.body.scrollTop);\n", + "\n", + " return { x: x, y: y };\n", + "};\n", + "\n", + "/*\n", + " * return a copy of an object with only non-object keys\n", + " * we need this to avoid circular references\n", + " * http://stackoverflow.com/a/24161582/3208463\n", + " */\n", + "function simpleKeys(original) {\n", + " return Object.keys(original).reduce(function (obj, key) {\n", + " if (typeof original[key] !== 'object') {\n", + " obj[key] = original[key];\n", + " }\n", + " return obj;\n", + " }, {});\n", + "}\n", + "\n", + "mpl.figure.prototype.mouse_event = function (event, name) {\n", + " var canvas_pos = mpl.findpos(event);\n", + "\n", + " if (name === 'button_press') {\n", + " this.canvas.focus();\n", + " this.canvas_div.focus();\n", + " }\n", + "\n", + " var x = canvas_pos.x * this.ratio;\n", + " var y = canvas_pos.y * this.ratio;\n", + "\n", + " this.send_message(name, {\n", + " x: x,\n", + " y: y,\n", + " button: event.button,\n", + " step: event.step,\n", + " guiEvent: simpleKeys(event),\n", + " });\n", + "\n", + " /* This prevents the web browser from automatically changing to\n", + " * the text insertion cursor when the button is pressed. We want\n", + " * to control all of the cursor setting manually through the\n", + " * 'cursor' event from matplotlib */\n", + " event.preventDefault();\n", + " return false;\n", + "};\n", + "\n", + "mpl.figure.prototype._key_event_extra = function (_event, _name) {\n", + " // Handle any extra behaviour associated with a key event\n", + "};\n", + "\n", + "mpl.figure.prototype.key_event = function (event, name) {\n", + " // Prevent repeat events\n", + " if (name === 'key_press') {\n", + " if (event.which === this._key) {\n", + " return;\n", + " } else {\n", + " this._key = event.which;\n", + " }\n", + " }\n", + " if (name === 'key_release') {\n", + " this._key = null;\n", + " }\n", + "\n", + " var value = '';\n", + " if (event.ctrlKey && event.which !== 17) {\n", + " value += 'ctrl+';\n", + " }\n", + " if (event.altKey && event.which !== 18) {\n", + " value += 'alt+';\n", + " }\n", + " if (event.shiftKey && event.which !== 16) {\n", + " value += 'shift+';\n", + " }\n", + "\n", + " value += 'k';\n", + " value += event.which.toString();\n", + "\n", + " this._key_event_extra(event, name);\n", + "\n", + " this.send_message(name, { key: value, guiEvent: simpleKeys(event) });\n", + " return false;\n", + "};\n", + "\n", + "mpl.figure.prototype.toolbar_button_onclick = function (name) {\n", + " if (name === 'download') {\n", + " this.handle_save(this, null);\n", + " } else {\n", + " this.send_message('toolbar_button', { name: name });\n", + " }\n", + "};\n", + "\n", + "mpl.figure.prototype.toolbar_button_onmouseover = function (tooltip) {\n", + " this.message.textContent = tooltip;\n", + "};\n", + "\n", + "///////////////// REMAINING CONTENT GENERATED BY embed_js.py /////////////////\n", + "// prettier-ignore\n", + "var _JSXTOOLS_RESIZE_OBSERVER=function(A){var t,i=new WeakMap,n=new WeakMap,a=new WeakMap,r=new WeakMap,o=new Set;function s(e){if(!(this instanceof s))throw new TypeError(\"Constructor requires 'new' operator\");i.set(this,e)}function h(){throw new TypeError(\"Function is not a constructor\")}function c(e,t,i,n){e=0 in arguments?Number(arguments[0]):0,t=1 in arguments?Number(arguments[1]):0,i=2 in arguments?Number(arguments[2]):0,n=3 in arguments?Number(arguments[3]):0,this.right=(this.x=this.left=e)+(this.width=i),this.bottom=(this.y=this.top=t)+(this.height=n),Object.freeze(this)}function d(){t=requestAnimationFrame(d);var s=new WeakMap,p=new Set;o.forEach((function(t){r.get(t).forEach((function(i){var r=t instanceof window.SVGElement,o=a.get(t),d=r?0:parseFloat(o.paddingTop),f=r?0:parseFloat(o.paddingRight),l=r?0:parseFloat(o.paddingBottom),u=r?0:parseFloat(o.paddingLeft),g=r?0:parseFloat(o.borderTopWidth),m=r?0:parseFloat(o.borderRightWidth),w=r?0:parseFloat(o.borderBottomWidth),b=u+f,F=d+l,v=(r?0:parseFloat(o.borderLeftWidth))+m,W=g+w,y=r?0:t.offsetHeight-W-t.clientHeight,E=r?0:t.offsetWidth-v-t.clientWidth,R=b+v,z=F+W,M=r?t.width:parseFloat(o.width)-R-E,O=r?t.height:parseFloat(o.height)-z-y;if(n.has(t)){var k=n.get(t);if(k[0]===M&&k[1]===O)return}n.set(t,[M,O]);var S=Object.create(h.prototype);S.target=t,S.contentRect=new c(u,d,M,O),s.has(i)||(s.set(i,[]),p.add(i)),s.get(i).push(S)}))})),p.forEach((function(e){i.get(e).call(e,s.get(e),e)}))}return s.prototype.observe=function(i){if(i instanceof window.Element){r.has(i)||(r.set(i,new Set),o.add(i),a.set(i,window.getComputedStyle(i)));var n=r.get(i);n.has(this)||n.add(this),cancelAnimationFrame(t),t=requestAnimationFrame(d)}},s.prototype.unobserve=function(i){if(i instanceof window.Element&&r.has(i)){var n=r.get(i);n.has(this)&&(n.delete(this),n.size||(r.delete(i),o.delete(i))),n.size||r.delete(i),o.size||cancelAnimationFrame(t)}},A.DOMRectReadOnly=c,A.ResizeObserver=s,A.ResizeObserverEntry=h,A}; // eslint-disable-line\n", + "mpl.toolbar_items = [[\"Home\", \"Reset original view\", \"fa fa-home icon-home\", \"home\"], [\"Back\", \"Back to previous view\", \"fa fa-arrow-left icon-arrow-left\", \"back\"], [\"Forward\", \"Forward to next view\", \"fa fa-arrow-right icon-arrow-right\", \"forward\"], [\"\", \"\", \"\", \"\"], [\"Pan\", \"Left button pans, Right button zooms\\nx/y fixes axis, CTRL fixes aspect\", \"fa fa-arrows icon-move\", \"pan\"], [\"Zoom\", \"Zoom to rectangle\\nx/y fixes axis, CTRL fixes aspect\", \"fa fa-square-o icon-check-empty\", \"zoom\"], [\"\", \"\", \"\", \"\"], [\"Download\", \"Download plot\", \"fa fa-floppy-o icon-save\", \"download\"]];\n", + "\n", + "mpl.extensions = [\"eps\", \"jpeg\", \"pdf\", \"png\", \"ps\", \"raw\", \"svg\", \"tif\"];\n", + "\n", + "mpl.default_extension = \"png\";/* global mpl */\n", + "\n", + "var comm_websocket_adapter = function (comm) {\n", + " // Create a \"websocket\"-like object which calls the given IPython comm\n", + " // object with the appropriate methods. Currently this is a non binary\n", + " // socket, so there is still some room for performance tuning.\n", + " var ws = {};\n", + "\n", + " ws.close = function () {\n", + " comm.close();\n", + " };\n", + " ws.send = function (m) {\n", + " //console.log('sending', m);\n", + " comm.send(m);\n", + " };\n", + " // Register the callback with on_msg.\n", + " comm.on_msg(function (msg) {\n", + " //console.log('receiving', msg['content']['data'], msg);\n", + " // Pass the mpl event to the overridden (by mpl) onmessage function.\n", + " ws.onmessage(msg['content']['data']);\n", + " });\n", + " return ws;\n", + "};\n", + "\n", + "mpl.mpl_figure_comm = function (comm, msg) {\n", + " // This is the function which gets called when the mpl process\n", + " // starts-up an IPython Comm through the \"matplotlib\" channel.\n", + "\n", + " var id = msg.content.data.id;\n", + " // Get hold of the div created by the display call when the Comm\n", + " // socket was opened in Python.\n", + " var element = document.getElementById(id);\n", + " var ws_proxy = comm_websocket_adapter(comm);\n", + "\n", + " function ondownload(figure, _format) {\n", + " window.open(figure.canvas.toDataURL());\n", + " }\n", + "\n", + " var fig = new mpl.figure(id, ws_proxy, ondownload, element);\n", + "\n", + " // Call onopen now - mpl needs it, as it is assuming we've passed it a real\n", + " // web socket which is closed, not our websocket->open comm proxy.\n", + " ws_proxy.onopen();\n", + "\n", + " fig.parent_element = element;\n", + " fig.cell_info = mpl.find_output_cell(\"
\");\n", + " if (!fig.cell_info) {\n", + " console.error('Failed to find cell for figure', id, fig);\n", + " return;\n", + " }\n", + " fig.cell_info[0].output_area.element.on(\n", + " 'cleared',\n", + " { fig: fig },\n", + " fig._remove_fig_handler\n", + " );\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_close = function (fig, msg) {\n", + " var width = fig.canvas.width / fig.ratio;\n", + " fig.cell_info[0].output_area.element.off(\n", + " 'cleared',\n", + " fig._remove_fig_handler\n", + " );\n", + " fig.resizeObserverInstance.unobserve(fig.canvas_div);\n", + "\n", + " // Update the output cell to use the data from the current canvas.\n", + " fig.push_to_output();\n", + " var dataURL = fig.canvas.toDataURL();\n", + " // Re-enable the keyboard manager in IPython - without this line, in FF,\n", + " // the notebook keyboard shortcuts fail.\n", + " IPython.keyboard_manager.enable();\n", + " fig.parent_element.innerHTML =\n", + " '';\n", + " fig.close_ws(fig, msg);\n", + "};\n", + "\n", + "mpl.figure.prototype.close_ws = function (fig, msg) {\n", + " fig.send_message('closing', msg);\n", + " // fig.ws.close()\n", + "};\n", + "\n", + "mpl.figure.prototype.push_to_output = function (_remove_interactive) {\n", + " // Turn the data on the canvas into data in the output cell.\n", + " var width = this.canvas.width / this.ratio;\n", + " var dataURL = this.canvas.toDataURL();\n", + " this.cell_info[1]['text/html'] =\n", + " '';\n", + "};\n", + "\n", + "mpl.figure.prototype.updated_canvas_event = function () {\n", + " // Tell IPython that the notebook contents must change.\n", + " IPython.notebook.set_dirty(true);\n", + " this.send_message('ack', {});\n", + " var fig = this;\n", + " // Wait a second, then push the new image to the DOM so\n", + " // that it is saved nicely (might be nice to debounce this).\n", + " setTimeout(function () {\n", + " fig.push_to_output();\n", + " }, 1000);\n", + "};\n", + "\n", + "mpl.figure.prototype._init_toolbar = function () {\n", + " var fig = this;\n", + "\n", + " var toolbar = document.createElement('div');\n", + " toolbar.classList = 'btn-toolbar';\n", + " this.root.appendChild(toolbar);\n", + "\n", + " function on_click_closure(name) {\n", + " return function (_event) {\n", + " return fig.toolbar_button_onclick(name);\n", + " };\n", + " }\n", + "\n", + " function on_mouseover_closure(tooltip) {\n", + " return function (event) {\n", + " if (!event.currentTarget.disabled) {\n", + " return fig.toolbar_button_onmouseover(tooltip);\n", + " }\n", + " };\n", + " }\n", + "\n", + " fig.buttons = {};\n", + " var buttonGroup = document.createElement('div');\n", + " buttonGroup.classList = 'btn-group';\n", + " var button;\n", + " for (var toolbar_ind in mpl.toolbar_items) {\n", + " var name = mpl.toolbar_items[toolbar_ind][0];\n", + " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n", + " var image = mpl.toolbar_items[toolbar_ind][2];\n", + " var method_name = mpl.toolbar_items[toolbar_ind][3];\n", + "\n", + " if (!name) {\n", + " /* Instead of a spacer, we start a new button group. */\n", + " if (buttonGroup.hasChildNodes()) {\n", + " toolbar.appendChild(buttonGroup);\n", + " }\n", + " buttonGroup = document.createElement('div');\n", + " buttonGroup.classList = 'btn-group';\n", + " continue;\n", + " }\n", + "\n", + " button = fig.buttons[name] = document.createElement('button');\n", + " button.classList = 'btn btn-default';\n", + " button.href = '#';\n", + " button.title = name;\n", + " button.innerHTML = '';\n", + " button.addEventListener('click', on_click_closure(method_name));\n", + " button.addEventListener('mouseover', on_mouseover_closure(tooltip));\n", + " buttonGroup.appendChild(button);\n", + " }\n", + "\n", + " if (buttonGroup.hasChildNodes()) {\n", + " toolbar.appendChild(buttonGroup);\n", + " }\n", + "\n", + " // Add the status bar.\n", + " var status_bar = document.createElement('span');\n", + " status_bar.classList = 'mpl-message pull-right';\n", + " toolbar.appendChild(status_bar);\n", + " this.message = status_bar;\n", + "\n", + " // Add the close button to the window.\n", + " var buttongrp = document.createElement('div');\n", + " buttongrp.classList = 'btn-group inline pull-right';\n", + " button = document.createElement('button');\n", + " button.classList = 'btn btn-mini btn-primary';\n", + " button.href = '#';\n", + " button.title = 'Stop Interaction';\n", + " button.innerHTML = '';\n", + " button.addEventListener('click', function (_evt) {\n", + " fig.handle_close(fig, {});\n", + " });\n", + " button.addEventListener(\n", + " 'mouseover',\n", + " on_mouseover_closure('Stop Interaction')\n", + " );\n", + " buttongrp.appendChild(button);\n", + " var titlebar = this.root.querySelector('.ui-dialog-titlebar');\n", + " titlebar.insertBefore(buttongrp, titlebar.firstChild);\n", + "};\n", + "\n", + "mpl.figure.prototype._remove_fig_handler = function (event) {\n", + " var fig = event.data.fig;\n", + " if (event.target !== this) {\n", + " // Ignore bubbled events from children.\n", + " return;\n", + " }\n", + " fig.close_ws(fig, {});\n", + "};\n", + "\n", + "mpl.figure.prototype._root_extra_style = function (el) {\n", + " el.style.boxSizing = 'content-box'; // override notebook setting of border-box.\n", + "};\n", + "\n", + "mpl.figure.prototype._canvas_extra_style = function (el) {\n", + " // this is important to make the div 'focusable\n", + " el.setAttribute('tabindex', 0);\n", + " // reach out to IPython and tell the keyboard manager to turn it's self\n", + " // off when our div gets focus\n", + "\n", + " // location in version 3\n", + " if (IPython.notebook.keyboard_manager) {\n", + " IPython.notebook.keyboard_manager.register_events(el);\n", + " } else {\n", + " // location in version 2\n", + " IPython.keyboard_manager.register_events(el);\n", + " }\n", + "};\n", + "\n", + "mpl.figure.prototype._key_event_extra = function (event, _name) {\n", + " var manager = IPython.notebook.keyboard_manager;\n", + " if (!manager) {\n", + " manager = IPython.keyboard_manager;\n", + " }\n", + "\n", + " // Check for shift+enter\n", + " if (event.shiftKey && event.which === 13) {\n", + " this.canvas_div.blur();\n", + " // select the cell after this one\n", + " var index = IPython.notebook.find_cell_index(this.cell_info[0]);\n", + " IPython.notebook.select(index + 1);\n", + " }\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_save = function (fig, _msg) {\n", + " fig.ondownload(fig, null);\n", + "};\n", + "\n", + "mpl.find_output_cell = function (html_output) {\n", + " // Return the cell and output element which can be found *uniquely* in the notebook.\n", + " // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n", + " // IPython event is triggered only after the cells have been serialised, which for\n", + " // our purposes (turning an active figure into a static one), is too late.\n", + " var cells = IPython.notebook.get_cells();\n", + " var ncells = cells.length;\n", + " for (var i = 0; i < ncells; i++) {\n", + " var cell = cells[i];\n", + " if (cell.cell_type === 'code') {\n", + " for (var j = 0; j < cell.output_area.outputs.length; j++) {\n", + " var data = cell.output_area.outputs[j];\n", + " if (data.data) {\n", + " // IPython >= 3 moved mimebundle to data attribute of output\n", + " data = data.data;\n", + " }\n", + " if (data['text/html'] === html_output) {\n", + " return [cell, data, j];\n", + " }\n", + " }\n", + " }\n", + " }\n", + "};\n", + "\n", + "// Register the function which deals with the matplotlib target/channel.\n", + "// The kernel may be null if the page has been refreshed.\n", + "if (IPython.notebook.kernel !== null) {\n", + " IPython.notebook.kernel.comm_manager.register_target(\n", + " 'matplotlib',\n", + " mpl.mpl_figure_comm\n", + " );\n", + "}\n" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "%matplotlib notebook\n", + "import matplotlib.pyplot as plt\n", + "\n", + "plt.figure()\n", + "plt.plot(cap_pass_trace(\"h\\n\"))\n", + "plt.plot(cap_pass_trace(\"0\\n\"))\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "If you are using the `%matplotlib notebook` magic, you can zoom in at the start. What you want to notice is there is two code paths taken, depending on a correct or incorrect path. Here for example is a correct & incorrect character processed (note that your trace will look different, the examples are taken from another target architecture):\n", + "\"SPA" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "OK interesting -- what's next? Let's plot every possible password character we could send.\n", + "\n", + "Our password implementation only recognizes characters in the list `abcdefghijklmnopqrstuvwxyz0123456789`, so we're going to limit it to those valid characters for now.\n", + "\n", + "You also may notice the traces are way too long - you might want to make a more narrow plot that only does the first say 100 samples of the power trace.\n", + "\n", + "
\n", + "

Plotting Note\n", + "If using `matplotlib` for plotting, you might need to add a `plt.figure()` at the start to make a new figure. Otherwise you might find your plot ends up in the figure above! If you don't see the plots, sometimes a `plt.show()` is needed at the end.\n", + "

" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "application/javascript": [ + "/* Put everything inside the global mpl namespace */\n", + "/* global mpl */\n", + "window.mpl = {};\n", + "\n", + "mpl.get_websocket_type = function () {\n", + " if (typeof WebSocket !== 'undefined') {\n", + " return WebSocket;\n", + " } else if (typeof MozWebSocket !== 'undefined') {\n", + " return MozWebSocket;\n", + " } else {\n", + " alert(\n", + " 'Your browser does not have WebSocket support. ' +\n", + " 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n", + " 'Firefox 4 and 5 are also supported but you ' +\n", + " 'have to enable WebSockets in about:config.'\n", + " );\n", + " }\n", + "};\n", + "\n", + "mpl.figure = function (figure_id, websocket, ondownload, parent_element) {\n", + " this.id = figure_id;\n", + "\n", + " this.ws = websocket;\n", + "\n", + " this.supports_binary = this.ws.binaryType !== undefined;\n", + "\n", + " if (!this.supports_binary) {\n", + " var warnings = document.getElementById('mpl-warnings');\n", + " if (warnings) {\n", + " warnings.style.display = 'block';\n", + " warnings.textContent =\n", + " 'This browser does not support binary websocket messages. ' +\n", + " 'Performance may be slow.';\n", + " }\n", + " }\n", + "\n", + " this.imageObj = new Image();\n", + "\n", + " this.context = undefined;\n", + " this.message = undefined;\n", + " this.canvas = undefined;\n", + " this.rubberband_canvas = undefined;\n", + " this.rubberband_context = undefined;\n", + " this.format_dropdown = undefined;\n", + "\n", + " this.image_mode = 'full';\n", + "\n", + " this.root = document.createElement('div');\n", + " this.root.setAttribute('style', 'display: inline-block');\n", + " this._root_extra_style(this.root);\n", + "\n", + " parent_element.appendChild(this.root);\n", + "\n", + " this._init_header(this);\n", + " this._init_canvas(this);\n", + " this._init_toolbar(this);\n", + "\n", + " var fig = this;\n", + "\n", + " this.waiting = false;\n", + "\n", + " this.ws.onopen = function () {\n", + " fig.send_message('supports_binary', { value: fig.supports_binary });\n", + " fig.send_message('send_image_mode', {});\n", + " if (fig.ratio !== 1) {\n", + " fig.send_message('set_dpi_ratio', { dpi_ratio: fig.ratio });\n", + " }\n", + " fig.send_message('refresh', {});\n", + " };\n", + "\n", + " this.imageObj.onload = function () {\n", + " if (fig.image_mode === 'full') {\n", + " // Full images could contain transparency (where diff images\n", + " // almost always do), so we need to clear the canvas so that\n", + " // there is no ghosting.\n", + " fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n", + " }\n", + " fig.context.drawImage(fig.imageObj, 0, 0);\n", + " };\n", + "\n", + " this.imageObj.onunload = function () {\n", + " fig.ws.close();\n", + " };\n", + "\n", + " this.ws.onmessage = this._make_on_message_function(this);\n", + "\n", + " this.ondownload = ondownload;\n", + "};\n", + "\n", + "mpl.figure.prototype._init_header = function () {\n", + " var titlebar = document.createElement('div');\n", + " titlebar.classList =\n", + " 'ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix';\n", + " var titletext = document.createElement('div');\n", + " titletext.classList = 'ui-dialog-title';\n", + " titletext.setAttribute(\n", + " 'style',\n", + " 'width: 100%; text-align: center; padding: 3px;'\n", + " );\n", + " titlebar.appendChild(titletext);\n", + " this.root.appendChild(titlebar);\n", + " this.header = titletext;\n", + "};\n", + "\n", + "mpl.figure.prototype._canvas_extra_style = function (_canvas_div) {};\n", + "\n", + "mpl.figure.prototype._root_extra_style = function (_canvas_div) {};\n", + "\n", + "mpl.figure.prototype._init_canvas = function () {\n", + " var fig = this;\n", + "\n", + " var canvas_div = (this.canvas_div = document.createElement('div'));\n", + " canvas_div.setAttribute(\n", + " 'style',\n", + " 'border: 1px solid #ddd;' +\n", + " 'box-sizing: content-box;' +\n", + " 'clear: both;' +\n", + " 'min-height: 1px;' +\n", + " 'min-width: 1px;' +\n", + " 'outline: 0;' +\n", + " 'overflow: hidden;' +\n", + " 'position: relative;' +\n", + " 'resize: both;'\n", + " );\n", + "\n", + " function on_keyboard_event_closure(name) {\n", + " return function (event) {\n", + " return fig.key_event(event, name);\n", + " };\n", + " }\n", + "\n", + " canvas_div.addEventListener(\n", + " 'keydown',\n", + " on_keyboard_event_closure('key_press')\n", + " );\n", + " canvas_div.addEventListener(\n", + " 'keyup',\n", + " on_keyboard_event_closure('key_release')\n", + " );\n", + "\n", + " this._canvas_extra_style(canvas_div);\n", + " this.root.appendChild(canvas_div);\n", + "\n", + " var canvas = (this.canvas = document.createElement('canvas'));\n", + " canvas.classList.add('mpl-canvas');\n", + " canvas.setAttribute('style', 'box-sizing: content-box;');\n", + "\n", + " this.context = canvas.getContext('2d');\n", + "\n", + " var backingStore =\n", + " this.context.backingStorePixelRatio ||\n", + " this.context.webkitBackingStorePixelRatio ||\n", + " this.context.mozBackingStorePixelRatio ||\n", + " this.context.msBackingStorePixelRatio ||\n", + " this.context.oBackingStorePixelRatio ||\n", + " this.context.backingStorePixelRatio ||\n", + " 1;\n", + "\n", + " this.ratio = (window.devicePixelRatio || 1) / backingStore;\n", + "\n", + " var rubberband_canvas = (this.rubberband_canvas = document.createElement(\n", + " 'canvas'\n", + " ));\n", + " rubberband_canvas.setAttribute(\n", + " 'style',\n", + " 'box-sizing: content-box; position: absolute; left: 0; top: 0; z-index: 1;'\n", + " );\n", + "\n", + " // Apply a ponyfill if ResizeObserver is not implemented by browser.\n", + " if (this.ResizeObserver === undefined) {\n", + " if (window.ResizeObserver !== undefined) {\n", + " this.ResizeObserver = window.ResizeObserver;\n", + " } else {\n", + " var obs = _JSXTOOLS_RESIZE_OBSERVER({});\n", + " this.ResizeObserver = obs.ResizeObserver;\n", + " }\n", + " }\n", + "\n", + " this.resizeObserverInstance = new this.ResizeObserver(function (entries) {\n", + " var nentries = entries.length;\n", + " for (var i = 0; i < nentries; i++) {\n", + " var entry = entries[i];\n", + " var width, height;\n", + " if (entry.contentBoxSize) {\n", + " if (entry.contentBoxSize instanceof Array) {\n", + " // Chrome 84 implements new version of spec.\n", + " width = entry.contentBoxSize[0].inlineSize;\n", + " height = entry.contentBoxSize[0].blockSize;\n", + " } else {\n", + " // Firefox implements old version of spec.\n", + " width = entry.contentBoxSize.inlineSize;\n", + " height = entry.contentBoxSize.blockSize;\n", + " }\n", + " } else {\n", + " // Chrome <84 implements even older version of spec.\n", + " width = entry.contentRect.width;\n", + " height = entry.contentRect.height;\n", + " }\n", + "\n", + " // Keep the size of the canvas and rubber band canvas in sync with\n", + " // the canvas container.\n", + " if (entry.devicePixelContentBoxSize) {\n", + " // Chrome 84 implements new version of spec.\n", + " canvas.setAttribute(\n", + " 'width',\n", + " entry.devicePixelContentBoxSize[0].inlineSize\n", + " );\n", + " canvas.setAttribute(\n", + " 'height',\n", + " entry.devicePixelContentBoxSize[0].blockSize\n", + " );\n", + " } else {\n", + " canvas.setAttribute('width', width * fig.ratio);\n", + " canvas.setAttribute('height', height * fig.ratio);\n", + " }\n", + " canvas.setAttribute(\n", + " 'style',\n", + " 'width: ' + width + 'px; height: ' + height + 'px;'\n", + " );\n", + "\n", + " rubberband_canvas.setAttribute('width', width);\n", + " rubberband_canvas.setAttribute('height', height);\n", + "\n", + " // And update the size in Python. We ignore the initial 0/0 size\n", + " // that occurs as the element is placed into the DOM, which should\n", + " // otherwise not happen due to the minimum size styling.\n", + " if (fig.ws.readyState == 1 && width != 0 && height != 0) {\n", + " fig.request_resize(width, height);\n", + " }\n", + " }\n", + " });\n", + " this.resizeObserverInstance.observe(canvas_div);\n", + "\n", + " function on_mouse_event_closure(name) {\n", + " return function (event) {\n", + " return fig.mouse_event(event, name);\n", + " };\n", + " }\n", + "\n", + " rubberband_canvas.addEventListener(\n", + " 'mousedown',\n", + " on_mouse_event_closure('button_press')\n", + " );\n", + " rubberband_canvas.addEventListener(\n", + " 'mouseup',\n", + " on_mouse_event_closure('button_release')\n", + " );\n", + " // Throttle sequential mouse events to 1 every 20ms.\n", + " rubberband_canvas.addEventListener(\n", + " 'mousemove',\n", + " on_mouse_event_closure('motion_notify')\n", + " );\n", + "\n", + " rubberband_canvas.addEventListener(\n", + " 'mouseenter',\n", + " on_mouse_event_closure('figure_enter')\n", + " );\n", + " rubberband_canvas.addEventListener(\n", + " 'mouseleave',\n", + " on_mouse_event_closure('figure_leave')\n", + " );\n", + "\n", + " canvas_div.addEventListener('wheel', function (event) {\n", + " if (event.deltaY < 0) {\n", + " event.step = 1;\n", + " } else {\n", + " event.step = -1;\n", + " }\n", + " on_mouse_event_closure('scroll')(event);\n", + " });\n", + "\n", + " canvas_div.appendChild(canvas);\n", + " canvas_div.appendChild(rubberband_canvas);\n", + "\n", + " this.rubberband_context = rubberband_canvas.getContext('2d');\n", + " this.rubberband_context.strokeStyle = '#000000';\n", + "\n", + " this._resize_canvas = function (width, height, forward) {\n", + " if (forward) {\n", + " canvas_div.style.width = width + 'px';\n", + " canvas_div.style.height = height + 'px';\n", + " }\n", + " };\n", + "\n", + " // Disable right mouse context menu.\n", + " this.rubberband_canvas.addEventListener('contextmenu', function (_e) {\n", + " event.preventDefault();\n", + " return false;\n", + " });\n", + "\n", + " function set_focus() {\n", + " canvas.focus();\n", + " canvas_div.focus();\n", + " }\n", + "\n", + " window.setTimeout(set_focus, 100);\n", + "};\n", + "\n", + "mpl.figure.prototype._init_toolbar = function () {\n", + " var fig = this;\n", + "\n", + " var toolbar = document.createElement('div');\n", + " toolbar.classList = 'mpl-toolbar';\n", + " this.root.appendChild(toolbar);\n", + "\n", + " function on_click_closure(name) {\n", + " return function (_event) {\n", + " return fig.toolbar_button_onclick(name);\n", + " };\n", + " }\n", + "\n", + " function on_mouseover_closure(tooltip) {\n", + " return function (event) {\n", + " if (!event.currentTarget.disabled) {\n", + " return fig.toolbar_button_onmouseover(tooltip);\n", + " }\n", + " };\n", + " }\n", + "\n", + " fig.buttons = {};\n", + " var buttonGroup = document.createElement('div');\n", + " buttonGroup.classList = 'mpl-button-group';\n", + " for (var toolbar_ind in mpl.toolbar_items) {\n", + " var name = mpl.toolbar_items[toolbar_ind][0];\n", + " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n", + " var image = mpl.toolbar_items[toolbar_ind][2];\n", + " var method_name = mpl.toolbar_items[toolbar_ind][3];\n", + "\n", + " if (!name) {\n", + " /* Instead of a spacer, we start a new button group. */\n", + " if (buttonGroup.hasChildNodes()) {\n", + " toolbar.appendChild(buttonGroup);\n", + " }\n", + " buttonGroup = document.createElement('div');\n", + " buttonGroup.classList = 'mpl-button-group';\n", + " continue;\n", + " }\n", + "\n", + " var button = (fig.buttons[name] = document.createElement('button'));\n", + " button.classList = 'mpl-widget';\n", + " button.setAttribute('role', 'button');\n", + " button.setAttribute('aria-disabled', 'false');\n", + " button.addEventListener('click', on_click_closure(method_name));\n", + " button.addEventListener('mouseover', on_mouseover_closure(tooltip));\n", + "\n", + " var icon_img = document.createElement('img');\n", + " icon_img.src = '_images/' + image + '.png';\n", + " icon_img.srcset = '_images/' + image + '_large.png 2x';\n", + " icon_img.alt = tooltip;\n", + " button.appendChild(icon_img);\n", + "\n", + " buttonGroup.appendChild(button);\n", + " }\n", + "\n", + " if (buttonGroup.hasChildNodes()) {\n", + " toolbar.appendChild(buttonGroup);\n", + " }\n", + "\n", + " var fmt_picker = document.createElement('select');\n", + " fmt_picker.classList = 'mpl-widget';\n", + " toolbar.appendChild(fmt_picker);\n", + " this.format_dropdown = fmt_picker;\n", + "\n", + " for (var ind in mpl.extensions) {\n", + " var fmt = mpl.extensions[ind];\n", + " var option = document.createElement('option');\n", + " option.selected = fmt === mpl.default_extension;\n", + " option.innerHTML = fmt;\n", + " fmt_picker.appendChild(option);\n", + " }\n", + "\n", + " var status_bar = document.createElement('span');\n", + " status_bar.classList = 'mpl-message';\n", + " toolbar.appendChild(status_bar);\n", + " this.message = status_bar;\n", + "};\n", + "\n", + "mpl.figure.prototype.request_resize = function (x_pixels, y_pixels) {\n", + " // Request matplotlib to resize the figure. Matplotlib will then trigger a resize in the client,\n", + " // which will in turn request a refresh of the image.\n", + " this.send_message('resize', { width: x_pixels, height: y_pixels });\n", + "};\n", + "\n", + "mpl.figure.prototype.send_message = function (type, properties) {\n", + " properties['type'] = type;\n", + " properties['figure_id'] = this.id;\n", + " this.ws.send(JSON.stringify(properties));\n", + "};\n", + "\n", + "mpl.figure.prototype.send_draw_message = function () {\n", + " if (!this.waiting) {\n", + " this.waiting = true;\n", + " this.ws.send(JSON.stringify({ type: 'draw', figure_id: this.id }));\n", + " }\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_save = function (fig, _msg) {\n", + " var format_dropdown = fig.format_dropdown;\n", + " var format = format_dropdown.options[format_dropdown.selectedIndex].value;\n", + " fig.ondownload(fig, format);\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_resize = function (fig, msg) {\n", + " var size = msg['size'];\n", + " if (size[0] !== fig.canvas.width || size[1] !== fig.canvas.height) {\n", + " fig._resize_canvas(size[0], size[1], msg['forward']);\n", + " fig.send_message('refresh', {});\n", + " }\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_rubberband = function (fig, msg) {\n", + " var x0 = msg['x0'] / fig.ratio;\n", + " var y0 = (fig.canvas.height - msg['y0']) / fig.ratio;\n", + " var x1 = msg['x1'] / fig.ratio;\n", + " var y1 = (fig.canvas.height - msg['y1']) / fig.ratio;\n", + " x0 = Math.floor(x0) + 0.5;\n", + " y0 = Math.floor(y0) + 0.5;\n", + " x1 = Math.floor(x1) + 0.5;\n", + " y1 = Math.floor(y1) + 0.5;\n", + " var min_x = Math.min(x0, x1);\n", + " var min_y = Math.min(y0, y1);\n", + " var width = Math.abs(x1 - x0);\n", + " var height = Math.abs(y1 - y0);\n", + "\n", + " fig.rubberband_context.clearRect(\n", + " 0,\n", + " 0,\n", + " fig.canvas.width / fig.ratio,\n", + " fig.canvas.height / fig.ratio\n", + " );\n", + "\n", + " fig.rubberband_context.strokeRect(min_x, min_y, width, height);\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_figure_label = function (fig, msg) {\n", + " // Updates the figure title.\n", + " fig.header.textContent = msg['label'];\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_cursor = function (fig, msg) {\n", + " var cursor = msg['cursor'];\n", + " switch (cursor) {\n", + " case 0:\n", + " cursor = 'pointer';\n", + " break;\n", + " case 1:\n", + " cursor = 'default';\n", + " break;\n", + " case 2:\n", + " cursor = 'crosshair';\n", + " break;\n", + " case 3:\n", + " cursor = 'move';\n", + " break;\n", + " }\n", + " fig.rubberband_canvas.style.cursor = cursor;\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_message = function (fig, msg) {\n", + " fig.message.textContent = msg['message'];\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_draw = function (fig, _msg) {\n", + " // Request the server to send over a new figure.\n", + " fig.send_draw_message();\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_image_mode = function (fig, msg) {\n", + " fig.image_mode = msg['mode'];\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_history_buttons = function (fig, msg) {\n", + " for (var key in msg) {\n", + " if (!(key in fig.buttons)) {\n", + " continue;\n", + " }\n", + " fig.buttons[key].disabled = !msg[key];\n", + " fig.buttons[key].setAttribute('aria-disabled', !msg[key]);\n", + " }\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_navigate_mode = function (fig, msg) {\n", + " if (msg['mode'] === 'PAN') {\n", + " fig.buttons['Pan'].classList.add('active');\n", + " fig.buttons['Zoom'].classList.remove('active');\n", + " } else if (msg['mode'] === 'ZOOM') {\n", + " fig.buttons['Pan'].classList.remove('active');\n", + " fig.buttons['Zoom'].classList.add('active');\n", + " } else {\n", + " fig.buttons['Pan'].classList.remove('active');\n", + " fig.buttons['Zoom'].classList.remove('active');\n", + " }\n", + "};\n", + "\n", + "mpl.figure.prototype.updated_canvas_event = function () {\n", + " // Called whenever the canvas gets updated.\n", + " this.send_message('ack', {});\n", + "};\n", + "\n", + "// A function to construct a web socket function for onmessage handling.\n", + "// Called in the figure constructor.\n", + "mpl.figure.prototype._make_on_message_function = function (fig) {\n", + " return function socket_on_message(evt) {\n", + " if (evt.data instanceof Blob) {\n", + " /* FIXME: We get \"Resource interpreted as Image but\n", + " * transferred with MIME type text/plain:\" errors on\n", + " * Chrome. But how to set the MIME type? It doesn't seem\n", + " * to be part of the websocket stream */\n", + " evt.data.type = 'image/png';\n", + "\n", + " /* Free the memory for the previous frames */\n", + " if (fig.imageObj.src) {\n", + " (window.URL || window.webkitURL).revokeObjectURL(\n", + " fig.imageObj.src\n", + " );\n", + " }\n", + "\n", + " fig.imageObj.src = (window.URL || window.webkitURL).createObjectURL(\n", + " evt.data\n", + " );\n", + " fig.updated_canvas_event();\n", + " fig.waiting = false;\n", + " return;\n", + " } else if (\n", + " typeof evt.data === 'string' &&\n", + " evt.data.slice(0, 21) === 'data:image/png;base64'\n", + " ) {\n", + " fig.imageObj.src = evt.data;\n", + " fig.updated_canvas_event();\n", + " fig.waiting = false;\n", + " return;\n", + " }\n", + "\n", + " var msg = JSON.parse(evt.data);\n", + " var msg_type = msg['type'];\n", + "\n", + " // Call the \"handle_{type}\" callback, which takes\n", + " // the figure and JSON message as its only arguments.\n", + " try {\n", + " var callback = fig['handle_' + msg_type];\n", + " } catch (e) {\n", + " console.log(\n", + " \"No handler for the '\" + msg_type + \"' message type: \",\n", + " msg\n", + " );\n", + " return;\n", + " }\n", + "\n", + " if (callback) {\n", + " try {\n", + " // console.log(\"Handling '\" + msg_type + \"' message: \", msg);\n", + " callback(fig, msg);\n", + " } catch (e) {\n", + " console.log(\n", + " \"Exception inside the 'handler_\" + msg_type + \"' callback:\",\n", + " e,\n", + " e.stack,\n", + " msg\n", + " );\n", + " }\n", + " }\n", + " };\n", + "};\n", + "\n", + "// from http://stackoverflow.com/questions/1114465/getting-mouse-location-in-canvas\n", + "mpl.findpos = function (e) {\n", + " //this section is from http://www.quirksmode.org/js/events_properties.html\n", + " var targ;\n", + " if (!e) {\n", + " e = window.event;\n", + " }\n", + " if (e.target) {\n", + " targ = e.target;\n", + " } else if (e.srcElement) {\n", + " targ = e.srcElement;\n", + " }\n", + " if (targ.nodeType === 3) {\n", + " // defeat Safari bug\n", + " targ = targ.parentNode;\n", + " }\n", + "\n", + " // pageX,Y are the mouse positions relative to the document\n", + " var boundingRect = targ.getBoundingClientRect();\n", + " var x = e.pageX - (boundingRect.left + document.body.scrollLeft);\n", + " var y = e.pageY - (boundingRect.top + document.body.scrollTop);\n", + "\n", + " return { x: x, y: y };\n", + "};\n", + "\n", + "/*\n", + " * return a copy of an object with only non-object keys\n", + " * we need this to avoid circular references\n", + " * http://stackoverflow.com/a/24161582/3208463\n", + " */\n", + "function simpleKeys(original) {\n", + " return Object.keys(original).reduce(function (obj, key) {\n", + " if (typeof original[key] !== 'object') {\n", + " obj[key] = original[key];\n", + " }\n", + " return obj;\n", + " }, {});\n", + "}\n", + "\n", + "mpl.figure.prototype.mouse_event = function (event, name) {\n", + " var canvas_pos = mpl.findpos(event);\n", + "\n", + " if (name === 'button_press') {\n", + " this.canvas.focus();\n", + " this.canvas_div.focus();\n", + " }\n", + "\n", + " var x = canvas_pos.x * this.ratio;\n", + " var y = canvas_pos.y * this.ratio;\n", + "\n", + " this.send_message(name, {\n", + " x: x,\n", + " y: y,\n", + " button: event.button,\n", + " step: event.step,\n", + " guiEvent: simpleKeys(event),\n", + " });\n", + "\n", + " /* This prevents the web browser from automatically changing to\n", + " * the text insertion cursor when the button is pressed. We want\n", + " * to control all of the cursor setting manually through the\n", + " * 'cursor' event from matplotlib */\n", + " event.preventDefault();\n", + " return false;\n", + "};\n", + "\n", + "mpl.figure.prototype._key_event_extra = function (_event, _name) {\n", + " // Handle any extra behaviour associated with a key event\n", + "};\n", + "\n", + "mpl.figure.prototype.key_event = function (event, name) {\n", + " // Prevent repeat events\n", + " if (name === 'key_press') {\n", + " if (event.which === this._key) {\n", + " return;\n", + " } else {\n", + " this._key = event.which;\n", + " }\n", + " }\n", + " if (name === 'key_release') {\n", + " this._key = null;\n", + " }\n", + "\n", + " var value = '';\n", + " if (event.ctrlKey && event.which !== 17) {\n", + " value += 'ctrl+';\n", + " }\n", + " if (event.altKey && event.which !== 18) {\n", + " value += 'alt+';\n", + " }\n", + " if (event.shiftKey && event.which !== 16) {\n", + " value += 'shift+';\n", + " }\n", + "\n", + " value += 'k';\n", + " value += event.which.toString();\n", + "\n", + " this._key_event_extra(event, name);\n", + "\n", + " this.send_message(name, { key: value, guiEvent: simpleKeys(event) });\n", + " return false;\n", + "};\n", + "\n", + "mpl.figure.prototype.toolbar_button_onclick = function (name) {\n", + " if (name === 'download') {\n", + " this.handle_save(this, null);\n", + " } else {\n", + " this.send_message('toolbar_button', { name: name });\n", + " }\n", + "};\n", + "\n", + "mpl.figure.prototype.toolbar_button_onmouseover = function (tooltip) {\n", + " this.message.textContent = tooltip;\n", + "};\n", + "\n", + "///////////////// REMAINING CONTENT GENERATED BY embed_js.py /////////////////\n", + "// prettier-ignore\n", + "var _JSXTOOLS_RESIZE_OBSERVER=function(A){var t,i=new WeakMap,n=new WeakMap,a=new WeakMap,r=new WeakMap,o=new Set;function s(e){if(!(this instanceof s))throw new TypeError(\"Constructor requires 'new' operator\");i.set(this,e)}function h(){throw new TypeError(\"Function is not a constructor\")}function c(e,t,i,n){e=0 in arguments?Number(arguments[0]):0,t=1 in arguments?Number(arguments[1]):0,i=2 in arguments?Number(arguments[2]):0,n=3 in arguments?Number(arguments[3]):0,this.right=(this.x=this.left=e)+(this.width=i),this.bottom=(this.y=this.top=t)+(this.height=n),Object.freeze(this)}function d(){t=requestAnimationFrame(d);var s=new WeakMap,p=new Set;o.forEach((function(t){r.get(t).forEach((function(i){var r=t instanceof window.SVGElement,o=a.get(t),d=r?0:parseFloat(o.paddingTop),f=r?0:parseFloat(o.paddingRight),l=r?0:parseFloat(o.paddingBottom),u=r?0:parseFloat(o.paddingLeft),g=r?0:parseFloat(o.borderTopWidth),m=r?0:parseFloat(o.borderRightWidth),w=r?0:parseFloat(o.borderBottomWidth),b=u+f,F=d+l,v=(r?0:parseFloat(o.borderLeftWidth))+m,W=g+w,y=r?0:t.offsetHeight-W-t.clientHeight,E=r?0:t.offsetWidth-v-t.clientWidth,R=b+v,z=F+W,M=r?t.width:parseFloat(o.width)-R-E,O=r?t.height:parseFloat(o.height)-z-y;if(n.has(t)){var k=n.get(t);if(k[0]===M&&k[1]===O)return}n.set(t,[M,O]);var S=Object.create(h.prototype);S.target=t,S.contentRect=new c(u,d,M,O),s.has(i)||(s.set(i,[]),p.add(i)),s.get(i).push(S)}))})),p.forEach((function(e){i.get(e).call(e,s.get(e),e)}))}return s.prototype.observe=function(i){if(i instanceof window.Element){r.has(i)||(r.set(i,new Set),o.add(i),a.set(i,window.getComputedStyle(i)));var n=r.get(i);n.has(this)||n.add(this),cancelAnimationFrame(t),t=requestAnimationFrame(d)}},s.prototype.unobserve=function(i){if(i instanceof window.Element&&r.has(i)){var n=r.get(i);n.has(this)&&(n.delete(this),n.size||(r.delete(i),o.delete(i))),n.size||r.delete(i),o.size||cancelAnimationFrame(t)}},A.DOMRectReadOnly=c,A.ResizeObserver=s,A.ResizeObserverEntry=h,A}; // eslint-disable-line\n", + "mpl.toolbar_items = [[\"Home\", \"Reset original view\", \"fa fa-home icon-home\", \"home\"], [\"Back\", \"Back to previous view\", \"fa fa-arrow-left icon-arrow-left\", \"back\"], [\"Forward\", \"Forward to next view\", \"fa fa-arrow-right icon-arrow-right\", \"forward\"], [\"\", \"\", \"\", \"\"], [\"Pan\", \"Left button pans, Right button zooms\\nx/y fixes axis, CTRL fixes aspect\", \"fa fa-arrows icon-move\", \"pan\"], [\"Zoom\", \"Zoom to rectangle\\nx/y fixes axis, CTRL fixes aspect\", \"fa fa-square-o icon-check-empty\", \"zoom\"], [\"\", \"\", \"\", \"\"], [\"Download\", \"Download plot\", \"fa fa-floppy-o icon-save\", \"download\"]];\n", + "\n", + "mpl.extensions = [\"eps\", \"jpeg\", \"pdf\", \"png\", \"ps\", \"raw\", \"svg\", \"tif\"];\n", + "\n", + "mpl.default_extension = \"png\";/* global mpl */\n", + "\n", + "var comm_websocket_adapter = function (comm) {\n", + " // Create a \"websocket\"-like object which calls the given IPython comm\n", + " // object with the appropriate methods. Currently this is a non binary\n", + " // socket, so there is still some room for performance tuning.\n", + " var ws = {};\n", + "\n", + " ws.close = function () {\n", + " comm.close();\n", + " };\n", + " ws.send = function (m) {\n", + " //console.log('sending', m);\n", + " comm.send(m);\n", + " };\n", + " // Register the callback with on_msg.\n", + " comm.on_msg(function (msg) {\n", + " //console.log('receiving', msg['content']['data'], msg);\n", + " // Pass the mpl event to the overridden (by mpl) onmessage function.\n", + " ws.onmessage(msg['content']['data']);\n", + " });\n", + " return ws;\n", + "};\n", + "\n", + "mpl.mpl_figure_comm = function (comm, msg) {\n", + " // This is the function which gets called when the mpl process\n", + " // starts-up an IPython Comm through the \"matplotlib\" channel.\n", + "\n", + " var id = msg.content.data.id;\n", + " // Get hold of the div created by the display call when the Comm\n", + " // socket was opened in Python.\n", + " var element = document.getElementById(id);\n", + " var ws_proxy = comm_websocket_adapter(comm);\n", + "\n", + " function ondownload(figure, _format) {\n", + " window.open(figure.canvas.toDataURL());\n", + " }\n", + "\n", + " var fig = new mpl.figure(id, ws_proxy, ondownload, element);\n", + "\n", + " // Call onopen now - mpl needs it, as it is assuming we've passed it a real\n", + " // web socket which is closed, not our websocket->open comm proxy.\n", + " ws_proxy.onopen();\n", + "\n", + " fig.parent_element = element;\n", + " fig.cell_info = mpl.find_output_cell(\"
\");\n", + " if (!fig.cell_info) {\n", + " console.error('Failed to find cell for figure', id, fig);\n", + " return;\n", + " }\n", + " fig.cell_info[0].output_area.element.on(\n", + " 'cleared',\n", + " { fig: fig },\n", + " fig._remove_fig_handler\n", + " );\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_close = function (fig, msg) {\n", + " var width = fig.canvas.width / fig.ratio;\n", + " fig.cell_info[0].output_area.element.off(\n", + " 'cleared',\n", + " fig._remove_fig_handler\n", + " );\n", + " fig.resizeObserverInstance.unobserve(fig.canvas_div);\n", + "\n", + " // Update the output cell to use the data from the current canvas.\n", + " fig.push_to_output();\n", + " var dataURL = fig.canvas.toDataURL();\n", + " // Re-enable the keyboard manager in IPython - without this line, in FF,\n", + " // the notebook keyboard shortcuts fail.\n", + " IPython.keyboard_manager.enable();\n", + " fig.parent_element.innerHTML =\n", + " '';\n", + " fig.close_ws(fig, msg);\n", + "};\n", + "\n", + "mpl.figure.prototype.close_ws = function (fig, msg) {\n", + " fig.send_message('closing', msg);\n", + " // fig.ws.close()\n", + "};\n", + "\n", + "mpl.figure.prototype.push_to_output = function (_remove_interactive) {\n", + " // Turn the data on the canvas into data in the output cell.\n", + " var width = this.canvas.width / this.ratio;\n", + " var dataURL = this.canvas.toDataURL();\n", + " this.cell_info[1]['text/html'] =\n", + " '';\n", + "};\n", + "\n", + "mpl.figure.prototype.updated_canvas_event = function () {\n", + " // Tell IPython that the notebook contents must change.\n", + " IPython.notebook.set_dirty(true);\n", + " this.send_message('ack', {});\n", + " var fig = this;\n", + " // Wait a second, then push the new image to the DOM so\n", + " // that it is saved nicely (might be nice to debounce this).\n", + " setTimeout(function () {\n", + " fig.push_to_output();\n", + " }, 1000);\n", + "};\n", + "\n", + "mpl.figure.prototype._init_toolbar = function () {\n", + " var fig = this;\n", + "\n", + " var toolbar = document.createElement('div');\n", + " toolbar.classList = 'btn-toolbar';\n", + " this.root.appendChild(toolbar);\n", + "\n", + " function on_click_closure(name) {\n", + " return function (_event) {\n", + " return fig.toolbar_button_onclick(name);\n", + " };\n", + " }\n", + "\n", + " function on_mouseover_closure(tooltip) {\n", + " return function (event) {\n", + " if (!event.currentTarget.disabled) {\n", + " return fig.toolbar_button_onmouseover(tooltip);\n", + " }\n", + " };\n", + " }\n", + "\n", + " fig.buttons = {};\n", + " var buttonGroup = document.createElement('div');\n", + " buttonGroup.classList = 'btn-group';\n", + " var button;\n", + " for (var toolbar_ind in mpl.toolbar_items) {\n", + " var name = mpl.toolbar_items[toolbar_ind][0];\n", + " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n", + " var image = mpl.toolbar_items[toolbar_ind][2];\n", + " var method_name = mpl.toolbar_items[toolbar_ind][3];\n", + "\n", + " if (!name) {\n", + " /* Instead of a spacer, we start a new button group. */\n", + " if (buttonGroup.hasChildNodes()) {\n", + " toolbar.appendChild(buttonGroup);\n", + " }\n", + " buttonGroup = document.createElement('div');\n", + " buttonGroup.classList = 'btn-group';\n", + " continue;\n", + " }\n", + "\n", + " button = fig.buttons[name] = document.createElement('button');\n", + " button.classList = 'btn btn-default';\n", + " button.href = '#';\n", + " button.title = name;\n", + " button.innerHTML = '';\n", + " button.addEventListener('click', on_click_closure(method_name));\n", + " button.addEventListener('mouseover', on_mouseover_closure(tooltip));\n", + " buttonGroup.appendChild(button);\n", + " }\n", + "\n", + " if (buttonGroup.hasChildNodes()) {\n", + " toolbar.appendChild(buttonGroup);\n", + " }\n", + "\n", + " // Add the status bar.\n", + " var status_bar = document.createElement('span');\n", + " status_bar.classList = 'mpl-message pull-right';\n", + " toolbar.appendChild(status_bar);\n", + " this.message = status_bar;\n", + "\n", + " // Add the close button to the window.\n", + " var buttongrp = document.createElement('div');\n", + " buttongrp.classList = 'btn-group inline pull-right';\n", + " button = document.createElement('button');\n", + " button.classList = 'btn btn-mini btn-primary';\n", + " button.href = '#';\n", + " button.title = 'Stop Interaction';\n", + " button.innerHTML = '';\n", + " button.addEventListener('click', function (_evt) {\n", + " fig.handle_close(fig, {});\n", + " });\n", + " button.addEventListener(\n", + " 'mouseover',\n", + " on_mouseover_closure('Stop Interaction')\n", + " );\n", + " buttongrp.appendChild(button);\n", + " var titlebar = this.root.querySelector('.ui-dialog-titlebar');\n", + " titlebar.insertBefore(buttongrp, titlebar.firstChild);\n", + "};\n", + "\n", + "mpl.figure.prototype._remove_fig_handler = function (event) {\n", + " var fig = event.data.fig;\n", + " if (event.target !== this) {\n", + " // Ignore bubbled events from children.\n", + " return;\n", + " }\n", + " fig.close_ws(fig, {});\n", + "};\n", + "\n", + "mpl.figure.prototype._root_extra_style = function (el) {\n", + " el.style.boxSizing = 'content-box'; // override notebook setting of border-box.\n", + "};\n", + "\n", + "mpl.figure.prototype._canvas_extra_style = function (el) {\n", + " // this is important to make the div 'focusable\n", + " el.setAttribute('tabindex', 0);\n", + " // reach out to IPython and tell the keyboard manager to turn it's self\n", + " // off when our div gets focus\n", + "\n", + " // location in version 3\n", + " if (IPython.notebook.keyboard_manager) {\n", + " IPython.notebook.keyboard_manager.register_events(el);\n", + " } else {\n", + " // location in version 2\n", + " IPython.keyboard_manager.register_events(el);\n", + " }\n", + "};\n", + "\n", + "mpl.figure.prototype._key_event_extra = function (event, _name) {\n", + " var manager = IPython.notebook.keyboard_manager;\n", + " if (!manager) {\n", + " manager = IPython.keyboard_manager;\n", + " }\n", + "\n", + " // Check for shift+enter\n", + " if (event.shiftKey && event.which === 13) {\n", + " this.canvas_div.blur();\n", + " // select the cell after this one\n", + " var index = IPython.notebook.find_cell_index(this.cell_info[0]);\n", + " IPython.notebook.select(index + 1);\n", + " }\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_save = function (fig, _msg) {\n", + " fig.ondownload(fig, null);\n", + "};\n", + "\n", + "mpl.find_output_cell = function (html_output) {\n", + " // Return the cell and output element which can be found *uniquely* in the notebook.\n", + " // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n", + " // IPython event is triggered only after the cells have been serialised, which for\n", + " // our purposes (turning an active figure into a static one), is too late.\n", + " var cells = IPython.notebook.get_cells();\n", + " var ncells = cells.length;\n", + " for (var i = 0; i < ncells; i++) {\n", + " var cell = cells[i];\n", + " if (cell.cell_type === 'code') {\n", + " for (var j = 0; j < cell.output_area.outputs.length; j++) {\n", + " var data = cell.output_area.outputs[j];\n", + " if (data.data) {\n", + " // IPython >= 3 moved mimebundle to data attribute of output\n", + " data = data.data;\n", + " }\n", + " if (data['text/html'] === html_output) {\n", + " return [cell, data, j];\n", + " }\n", + " }\n", + " }\n", + " }\n", + "};\n", + "\n", + "// Register the function which deals with the matplotlib target/channel.\n", + "// The kernel may be null if the page has been refreshed.\n", + "if (IPython.notebook.kernel !== null) {\n", + " IPython.notebook.kernel.comm_manager.register_target(\n", + " 'matplotlib',\n", + " mpl.mpl_figure_comm\n", + " );\n", + "}\n" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "alphabet = 'abcdefghijklmnopqrstuvwxyz0123456789'\n", + "\n", + "plt.figure()\n", + "\n", + "# Try out all one-letter passwords and plot the obtained power trace\n", + "# FIXME: Your code goes here\n", + "for i in alphabet:\n", + " plt.plot(cap_pass_trace(i))\n", + "\n", + "plt.legend(alphabet)\n", + "\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The end result should be if you zoom in, you'll see there is a location where a single \"outlier\" trace doesn't follow the path of all the other traces. That is great news, since it means we indeed learn something about the system from power analysis.\n", + "\n", + "\"SPA" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Automating an Attack against One Character" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "To start with - we're going to automate an attack against a **single** character of the password. Since we don't know the password (let's assume), we'll use a strategy of comparing all possible inputs together.\n", + "\n", + "An easy way to do this might be to use something that we know can't be part of the valid password. As long as it's processed the same way, this will work just fine. So for now, let's use a password as `0x00` (i.e., a null byte). We can compare the null byte to processing something else:" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "application/javascript": [ + "/* Put everything inside the global mpl namespace */\n", + "/* global mpl */\n", + "window.mpl = {};\n", + "\n", + "mpl.get_websocket_type = function () {\n", + " if (typeof WebSocket !== 'undefined') {\n", + " return WebSocket;\n", + " } else if (typeof MozWebSocket !== 'undefined') {\n", + " return MozWebSocket;\n", + " } else {\n", + " alert(\n", + " 'Your browser does not have WebSocket support. ' +\n", + " 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n", + " 'Firefox 4 and 5 are also supported but you ' +\n", + " 'have to enable WebSockets in about:config.'\n", + " );\n", + " }\n", + "};\n", + "\n", + "mpl.figure = function (figure_id, websocket, ondownload, parent_element) {\n", + " this.id = figure_id;\n", + "\n", + " this.ws = websocket;\n", + "\n", + " this.supports_binary = this.ws.binaryType !== undefined;\n", + "\n", + " if (!this.supports_binary) {\n", + " var warnings = document.getElementById('mpl-warnings');\n", + " if (warnings) {\n", + " warnings.style.display = 'block';\n", + " warnings.textContent =\n", + " 'This browser does not support binary websocket messages. ' +\n", + " 'Performance may be slow.';\n", + " }\n", + " }\n", + "\n", + " this.imageObj = new Image();\n", + "\n", + " this.context = undefined;\n", + " this.message = undefined;\n", + " this.canvas = undefined;\n", + " this.rubberband_canvas = undefined;\n", + " this.rubberband_context = undefined;\n", + " this.format_dropdown = undefined;\n", + "\n", + " this.image_mode = 'full';\n", + "\n", + " this.root = document.createElement('div');\n", + " this.root.setAttribute('style', 'display: inline-block');\n", + " this._root_extra_style(this.root);\n", + "\n", + " parent_element.appendChild(this.root);\n", + "\n", + " this._init_header(this);\n", + " this._init_canvas(this);\n", + " this._init_toolbar(this);\n", + "\n", + " var fig = this;\n", + "\n", + " this.waiting = false;\n", + "\n", + " this.ws.onopen = function () {\n", + " fig.send_message('supports_binary', { value: fig.supports_binary });\n", + " fig.send_message('send_image_mode', {});\n", + " if (fig.ratio !== 1) {\n", + " fig.send_message('set_dpi_ratio', { dpi_ratio: fig.ratio });\n", + " }\n", + " fig.send_message('refresh', {});\n", + " };\n", + "\n", + " this.imageObj.onload = function () {\n", + " if (fig.image_mode === 'full') {\n", + " // Full images could contain transparency (where diff images\n", + " // almost always do), so we need to clear the canvas so that\n", + " // there is no ghosting.\n", + " fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n", + " }\n", + " fig.context.drawImage(fig.imageObj, 0, 0);\n", + " };\n", + "\n", + " this.imageObj.onunload = function () {\n", + " fig.ws.close();\n", + " };\n", + "\n", + " this.ws.onmessage = this._make_on_message_function(this);\n", + "\n", + " this.ondownload = ondownload;\n", + "};\n", + "\n", + "mpl.figure.prototype._init_header = function () {\n", + " var titlebar = document.createElement('div');\n", + " titlebar.classList =\n", + " 'ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix';\n", + " var titletext = document.createElement('div');\n", + " titletext.classList = 'ui-dialog-title';\n", + " titletext.setAttribute(\n", + " 'style',\n", + " 'width: 100%; text-align: center; padding: 3px;'\n", + " );\n", + " titlebar.appendChild(titletext);\n", + " this.root.appendChild(titlebar);\n", + " this.header = titletext;\n", + "};\n", + "\n", + "mpl.figure.prototype._canvas_extra_style = function (_canvas_div) {};\n", + "\n", + "mpl.figure.prototype._root_extra_style = function (_canvas_div) {};\n", + "\n", + "mpl.figure.prototype._init_canvas = function () {\n", + " var fig = this;\n", + "\n", + " var canvas_div = (this.canvas_div = document.createElement('div'));\n", + " canvas_div.setAttribute(\n", + " 'style',\n", + " 'border: 1px solid #ddd;' +\n", + " 'box-sizing: content-box;' +\n", + " 'clear: both;' +\n", + " 'min-height: 1px;' +\n", + " 'min-width: 1px;' +\n", + " 'outline: 0;' +\n", + " 'overflow: hidden;' +\n", + " 'position: relative;' +\n", + " 'resize: both;'\n", + " );\n", + "\n", + " function on_keyboard_event_closure(name) {\n", + " return function (event) {\n", + " return fig.key_event(event, name);\n", + " };\n", + " }\n", + "\n", + " canvas_div.addEventListener(\n", + " 'keydown',\n", + " on_keyboard_event_closure('key_press')\n", + " );\n", + " canvas_div.addEventListener(\n", + " 'keyup',\n", + " on_keyboard_event_closure('key_release')\n", + " );\n", + "\n", + " this._canvas_extra_style(canvas_div);\n", + " this.root.appendChild(canvas_div);\n", + "\n", + " var canvas = (this.canvas = document.createElement('canvas'));\n", + " canvas.classList.add('mpl-canvas');\n", + " canvas.setAttribute('style', 'box-sizing: content-box;');\n", + "\n", + " this.context = canvas.getContext('2d');\n", + "\n", + " var backingStore =\n", + " this.context.backingStorePixelRatio ||\n", + " this.context.webkitBackingStorePixelRatio ||\n", + " this.context.mozBackingStorePixelRatio ||\n", + " this.context.msBackingStorePixelRatio ||\n", + " this.context.oBackingStorePixelRatio ||\n", + " this.context.backingStorePixelRatio ||\n", + " 1;\n", + "\n", + " this.ratio = (window.devicePixelRatio || 1) / backingStore;\n", + "\n", + " var rubberband_canvas = (this.rubberband_canvas = document.createElement(\n", + " 'canvas'\n", + " ));\n", + " rubberband_canvas.setAttribute(\n", + " 'style',\n", + " 'box-sizing: content-box; position: absolute; left: 0; top: 0; z-index: 1;'\n", + " );\n", + "\n", + " // Apply a ponyfill if ResizeObserver is not implemented by browser.\n", + " if (this.ResizeObserver === undefined) {\n", + " if (window.ResizeObserver !== undefined) {\n", + " this.ResizeObserver = window.ResizeObserver;\n", + " } else {\n", + " var obs = _JSXTOOLS_RESIZE_OBSERVER({});\n", + " this.ResizeObserver = obs.ResizeObserver;\n", + " }\n", + " }\n", + "\n", + " this.resizeObserverInstance = new this.ResizeObserver(function (entries) {\n", + " var nentries = entries.length;\n", + " for (var i = 0; i < nentries; i++) {\n", + " var entry = entries[i];\n", + " var width, height;\n", + " if (entry.contentBoxSize) {\n", + " if (entry.contentBoxSize instanceof Array) {\n", + " // Chrome 84 implements new version of spec.\n", + " width = entry.contentBoxSize[0].inlineSize;\n", + " height = entry.contentBoxSize[0].blockSize;\n", + " } else {\n", + " // Firefox implements old version of spec.\n", + " width = entry.contentBoxSize.inlineSize;\n", + " height = entry.contentBoxSize.blockSize;\n", + " }\n", + " } else {\n", + " // Chrome <84 implements even older version of spec.\n", + " width = entry.contentRect.width;\n", + " height = entry.contentRect.height;\n", + " }\n", + "\n", + " // Keep the size of the canvas and rubber band canvas in sync with\n", + " // the canvas container.\n", + " if (entry.devicePixelContentBoxSize) {\n", + " // Chrome 84 implements new version of spec.\n", + " canvas.setAttribute(\n", + " 'width',\n", + " entry.devicePixelContentBoxSize[0].inlineSize\n", + " );\n", + " canvas.setAttribute(\n", + " 'height',\n", + " entry.devicePixelContentBoxSize[0].blockSize\n", + " );\n", + " } else {\n", + " canvas.setAttribute('width', width * fig.ratio);\n", + " canvas.setAttribute('height', height * fig.ratio);\n", + " }\n", + " canvas.setAttribute(\n", + " 'style',\n", + " 'width: ' + width + 'px; height: ' + height + 'px;'\n", + " );\n", + "\n", + " rubberband_canvas.setAttribute('width', width);\n", + " rubberband_canvas.setAttribute('height', height);\n", + "\n", + " // And update the size in Python. We ignore the initial 0/0 size\n", + " // that occurs as the element is placed into the DOM, which should\n", + " // otherwise not happen due to the minimum size styling.\n", + " if (fig.ws.readyState == 1 && width != 0 && height != 0) {\n", + " fig.request_resize(width, height);\n", + " }\n", + " }\n", + " });\n", + " this.resizeObserverInstance.observe(canvas_div);\n", + "\n", + " function on_mouse_event_closure(name) {\n", + " return function (event) {\n", + " return fig.mouse_event(event, name);\n", + " };\n", + " }\n", + "\n", + " rubberband_canvas.addEventListener(\n", + " 'mousedown',\n", + " on_mouse_event_closure('button_press')\n", + " );\n", + " rubberband_canvas.addEventListener(\n", + " 'mouseup',\n", + " on_mouse_event_closure('button_release')\n", + " );\n", + " // Throttle sequential mouse events to 1 every 20ms.\n", + " rubberband_canvas.addEventListener(\n", + " 'mousemove',\n", + " on_mouse_event_closure('motion_notify')\n", + " );\n", + "\n", + " rubberband_canvas.addEventListener(\n", + " 'mouseenter',\n", + " on_mouse_event_closure('figure_enter')\n", + " );\n", + " rubberband_canvas.addEventListener(\n", + " 'mouseleave',\n", + " on_mouse_event_closure('figure_leave')\n", + " );\n", + "\n", + " canvas_div.addEventListener('wheel', function (event) {\n", + " if (event.deltaY < 0) {\n", + " event.step = 1;\n", + " } else {\n", + " event.step = -1;\n", + " }\n", + " on_mouse_event_closure('scroll')(event);\n", + " });\n", + "\n", + " canvas_div.appendChild(canvas);\n", + " canvas_div.appendChild(rubberband_canvas);\n", + "\n", + " this.rubberband_context = rubberband_canvas.getContext('2d');\n", + " this.rubberband_context.strokeStyle = '#000000';\n", + "\n", + " this._resize_canvas = function (width, height, forward) {\n", + " if (forward) {\n", + " canvas_div.style.width = width + 'px';\n", + " canvas_div.style.height = height + 'px';\n", + " }\n", + " };\n", + "\n", + " // Disable right mouse context menu.\n", + " this.rubberband_canvas.addEventListener('contextmenu', function (_e) {\n", + " event.preventDefault();\n", + " return false;\n", + " });\n", + "\n", + " function set_focus() {\n", + " canvas.focus();\n", + " canvas_div.focus();\n", + " }\n", + "\n", + " window.setTimeout(set_focus, 100);\n", + "};\n", + "\n", + "mpl.figure.prototype._init_toolbar = function () {\n", + " var fig = this;\n", + "\n", + " var toolbar = document.createElement('div');\n", + " toolbar.classList = 'mpl-toolbar';\n", + " this.root.appendChild(toolbar);\n", + "\n", + " function on_click_closure(name) {\n", + " return function (_event) {\n", + " return fig.toolbar_button_onclick(name);\n", + " };\n", + " }\n", + "\n", + " function on_mouseover_closure(tooltip) {\n", + " return function (event) {\n", + " if (!event.currentTarget.disabled) {\n", + " return fig.toolbar_button_onmouseover(tooltip);\n", + " }\n", + " };\n", + " }\n", + "\n", + " fig.buttons = {};\n", + " var buttonGroup = document.createElement('div');\n", + " buttonGroup.classList = 'mpl-button-group';\n", + " for (var toolbar_ind in mpl.toolbar_items) {\n", + " var name = mpl.toolbar_items[toolbar_ind][0];\n", + " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n", + " var image = mpl.toolbar_items[toolbar_ind][2];\n", + " var method_name = mpl.toolbar_items[toolbar_ind][3];\n", + "\n", + " if (!name) {\n", + " /* Instead of a spacer, we start a new button group. */\n", + " if (buttonGroup.hasChildNodes()) {\n", + " toolbar.appendChild(buttonGroup);\n", + " }\n", + " buttonGroup = document.createElement('div');\n", + " buttonGroup.classList = 'mpl-button-group';\n", + " continue;\n", + " }\n", + "\n", + " var button = (fig.buttons[name] = document.createElement('button'));\n", + " button.classList = 'mpl-widget';\n", + " button.setAttribute('role', 'button');\n", + " button.setAttribute('aria-disabled', 'false');\n", + " button.addEventListener('click', on_click_closure(method_name));\n", + " button.addEventListener('mouseover', on_mouseover_closure(tooltip));\n", + "\n", + " var icon_img = document.createElement('img');\n", + " icon_img.src = '_images/' + image + '.png';\n", + " icon_img.srcset = '_images/' + image + '_large.png 2x';\n", + " icon_img.alt = tooltip;\n", + " button.appendChild(icon_img);\n", + "\n", + " buttonGroup.appendChild(button);\n", + " }\n", + "\n", + " if (buttonGroup.hasChildNodes()) {\n", + " toolbar.appendChild(buttonGroup);\n", + " }\n", + "\n", + " var fmt_picker = document.createElement('select');\n", + " fmt_picker.classList = 'mpl-widget';\n", + " toolbar.appendChild(fmt_picker);\n", + " this.format_dropdown = fmt_picker;\n", + "\n", + " for (var ind in mpl.extensions) {\n", + " var fmt = mpl.extensions[ind];\n", + " var option = document.createElement('option');\n", + " option.selected = fmt === mpl.default_extension;\n", + " option.innerHTML = fmt;\n", + " fmt_picker.appendChild(option);\n", + " }\n", + "\n", + " var status_bar = document.createElement('span');\n", + " status_bar.classList = 'mpl-message';\n", + " toolbar.appendChild(status_bar);\n", + " this.message = status_bar;\n", + "};\n", + "\n", + "mpl.figure.prototype.request_resize = function (x_pixels, y_pixels) {\n", + " // Request matplotlib to resize the figure. Matplotlib will then trigger a resize in the client,\n", + " // which will in turn request a refresh of the image.\n", + " this.send_message('resize', { width: x_pixels, height: y_pixels });\n", + "};\n", + "\n", + "mpl.figure.prototype.send_message = function (type, properties) {\n", + " properties['type'] = type;\n", + " properties['figure_id'] = this.id;\n", + " this.ws.send(JSON.stringify(properties));\n", + "};\n", + "\n", + "mpl.figure.prototype.send_draw_message = function () {\n", + " if (!this.waiting) {\n", + " this.waiting = true;\n", + " this.ws.send(JSON.stringify({ type: 'draw', figure_id: this.id }));\n", + " }\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_save = function (fig, _msg) {\n", + " var format_dropdown = fig.format_dropdown;\n", + " var format = format_dropdown.options[format_dropdown.selectedIndex].value;\n", + " fig.ondownload(fig, format);\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_resize = function (fig, msg) {\n", + " var size = msg['size'];\n", + " if (size[0] !== fig.canvas.width || size[1] !== fig.canvas.height) {\n", + " fig._resize_canvas(size[0], size[1], msg['forward']);\n", + " fig.send_message('refresh', {});\n", + " }\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_rubberband = function (fig, msg) {\n", + " var x0 = msg['x0'] / fig.ratio;\n", + " var y0 = (fig.canvas.height - msg['y0']) / fig.ratio;\n", + " var x1 = msg['x1'] / fig.ratio;\n", + " var y1 = (fig.canvas.height - msg['y1']) / fig.ratio;\n", + " x0 = Math.floor(x0) + 0.5;\n", + " y0 = Math.floor(y0) + 0.5;\n", + " x1 = Math.floor(x1) + 0.5;\n", + " y1 = Math.floor(y1) + 0.5;\n", + " var min_x = Math.min(x0, x1);\n", + " var min_y = Math.min(y0, y1);\n", + " var width = Math.abs(x1 - x0);\n", + " var height = Math.abs(y1 - y0);\n", + "\n", + " fig.rubberband_context.clearRect(\n", + " 0,\n", + " 0,\n", + " fig.canvas.width / fig.ratio,\n", + " fig.canvas.height / fig.ratio\n", + " );\n", + "\n", + " fig.rubberband_context.strokeRect(min_x, min_y, width, height);\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_figure_label = function (fig, msg) {\n", + " // Updates the figure title.\n", + " fig.header.textContent = msg['label'];\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_cursor = function (fig, msg) {\n", + " var cursor = msg['cursor'];\n", + " switch (cursor) {\n", + " case 0:\n", + " cursor = 'pointer';\n", + " break;\n", + " case 1:\n", + " cursor = 'default';\n", + " break;\n", + " case 2:\n", + " cursor = 'crosshair';\n", + " break;\n", + " case 3:\n", + " cursor = 'move';\n", + " break;\n", + " }\n", + " fig.rubberband_canvas.style.cursor = cursor;\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_message = function (fig, msg) {\n", + " fig.message.textContent = msg['message'];\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_draw = function (fig, _msg) {\n", + " // Request the server to send over a new figure.\n", + " fig.send_draw_message();\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_image_mode = function (fig, msg) {\n", + " fig.image_mode = msg['mode'];\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_history_buttons = function (fig, msg) {\n", + " for (var key in msg) {\n", + " if (!(key in fig.buttons)) {\n", + " continue;\n", + " }\n", + " fig.buttons[key].disabled = !msg[key];\n", + " fig.buttons[key].setAttribute('aria-disabled', !msg[key]);\n", + " }\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_navigate_mode = function (fig, msg) {\n", + " if (msg['mode'] === 'PAN') {\n", + " fig.buttons['Pan'].classList.add('active');\n", + " fig.buttons['Zoom'].classList.remove('active');\n", + " } else if (msg['mode'] === 'ZOOM') {\n", + " fig.buttons['Pan'].classList.remove('active');\n", + " fig.buttons['Zoom'].classList.add('active');\n", + " } else {\n", + " fig.buttons['Pan'].classList.remove('active');\n", + " fig.buttons['Zoom'].classList.remove('active');\n", + " }\n", + "};\n", + "\n", + "mpl.figure.prototype.updated_canvas_event = function () {\n", + " // Called whenever the canvas gets updated.\n", + " this.send_message('ack', {});\n", + "};\n", + "\n", + "// A function to construct a web socket function for onmessage handling.\n", + "// Called in the figure constructor.\n", + "mpl.figure.prototype._make_on_message_function = function (fig) {\n", + " return function socket_on_message(evt) {\n", + " if (evt.data instanceof Blob) {\n", + " /* FIXME: We get \"Resource interpreted as Image but\n", + " * transferred with MIME type text/plain:\" errors on\n", + " * Chrome. But how to set the MIME type? It doesn't seem\n", + " * to be part of the websocket stream */\n", + " evt.data.type = 'image/png';\n", + "\n", + " /* Free the memory for the previous frames */\n", + " if (fig.imageObj.src) {\n", + " (window.URL || window.webkitURL).revokeObjectURL(\n", + " fig.imageObj.src\n", + " );\n", + " }\n", + "\n", + " fig.imageObj.src = (window.URL || window.webkitURL).createObjectURL(\n", + " evt.data\n", + " );\n", + " fig.updated_canvas_event();\n", + " fig.waiting = false;\n", + " return;\n", + " } else if (\n", + " typeof evt.data === 'string' &&\n", + " evt.data.slice(0, 21) === 'data:image/png;base64'\n", + " ) {\n", + " fig.imageObj.src = evt.data;\n", + " fig.updated_canvas_event();\n", + " fig.waiting = false;\n", + " return;\n", + " }\n", + "\n", + " var msg = JSON.parse(evt.data);\n", + " var msg_type = msg['type'];\n", + "\n", + " // Call the \"handle_{type}\" callback, which takes\n", + " // the figure and JSON message as its only arguments.\n", + " try {\n", + " var callback = fig['handle_' + msg_type];\n", + " } catch (e) {\n", + " console.log(\n", + " \"No handler for the '\" + msg_type + \"' message type: \",\n", + " msg\n", + " );\n", + " return;\n", + " }\n", + "\n", + " if (callback) {\n", + " try {\n", + " // console.log(\"Handling '\" + msg_type + \"' message: \", msg);\n", + " callback(fig, msg);\n", + " } catch (e) {\n", + " console.log(\n", + " \"Exception inside the 'handler_\" + msg_type + \"' callback:\",\n", + " e,\n", + " e.stack,\n", + " msg\n", + " );\n", + " }\n", + " }\n", + " };\n", + "};\n", + "\n", + "// from http://stackoverflow.com/questions/1114465/getting-mouse-location-in-canvas\n", + "mpl.findpos = function (e) {\n", + " //this section is from http://www.quirksmode.org/js/events_properties.html\n", + " var targ;\n", + " if (!e) {\n", + " e = window.event;\n", + " }\n", + " if (e.target) {\n", + " targ = e.target;\n", + " } else if (e.srcElement) {\n", + " targ = e.srcElement;\n", + " }\n", + " if (targ.nodeType === 3) {\n", + " // defeat Safari bug\n", + " targ = targ.parentNode;\n", + " }\n", + "\n", + " // pageX,Y are the mouse positions relative to the document\n", + " var boundingRect = targ.getBoundingClientRect();\n", + " var x = e.pageX - (boundingRect.left + document.body.scrollLeft);\n", + " var y = e.pageY - (boundingRect.top + document.body.scrollTop);\n", + "\n", + " return { x: x, y: y };\n", + "};\n", + "\n", + "/*\n", + " * return a copy of an object with only non-object keys\n", + " * we need this to avoid circular references\n", + " * http://stackoverflow.com/a/24161582/3208463\n", + " */\n", + "function simpleKeys(original) {\n", + " return Object.keys(original).reduce(function (obj, key) {\n", + " if (typeof original[key] !== 'object') {\n", + " obj[key] = original[key];\n", + " }\n", + " return obj;\n", + " }, {});\n", + "}\n", + "\n", + "mpl.figure.prototype.mouse_event = function (event, name) {\n", + " var canvas_pos = mpl.findpos(event);\n", + "\n", + " if (name === 'button_press') {\n", + " this.canvas.focus();\n", + " this.canvas_div.focus();\n", + " }\n", + "\n", + " var x = canvas_pos.x * this.ratio;\n", + " var y = canvas_pos.y * this.ratio;\n", + "\n", + " this.send_message(name, {\n", + " x: x,\n", + " y: y,\n", + " button: event.button,\n", + " step: event.step,\n", + " guiEvent: simpleKeys(event),\n", + " });\n", + "\n", + " /* This prevents the web browser from automatically changing to\n", + " * the text insertion cursor when the button is pressed. We want\n", + " * to control all of the cursor setting manually through the\n", + " * 'cursor' event from matplotlib */\n", + " event.preventDefault();\n", + " return false;\n", + "};\n", + "\n", + "mpl.figure.prototype._key_event_extra = function (_event, _name) {\n", + " // Handle any extra behaviour associated with a key event\n", + "};\n", + "\n", + "mpl.figure.prototype.key_event = function (event, name) {\n", + " // Prevent repeat events\n", + " if (name === 'key_press') {\n", + " if (event.which === this._key) {\n", + " return;\n", + " } else {\n", + " this._key = event.which;\n", + " }\n", + " }\n", + " if (name === 'key_release') {\n", + " this._key = null;\n", + " }\n", + "\n", + " var value = '';\n", + " if (event.ctrlKey && event.which !== 17) {\n", + " value += 'ctrl+';\n", + " }\n", + " if (event.altKey && event.which !== 18) {\n", + " value += 'alt+';\n", + " }\n", + " if (event.shiftKey && event.which !== 16) {\n", + " value += 'shift+';\n", + " }\n", + "\n", + " value += 'k';\n", + " value += event.which.toString();\n", + "\n", + " this._key_event_extra(event, name);\n", + "\n", + " this.send_message(name, { key: value, guiEvent: simpleKeys(event) });\n", + " return false;\n", + "};\n", + "\n", + "mpl.figure.prototype.toolbar_button_onclick = function (name) {\n", + " if (name === 'download') {\n", + " this.handle_save(this, null);\n", + " } else {\n", + " this.send_message('toolbar_button', { name: name });\n", + " }\n", + "};\n", + "\n", + "mpl.figure.prototype.toolbar_button_onmouseover = function (tooltip) {\n", + " this.message.textContent = tooltip;\n", + "};\n", + "\n", + "///////////////// REMAINING CONTENT GENERATED BY embed_js.py /////////////////\n", + "// prettier-ignore\n", + "var _JSXTOOLS_RESIZE_OBSERVER=function(A){var t,i=new WeakMap,n=new WeakMap,a=new WeakMap,r=new WeakMap,o=new Set;function s(e){if(!(this instanceof s))throw new TypeError(\"Constructor requires 'new' operator\");i.set(this,e)}function h(){throw new TypeError(\"Function is not a constructor\")}function c(e,t,i,n){e=0 in arguments?Number(arguments[0]):0,t=1 in arguments?Number(arguments[1]):0,i=2 in arguments?Number(arguments[2]):0,n=3 in arguments?Number(arguments[3]):0,this.right=(this.x=this.left=e)+(this.width=i),this.bottom=(this.y=this.top=t)+(this.height=n),Object.freeze(this)}function d(){t=requestAnimationFrame(d);var s=new WeakMap,p=new Set;o.forEach((function(t){r.get(t).forEach((function(i){var r=t instanceof window.SVGElement,o=a.get(t),d=r?0:parseFloat(o.paddingTop),f=r?0:parseFloat(o.paddingRight),l=r?0:parseFloat(o.paddingBottom),u=r?0:parseFloat(o.paddingLeft),g=r?0:parseFloat(o.borderTopWidth),m=r?0:parseFloat(o.borderRightWidth),w=r?0:parseFloat(o.borderBottomWidth),b=u+f,F=d+l,v=(r?0:parseFloat(o.borderLeftWidth))+m,W=g+w,y=r?0:t.offsetHeight-W-t.clientHeight,E=r?0:t.offsetWidth-v-t.clientWidth,R=b+v,z=F+W,M=r?t.width:parseFloat(o.width)-R-E,O=r?t.height:parseFloat(o.height)-z-y;if(n.has(t)){var k=n.get(t);if(k[0]===M&&k[1]===O)return}n.set(t,[M,O]);var S=Object.create(h.prototype);S.target=t,S.contentRect=new c(u,d,M,O),s.has(i)||(s.set(i,[]),p.add(i)),s.get(i).push(S)}))})),p.forEach((function(e){i.get(e).call(e,s.get(e),e)}))}return s.prototype.observe=function(i){if(i instanceof window.Element){r.has(i)||(r.set(i,new Set),o.add(i),a.set(i,window.getComputedStyle(i)));var n=r.get(i);n.has(this)||n.add(this),cancelAnimationFrame(t),t=requestAnimationFrame(d)}},s.prototype.unobserve=function(i){if(i instanceof window.Element&&r.has(i)){var n=r.get(i);n.has(this)&&(n.delete(this),n.size||(r.delete(i),o.delete(i))),n.size||r.delete(i),o.size||cancelAnimationFrame(t)}},A.DOMRectReadOnly=c,A.ResizeObserver=s,A.ResizeObserverEntry=h,A}; // eslint-disable-line\n", + "mpl.toolbar_items = [[\"Home\", \"Reset original view\", \"fa fa-home icon-home\", \"home\"], [\"Back\", \"Back to previous view\", \"fa fa-arrow-left icon-arrow-left\", \"back\"], [\"Forward\", \"Forward to next view\", \"fa fa-arrow-right icon-arrow-right\", \"forward\"], [\"\", \"\", \"\", \"\"], [\"Pan\", \"Left button pans, Right button zooms\\nx/y fixes axis, CTRL fixes aspect\", \"fa fa-arrows icon-move\", \"pan\"], [\"Zoom\", \"Zoom to rectangle\\nx/y fixes axis, CTRL fixes aspect\", \"fa fa-square-o icon-check-empty\", \"zoom\"], [\"\", \"\", \"\", \"\"], [\"Download\", \"Download plot\", \"fa fa-floppy-o icon-save\", \"download\"]];\n", + "\n", + "mpl.extensions = [\"eps\", \"jpeg\", \"pdf\", \"png\", \"ps\", \"raw\", \"svg\", \"tif\"];\n", + "\n", + "mpl.default_extension = \"png\";/* global mpl */\n", + "\n", + "var comm_websocket_adapter = function (comm) {\n", + " // Create a \"websocket\"-like object which calls the given IPython comm\n", + " // object with the appropriate methods. Currently this is a non binary\n", + " // socket, so there is still some room for performance tuning.\n", + " var ws = {};\n", + "\n", + " ws.close = function () {\n", + " comm.close();\n", + " };\n", + " ws.send = function (m) {\n", + " //console.log('sending', m);\n", + " comm.send(m);\n", + " };\n", + " // Register the callback with on_msg.\n", + " comm.on_msg(function (msg) {\n", + " //console.log('receiving', msg['content']['data'], msg);\n", + " // Pass the mpl event to the overridden (by mpl) onmessage function.\n", + " ws.onmessage(msg['content']['data']);\n", + " });\n", + " return ws;\n", + "};\n", + "\n", + "mpl.mpl_figure_comm = function (comm, msg) {\n", + " // This is the function which gets called when the mpl process\n", + " // starts-up an IPython Comm through the \"matplotlib\" channel.\n", + "\n", + " var id = msg.content.data.id;\n", + " // Get hold of the div created by the display call when the Comm\n", + " // socket was opened in Python.\n", + " var element = document.getElementById(id);\n", + " var ws_proxy = comm_websocket_adapter(comm);\n", + "\n", + " function ondownload(figure, _format) {\n", + " window.open(figure.canvas.toDataURL());\n", + " }\n", + "\n", + " var fig = new mpl.figure(id, ws_proxy, ondownload, element);\n", + "\n", + " // Call onopen now - mpl needs it, as it is assuming we've passed it a real\n", + " // web socket which is closed, not our websocket->open comm proxy.\n", + " ws_proxy.onopen();\n", + "\n", + " fig.parent_element = element;\n", + " fig.cell_info = mpl.find_output_cell(\"
\");\n", + " if (!fig.cell_info) {\n", + " console.error('Failed to find cell for figure', id, fig);\n", + " return;\n", + " }\n", + " fig.cell_info[0].output_area.element.on(\n", + " 'cleared',\n", + " { fig: fig },\n", + " fig._remove_fig_handler\n", + " );\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_close = function (fig, msg) {\n", + " var width = fig.canvas.width / fig.ratio;\n", + " fig.cell_info[0].output_area.element.off(\n", + " 'cleared',\n", + " fig._remove_fig_handler\n", + " );\n", + " fig.resizeObserverInstance.unobserve(fig.canvas_div);\n", + "\n", + " // Update the output cell to use the data from the current canvas.\n", + " fig.push_to_output();\n", + " var dataURL = fig.canvas.toDataURL();\n", + " // Re-enable the keyboard manager in IPython - without this line, in FF,\n", + " // the notebook keyboard shortcuts fail.\n", + " IPython.keyboard_manager.enable();\n", + " fig.parent_element.innerHTML =\n", + " '';\n", + " fig.close_ws(fig, msg);\n", + "};\n", + "\n", + "mpl.figure.prototype.close_ws = function (fig, msg) {\n", + " fig.send_message('closing', msg);\n", + " // fig.ws.close()\n", + "};\n", + "\n", + "mpl.figure.prototype.push_to_output = function (_remove_interactive) {\n", + " // Turn the data on the canvas into data in the output cell.\n", + " var width = this.canvas.width / this.ratio;\n", + " var dataURL = this.canvas.toDataURL();\n", + " this.cell_info[1]['text/html'] =\n", + " '';\n", + "};\n", + "\n", + "mpl.figure.prototype.updated_canvas_event = function () {\n", + " // Tell IPython that the notebook contents must change.\n", + " IPython.notebook.set_dirty(true);\n", + " this.send_message('ack', {});\n", + " var fig = this;\n", + " // Wait a second, then push the new image to the DOM so\n", + " // that it is saved nicely (might be nice to debounce this).\n", + " setTimeout(function () {\n", + " fig.push_to_output();\n", + " }, 1000);\n", + "};\n", + "\n", + "mpl.figure.prototype._init_toolbar = function () {\n", + " var fig = this;\n", + "\n", + " var toolbar = document.createElement('div');\n", + " toolbar.classList = 'btn-toolbar';\n", + " this.root.appendChild(toolbar);\n", + "\n", + " function on_click_closure(name) {\n", + " return function (_event) {\n", + " return fig.toolbar_button_onclick(name);\n", + " };\n", + " }\n", + "\n", + " function on_mouseover_closure(tooltip) {\n", + " return function (event) {\n", + " if (!event.currentTarget.disabled) {\n", + " return fig.toolbar_button_onmouseover(tooltip);\n", + " }\n", + " };\n", + " }\n", + "\n", + " fig.buttons = {};\n", + " var buttonGroup = document.createElement('div');\n", + " buttonGroup.classList = 'btn-group';\n", + " var button;\n", + " for (var toolbar_ind in mpl.toolbar_items) {\n", + " var name = mpl.toolbar_items[toolbar_ind][0];\n", + " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n", + " var image = mpl.toolbar_items[toolbar_ind][2];\n", + " var method_name = mpl.toolbar_items[toolbar_ind][3];\n", + "\n", + " if (!name) {\n", + " /* Instead of a spacer, we start a new button group. */\n", + " if (buttonGroup.hasChildNodes()) {\n", + " toolbar.appendChild(buttonGroup);\n", + " }\n", + " buttonGroup = document.createElement('div');\n", + " buttonGroup.classList = 'btn-group';\n", + " continue;\n", + " }\n", + "\n", + " button = fig.buttons[name] = document.createElement('button');\n", + " button.classList = 'btn btn-default';\n", + " button.href = '#';\n", + " button.title = name;\n", + " button.innerHTML = '';\n", + " button.addEventListener('click', on_click_closure(method_name));\n", + " button.addEventListener('mouseover', on_mouseover_closure(tooltip));\n", + " buttonGroup.appendChild(button);\n", + " }\n", + "\n", + " if (buttonGroup.hasChildNodes()) {\n", + " toolbar.appendChild(buttonGroup);\n", + " }\n", + "\n", + " // Add the status bar.\n", + " var status_bar = document.createElement('span');\n", + " status_bar.classList = 'mpl-message pull-right';\n", + " toolbar.appendChild(status_bar);\n", + " this.message = status_bar;\n", + "\n", + " // Add the close button to the window.\n", + " var buttongrp = document.createElement('div');\n", + " buttongrp.classList = 'btn-group inline pull-right';\n", + " button = document.createElement('button');\n", + " button.classList = 'btn btn-mini btn-primary';\n", + " button.href = '#';\n", + " button.title = 'Stop Interaction';\n", + " button.innerHTML = '';\n", + " button.addEventListener('click', function (_evt) {\n", + " fig.handle_close(fig, {});\n", + " });\n", + " button.addEventListener(\n", + " 'mouseover',\n", + " on_mouseover_closure('Stop Interaction')\n", + " );\n", + " buttongrp.appendChild(button);\n", + " var titlebar = this.root.querySelector('.ui-dialog-titlebar');\n", + " titlebar.insertBefore(buttongrp, titlebar.firstChild);\n", + "};\n", + "\n", + "mpl.figure.prototype._remove_fig_handler = function (event) {\n", + " var fig = event.data.fig;\n", + " if (event.target !== this) {\n", + " // Ignore bubbled events from children.\n", + " return;\n", + " }\n", + " fig.close_ws(fig, {});\n", + "};\n", + "\n", + "mpl.figure.prototype._root_extra_style = function (el) {\n", + " el.style.boxSizing = 'content-box'; // override notebook setting of border-box.\n", + "};\n", + "\n", + "mpl.figure.prototype._canvas_extra_style = function (el) {\n", + " // this is important to make the div 'focusable\n", + " el.setAttribute('tabindex', 0);\n", + " // reach out to IPython and tell the keyboard manager to turn it's self\n", + " // off when our div gets focus\n", + "\n", + " // location in version 3\n", + " if (IPython.notebook.keyboard_manager) {\n", + " IPython.notebook.keyboard_manager.register_events(el);\n", + " } else {\n", + " // location in version 2\n", + " IPython.keyboard_manager.register_events(el);\n", + " }\n", + "};\n", + "\n", + "mpl.figure.prototype._key_event_extra = function (event, _name) {\n", + " var manager = IPython.notebook.keyboard_manager;\n", + " if (!manager) {\n", + " manager = IPython.keyboard_manager;\n", + " }\n", + "\n", + " // Check for shift+enter\n", + " if (event.shiftKey && event.which === 13) {\n", + " this.canvas_div.blur();\n", + " // select the cell after this one\n", + " var index = IPython.notebook.find_cell_index(this.cell_info[0]);\n", + " IPython.notebook.select(index + 1);\n", + " }\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_save = function (fig, _msg) {\n", + " fig.ondownload(fig, null);\n", + "};\n", + "\n", + "mpl.find_output_cell = function (html_output) {\n", + " // Return the cell and output element which can be found *uniquely* in the notebook.\n", + " // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n", + " // IPython event is triggered only after the cells have been serialised, which for\n", + " // our purposes (turning an active figure into a static one), is too late.\n", + " var cells = IPython.notebook.get_cells();\n", + " var ncells = cells.length;\n", + " for (var i = 0; i < ncells; i++) {\n", + " var cell = cells[i];\n", + " if (cell.cell_type === 'code') {\n", + " for (var j = 0; j < cell.output_area.outputs.length; j++) {\n", + " var data = cell.output_area.outputs[j];\n", + " if (data.data) {\n", + " // IPython >= 3 moved mimebundle to data attribute of output\n", + " data = data.data;\n", + " }\n", + " if (data['text/html'] === html_output) {\n", + " return [cell, data, j];\n", + " }\n", + " }\n", + " }\n", + " }\n", + "};\n", + "\n", + "// Register the function which deals with the matplotlib target/channel.\n", + "// The kernel may be null if the page has been refreshed.\n", + "if (IPython.notebook.kernel !== null) {\n", + " IPython.notebook.kernel.comm_manager.register_target(\n", + " 'matplotlib',\n", + " mpl.mpl_figure_comm\n", + " );\n", + "}\n" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "%matplotlib notebook\n", + "import matplotlib.pylab as plt\n", + "\n", + "plt.figure()\n", + "ref_trace = cap_pass_trace(\"\\x00\\n\")[0:100]\n", + "plt.plot(ref_trace)\n", + "other_trace = cap_pass_trace(\"c\\n\")[0:100]\n", + "plt.plot(other_trace)\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "This will plot a trace with an input of \"\\x00\" - a null password! This is an invalid character, and seems to be processed as any other invalid password (so the two plots actually look quite the same).\n", + "\n", + "Let's make this a little more obvious, and plot the *difference* between a known (wrong) reference and every other capture. You need to write some code that does something like this:\n", + "\n", + "* Capture a reference trace using a null character\n", + "* For each valid character, capture a trace and plot the difference between this trace and the reference trace\n" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "application/javascript": [ + "/* Put everything inside the global mpl namespace */\n", + "/* global mpl */\n", + "window.mpl = {};\n", + "\n", + "mpl.get_websocket_type = function () {\n", + " if (typeof WebSocket !== 'undefined') {\n", + " return WebSocket;\n", + " } else if (typeof MozWebSocket !== 'undefined') {\n", + " return MozWebSocket;\n", + " } else {\n", + " alert(\n", + " 'Your browser does not have WebSocket support. ' +\n", + " 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n", + " 'Firefox 4 and 5 are also supported but you ' +\n", + " 'have to enable WebSockets in about:config.'\n", + " );\n", + " }\n", + "};\n", + "\n", + "mpl.figure = function (figure_id, websocket, ondownload, parent_element) {\n", + " this.id = figure_id;\n", + "\n", + " this.ws = websocket;\n", + "\n", + " this.supports_binary = this.ws.binaryType !== undefined;\n", + "\n", + " if (!this.supports_binary) {\n", + " var warnings = document.getElementById('mpl-warnings');\n", + " if (warnings) {\n", + " warnings.style.display = 'block';\n", + " warnings.textContent =\n", + " 'This browser does not support binary websocket messages. ' +\n", + " 'Performance may be slow.';\n", + " }\n", + " }\n", + "\n", + " this.imageObj = new Image();\n", + "\n", + " this.context = undefined;\n", + " this.message = undefined;\n", + " this.canvas = undefined;\n", + " this.rubberband_canvas = undefined;\n", + " this.rubberband_context = undefined;\n", + " this.format_dropdown = undefined;\n", + "\n", + " this.image_mode = 'full';\n", + "\n", + " this.root = document.createElement('div');\n", + " this.root.setAttribute('style', 'display: inline-block');\n", + " this._root_extra_style(this.root);\n", + "\n", + " parent_element.appendChild(this.root);\n", + "\n", + " this._init_header(this);\n", + " this._init_canvas(this);\n", + " this._init_toolbar(this);\n", + "\n", + " var fig = this;\n", + "\n", + " this.waiting = false;\n", + "\n", + " this.ws.onopen = function () {\n", + " fig.send_message('supports_binary', { value: fig.supports_binary });\n", + " fig.send_message('send_image_mode', {});\n", + " if (fig.ratio !== 1) {\n", + " fig.send_message('set_dpi_ratio', { dpi_ratio: fig.ratio });\n", + " }\n", + " fig.send_message('refresh', {});\n", + " };\n", + "\n", + " this.imageObj.onload = function () {\n", + " if (fig.image_mode === 'full') {\n", + " // Full images could contain transparency (where diff images\n", + " // almost always do), so we need to clear the canvas so that\n", + " // there is no ghosting.\n", + " fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n", + " }\n", + " fig.context.drawImage(fig.imageObj, 0, 0);\n", + " };\n", + "\n", + " this.imageObj.onunload = function () {\n", + " fig.ws.close();\n", + " };\n", + "\n", + " this.ws.onmessage = this._make_on_message_function(this);\n", + "\n", + " this.ondownload = ondownload;\n", + "};\n", + "\n", + "mpl.figure.prototype._init_header = function () {\n", + " var titlebar = document.createElement('div');\n", + " titlebar.classList =\n", + " 'ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix';\n", + " var titletext = document.createElement('div');\n", + " titletext.classList = 'ui-dialog-title';\n", + " titletext.setAttribute(\n", + " 'style',\n", + " 'width: 100%; text-align: center; padding: 3px;'\n", + " );\n", + " titlebar.appendChild(titletext);\n", + " this.root.appendChild(titlebar);\n", + " this.header = titletext;\n", + "};\n", + "\n", + "mpl.figure.prototype._canvas_extra_style = function (_canvas_div) {};\n", + "\n", + "mpl.figure.prototype._root_extra_style = function (_canvas_div) {};\n", + "\n", + "mpl.figure.prototype._init_canvas = function () {\n", + " var fig = this;\n", + "\n", + " var canvas_div = (this.canvas_div = document.createElement('div'));\n", + " canvas_div.setAttribute(\n", + " 'style',\n", + " 'border: 1px solid #ddd;' +\n", + " 'box-sizing: content-box;' +\n", + " 'clear: both;' +\n", + " 'min-height: 1px;' +\n", + " 'min-width: 1px;' +\n", + " 'outline: 0;' +\n", + " 'overflow: hidden;' +\n", + " 'position: relative;' +\n", + " 'resize: both;'\n", + " );\n", + "\n", + " function on_keyboard_event_closure(name) {\n", + " return function (event) {\n", + " return fig.key_event(event, name);\n", + " };\n", + " }\n", + "\n", + " canvas_div.addEventListener(\n", + " 'keydown',\n", + " on_keyboard_event_closure('key_press')\n", + " );\n", + " canvas_div.addEventListener(\n", + " 'keyup',\n", + " on_keyboard_event_closure('key_release')\n", + " );\n", + "\n", + " this._canvas_extra_style(canvas_div);\n", + " this.root.appendChild(canvas_div);\n", + "\n", + " var canvas = (this.canvas = document.createElement('canvas'));\n", + " canvas.classList.add('mpl-canvas');\n", + " canvas.setAttribute('style', 'box-sizing: content-box;');\n", + "\n", + " this.context = canvas.getContext('2d');\n", + "\n", + " var backingStore =\n", + " this.context.backingStorePixelRatio ||\n", + " this.context.webkitBackingStorePixelRatio ||\n", + " this.context.mozBackingStorePixelRatio ||\n", + " this.context.msBackingStorePixelRatio ||\n", + " this.context.oBackingStorePixelRatio ||\n", + " this.context.backingStorePixelRatio ||\n", + " 1;\n", + "\n", + " this.ratio = (window.devicePixelRatio || 1) / backingStore;\n", + "\n", + " var rubberband_canvas = (this.rubberband_canvas = document.createElement(\n", + " 'canvas'\n", + " ));\n", + " rubberband_canvas.setAttribute(\n", + " 'style',\n", + " 'box-sizing: content-box; position: absolute; left: 0; top: 0; z-index: 1;'\n", + " );\n", + "\n", + " // Apply a ponyfill if ResizeObserver is not implemented by browser.\n", + " if (this.ResizeObserver === undefined) {\n", + " if (window.ResizeObserver !== undefined) {\n", + " this.ResizeObserver = window.ResizeObserver;\n", + " } else {\n", + " var obs = _JSXTOOLS_RESIZE_OBSERVER({});\n", + " this.ResizeObserver = obs.ResizeObserver;\n", + " }\n", + " }\n", + "\n", + " this.resizeObserverInstance = new this.ResizeObserver(function (entries) {\n", + " var nentries = entries.length;\n", + " for (var i = 0; i < nentries; i++) {\n", + " var entry = entries[i];\n", + " var width, height;\n", + " if (entry.contentBoxSize) {\n", + " if (entry.contentBoxSize instanceof Array) {\n", + " // Chrome 84 implements new version of spec.\n", + " width = entry.contentBoxSize[0].inlineSize;\n", + " height = entry.contentBoxSize[0].blockSize;\n", + " } else {\n", + " // Firefox implements old version of spec.\n", + " width = entry.contentBoxSize.inlineSize;\n", + " height = entry.contentBoxSize.blockSize;\n", + " }\n", + " } else {\n", + " // Chrome <84 implements even older version of spec.\n", + " width = entry.contentRect.width;\n", + " height = entry.contentRect.height;\n", + " }\n", + "\n", + " // Keep the size of the canvas and rubber band canvas in sync with\n", + " // the canvas container.\n", + " if (entry.devicePixelContentBoxSize) {\n", + " // Chrome 84 implements new version of spec.\n", + " canvas.setAttribute(\n", + " 'width',\n", + " entry.devicePixelContentBoxSize[0].inlineSize\n", + " );\n", + " canvas.setAttribute(\n", + " 'height',\n", + " entry.devicePixelContentBoxSize[0].blockSize\n", + " );\n", + " } else {\n", + " canvas.setAttribute('width', width * fig.ratio);\n", + " canvas.setAttribute('height', height * fig.ratio);\n", + " }\n", + " canvas.setAttribute(\n", + " 'style',\n", + " 'width: ' + width + 'px; height: ' + height + 'px;'\n", + " );\n", + "\n", + " rubberband_canvas.setAttribute('width', width);\n", + " rubberband_canvas.setAttribute('height', height);\n", + "\n", + " // And update the size in Python. We ignore the initial 0/0 size\n", + " // that occurs as the element is placed into the DOM, which should\n", + " // otherwise not happen due to the minimum size styling.\n", + " if (fig.ws.readyState == 1 && width != 0 && height != 0) {\n", + " fig.request_resize(width, height);\n", + " }\n", + " }\n", + " });\n", + " this.resizeObserverInstance.observe(canvas_div);\n", + "\n", + " function on_mouse_event_closure(name) {\n", + " return function (event) {\n", + " return fig.mouse_event(event, name);\n", + " };\n", + " }\n", + "\n", + " rubberband_canvas.addEventListener(\n", + " 'mousedown',\n", + " on_mouse_event_closure('button_press')\n", + " );\n", + " rubberband_canvas.addEventListener(\n", + " 'mouseup',\n", + " on_mouse_event_closure('button_release')\n", + " );\n", + " // Throttle sequential mouse events to 1 every 20ms.\n", + " rubberband_canvas.addEventListener(\n", + " 'mousemove',\n", + " on_mouse_event_closure('motion_notify')\n", + " );\n", + "\n", + " rubberband_canvas.addEventListener(\n", + " 'mouseenter',\n", + " on_mouse_event_closure('figure_enter')\n", + " );\n", + " rubberband_canvas.addEventListener(\n", + " 'mouseleave',\n", + " on_mouse_event_closure('figure_leave')\n", + " );\n", + "\n", + " canvas_div.addEventListener('wheel', function (event) {\n", + " if (event.deltaY < 0) {\n", + " event.step = 1;\n", + " } else {\n", + " event.step = -1;\n", + " }\n", + " on_mouse_event_closure('scroll')(event);\n", + " });\n", + "\n", + " canvas_div.appendChild(canvas);\n", + " canvas_div.appendChild(rubberband_canvas);\n", + "\n", + " this.rubberband_context = rubberband_canvas.getContext('2d');\n", + " this.rubberband_context.strokeStyle = '#000000';\n", + "\n", + " this._resize_canvas = function (width, height, forward) {\n", + " if (forward) {\n", + " canvas_div.style.width = width + 'px';\n", + " canvas_div.style.height = height + 'px';\n", + " }\n", + " };\n", + "\n", + " // Disable right mouse context menu.\n", + " this.rubberband_canvas.addEventListener('contextmenu', function (_e) {\n", + " event.preventDefault();\n", + " return false;\n", + " });\n", + "\n", + " function set_focus() {\n", + " canvas.focus();\n", + " canvas_div.focus();\n", + " }\n", + "\n", + " window.setTimeout(set_focus, 100);\n", + "};\n", + "\n", + "mpl.figure.prototype._init_toolbar = function () {\n", + " var fig = this;\n", + "\n", + " var toolbar = document.createElement('div');\n", + " toolbar.classList = 'mpl-toolbar';\n", + " this.root.appendChild(toolbar);\n", + "\n", + " function on_click_closure(name) {\n", + " return function (_event) {\n", + " return fig.toolbar_button_onclick(name);\n", + " };\n", + " }\n", + "\n", + " function on_mouseover_closure(tooltip) {\n", + " return function (event) {\n", + " if (!event.currentTarget.disabled) {\n", + " return fig.toolbar_button_onmouseover(tooltip);\n", + " }\n", + " };\n", + " }\n", + "\n", + " fig.buttons = {};\n", + " var buttonGroup = document.createElement('div');\n", + " buttonGroup.classList = 'mpl-button-group';\n", + " for (var toolbar_ind in mpl.toolbar_items) {\n", + " var name = mpl.toolbar_items[toolbar_ind][0];\n", + " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n", + " var image = mpl.toolbar_items[toolbar_ind][2];\n", + " var method_name = mpl.toolbar_items[toolbar_ind][3];\n", + "\n", + " if (!name) {\n", + " /* Instead of a spacer, we start a new button group. */\n", + " if (buttonGroup.hasChildNodes()) {\n", + " toolbar.appendChild(buttonGroup);\n", + " }\n", + " buttonGroup = document.createElement('div');\n", + " buttonGroup.classList = 'mpl-button-group';\n", + " continue;\n", + " }\n", + "\n", + " var button = (fig.buttons[name] = document.createElement('button'));\n", + " button.classList = 'mpl-widget';\n", + " button.setAttribute('role', 'button');\n", + " button.setAttribute('aria-disabled', 'false');\n", + " button.addEventListener('click', on_click_closure(method_name));\n", + " button.addEventListener('mouseover', on_mouseover_closure(tooltip));\n", + "\n", + " var icon_img = document.createElement('img');\n", + " icon_img.src = '_images/' + image + '.png';\n", + " icon_img.srcset = '_images/' + image + '_large.png 2x';\n", + " icon_img.alt = tooltip;\n", + " button.appendChild(icon_img);\n", + "\n", + " buttonGroup.appendChild(button);\n", + " }\n", + "\n", + " if (buttonGroup.hasChildNodes()) {\n", + " toolbar.appendChild(buttonGroup);\n", + " }\n", + "\n", + " var fmt_picker = document.createElement('select');\n", + " fmt_picker.classList = 'mpl-widget';\n", + " toolbar.appendChild(fmt_picker);\n", + " this.format_dropdown = fmt_picker;\n", + "\n", + " for (var ind in mpl.extensions) {\n", + " var fmt = mpl.extensions[ind];\n", + " var option = document.createElement('option');\n", + " option.selected = fmt === mpl.default_extension;\n", + " option.innerHTML = fmt;\n", + " fmt_picker.appendChild(option);\n", + " }\n", + "\n", + " var status_bar = document.createElement('span');\n", + " status_bar.classList = 'mpl-message';\n", + " toolbar.appendChild(status_bar);\n", + " this.message = status_bar;\n", + "};\n", + "\n", + "mpl.figure.prototype.request_resize = function (x_pixels, y_pixels) {\n", + " // Request matplotlib to resize the figure. Matplotlib will then trigger a resize in the client,\n", + " // which will in turn request a refresh of the image.\n", + " this.send_message('resize', { width: x_pixels, height: y_pixels });\n", + "};\n", + "\n", + "mpl.figure.prototype.send_message = function (type, properties) {\n", + " properties['type'] = type;\n", + " properties['figure_id'] = this.id;\n", + " this.ws.send(JSON.stringify(properties));\n", + "};\n", + "\n", + "mpl.figure.prototype.send_draw_message = function () {\n", + " if (!this.waiting) {\n", + " this.waiting = true;\n", + " this.ws.send(JSON.stringify({ type: 'draw', figure_id: this.id }));\n", + " }\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_save = function (fig, _msg) {\n", + " var format_dropdown = fig.format_dropdown;\n", + " var format = format_dropdown.options[format_dropdown.selectedIndex].value;\n", + " fig.ondownload(fig, format);\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_resize = function (fig, msg) {\n", + " var size = msg['size'];\n", + " if (size[0] !== fig.canvas.width || size[1] !== fig.canvas.height) {\n", + " fig._resize_canvas(size[0], size[1], msg['forward']);\n", + " fig.send_message('refresh', {});\n", + " }\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_rubberband = function (fig, msg) {\n", + " var x0 = msg['x0'] / fig.ratio;\n", + " var y0 = (fig.canvas.height - msg['y0']) / fig.ratio;\n", + " var x1 = msg['x1'] / fig.ratio;\n", + " var y1 = (fig.canvas.height - msg['y1']) / fig.ratio;\n", + " x0 = Math.floor(x0) + 0.5;\n", + " y0 = Math.floor(y0) + 0.5;\n", + " x1 = Math.floor(x1) + 0.5;\n", + " y1 = Math.floor(y1) + 0.5;\n", + " var min_x = Math.min(x0, x1);\n", + " var min_y = Math.min(y0, y1);\n", + " var width = Math.abs(x1 - x0);\n", + " var height = Math.abs(y1 - y0);\n", + "\n", + " fig.rubberband_context.clearRect(\n", + " 0,\n", + " 0,\n", + " fig.canvas.width / fig.ratio,\n", + " fig.canvas.height / fig.ratio\n", + " );\n", + "\n", + " fig.rubberband_context.strokeRect(min_x, min_y, width, height);\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_figure_label = function (fig, msg) {\n", + " // Updates the figure title.\n", + " fig.header.textContent = msg['label'];\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_cursor = function (fig, msg) {\n", + " var cursor = msg['cursor'];\n", + " switch (cursor) {\n", + " case 0:\n", + " cursor = 'pointer';\n", + " break;\n", + " case 1:\n", + " cursor = 'default';\n", + " break;\n", + " case 2:\n", + " cursor = 'crosshair';\n", + " break;\n", + " case 3:\n", + " cursor = 'move';\n", + " break;\n", + " }\n", + " fig.rubberband_canvas.style.cursor = cursor;\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_message = function (fig, msg) {\n", + " fig.message.textContent = msg['message'];\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_draw = function (fig, _msg) {\n", + " // Request the server to send over a new figure.\n", + " fig.send_draw_message();\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_image_mode = function (fig, msg) {\n", + " fig.image_mode = msg['mode'];\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_history_buttons = function (fig, msg) {\n", + " for (var key in msg) {\n", + " if (!(key in fig.buttons)) {\n", + " continue;\n", + " }\n", + " fig.buttons[key].disabled = !msg[key];\n", + " fig.buttons[key].setAttribute('aria-disabled', !msg[key]);\n", + " }\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_navigate_mode = function (fig, msg) {\n", + " if (msg['mode'] === 'PAN') {\n", + " fig.buttons['Pan'].classList.add('active');\n", + " fig.buttons['Zoom'].classList.remove('active');\n", + " } else if (msg['mode'] === 'ZOOM') {\n", + " fig.buttons['Pan'].classList.remove('active');\n", + " fig.buttons['Zoom'].classList.add('active');\n", + " } else {\n", + " fig.buttons['Pan'].classList.remove('active');\n", + " fig.buttons['Zoom'].classList.remove('active');\n", + " }\n", + "};\n", + "\n", + "mpl.figure.prototype.updated_canvas_event = function () {\n", + " // Called whenever the canvas gets updated.\n", + " this.send_message('ack', {});\n", + "};\n", + "\n", + "// A function to construct a web socket function for onmessage handling.\n", + "// Called in the figure constructor.\n", + "mpl.figure.prototype._make_on_message_function = function (fig) {\n", + " return function socket_on_message(evt) {\n", + " if (evt.data instanceof Blob) {\n", + " /* FIXME: We get \"Resource interpreted as Image but\n", + " * transferred with MIME type text/plain:\" errors on\n", + " * Chrome. But how to set the MIME type? It doesn't seem\n", + " * to be part of the websocket stream */\n", + " evt.data.type = 'image/png';\n", + "\n", + " /* Free the memory for the previous frames */\n", + " if (fig.imageObj.src) {\n", + " (window.URL || window.webkitURL).revokeObjectURL(\n", + " fig.imageObj.src\n", + " );\n", + " }\n", + "\n", + " fig.imageObj.src = (window.URL || window.webkitURL).createObjectURL(\n", + " evt.data\n", + " );\n", + " fig.updated_canvas_event();\n", + " fig.waiting = false;\n", + " return;\n", + " } else if (\n", + " typeof evt.data === 'string' &&\n", + " evt.data.slice(0, 21) === 'data:image/png;base64'\n", + " ) {\n", + " fig.imageObj.src = evt.data;\n", + " fig.updated_canvas_event();\n", + " fig.waiting = false;\n", + " return;\n", + " }\n", + "\n", + " var msg = JSON.parse(evt.data);\n", + " var msg_type = msg['type'];\n", + "\n", + " // Call the \"handle_{type}\" callback, which takes\n", + " // the figure and JSON message as its only arguments.\n", + " try {\n", + " var callback = fig['handle_' + msg_type];\n", + " } catch (e) {\n", + " console.log(\n", + " \"No handler for the '\" + msg_type + \"' message type: \",\n", + " msg\n", + " );\n", + " return;\n", + " }\n", + "\n", + " if (callback) {\n", + " try {\n", + " // console.log(\"Handling '\" + msg_type + \"' message: \", msg);\n", + " callback(fig, msg);\n", + " } catch (e) {\n", + " console.log(\n", + " \"Exception inside the 'handler_\" + msg_type + \"' callback:\",\n", + " e,\n", + " e.stack,\n", + " msg\n", + " );\n", + " }\n", + " }\n", + " };\n", + "};\n", + "\n", + "// from http://stackoverflow.com/questions/1114465/getting-mouse-location-in-canvas\n", + "mpl.findpos = function (e) {\n", + " //this section is from http://www.quirksmode.org/js/events_properties.html\n", + " var targ;\n", + " if (!e) {\n", + " e = window.event;\n", + " }\n", + " if (e.target) {\n", + " targ = e.target;\n", + " } else if (e.srcElement) {\n", + " targ = e.srcElement;\n", + " }\n", + " if (targ.nodeType === 3) {\n", + " // defeat Safari bug\n", + " targ = targ.parentNode;\n", + " }\n", + "\n", + " // pageX,Y are the mouse positions relative to the document\n", + " var boundingRect = targ.getBoundingClientRect();\n", + " var x = e.pageX - (boundingRect.left + document.body.scrollLeft);\n", + " var y = e.pageY - (boundingRect.top + document.body.scrollTop);\n", + "\n", + " return { x: x, y: y };\n", + "};\n", + "\n", + "/*\n", + " * return a copy of an object with only non-object keys\n", + " * we need this to avoid circular references\n", + " * http://stackoverflow.com/a/24161582/3208463\n", + " */\n", + "function simpleKeys(original) {\n", + " return Object.keys(original).reduce(function (obj, key) {\n", + " if (typeof original[key] !== 'object') {\n", + " obj[key] = original[key];\n", + " }\n", + " return obj;\n", + " }, {});\n", + "}\n", + "\n", + "mpl.figure.prototype.mouse_event = function (event, name) {\n", + " var canvas_pos = mpl.findpos(event);\n", + "\n", + " if (name === 'button_press') {\n", + " this.canvas.focus();\n", + " this.canvas_div.focus();\n", + " }\n", + "\n", + " var x = canvas_pos.x * this.ratio;\n", + " var y = canvas_pos.y * this.ratio;\n", + "\n", + " this.send_message(name, {\n", + " x: x,\n", + " y: y,\n", + " button: event.button,\n", + " step: event.step,\n", + " guiEvent: simpleKeys(event),\n", + " });\n", + "\n", + " /* This prevents the web browser from automatically changing to\n", + " * the text insertion cursor when the button is pressed. We want\n", + " * to control all of the cursor setting manually through the\n", + " * 'cursor' event from matplotlib */\n", + " event.preventDefault();\n", + " return false;\n", + "};\n", + "\n", + "mpl.figure.prototype._key_event_extra = function (_event, _name) {\n", + " // Handle any extra behaviour associated with a key event\n", + "};\n", + "\n", + "mpl.figure.prototype.key_event = function (event, name) {\n", + " // Prevent repeat events\n", + " if (name === 'key_press') {\n", + " if (event.which === this._key) {\n", + " return;\n", + " } else {\n", + " this._key = event.which;\n", + " }\n", + " }\n", + " if (name === 'key_release') {\n", + " this._key = null;\n", + " }\n", + "\n", + " var value = '';\n", + " if (event.ctrlKey && event.which !== 17) {\n", + " value += 'ctrl+';\n", + " }\n", + " if (event.altKey && event.which !== 18) {\n", + " value += 'alt+';\n", + " }\n", + " if (event.shiftKey && event.which !== 16) {\n", + " value += 'shift+';\n", + " }\n", + "\n", + " value += 'k';\n", + " value += event.which.toString();\n", + "\n", + " this._key_event_extra(event, name);\n", + "\n", + " this.send_message(name, { key: value, guiEvent: simpleKeys(event) });\n", + " return false;\n", + "};\n", + "\n", + "mpl.figure.prototype.toolbar_button_onclick = function (name) {\n", + " if (name === 'download') {\n", + " this.handle_save(this, null);\n", + " } else {\n", + " this.send_message('toolbar_button', { name: name });\n", + " }\n", + "};\n", + "\n", + "mpl.figure.prototype.toolbar_button_onmouseover = function (tooltip) {\n", + " this.message.textContent = tooltip;\n", + "};\n", + "\n", + "///////////////// REMAINING CONTENT GENERATED BY embed_js.py /////////////////\n", + "// prettier-ignore\n", + "var _JSXTOOLS_RESIZE_OBSERVER=function(A){var t,i=new WeakMap,n=new WeakMap,a=new WeakMap,r=new WeakMap,o=new Set;function s(e){if(!(this instanceof s))throw new TypeError(\"Constructor requires 'new' operator\");i.set(this,e)}function h(){throw new TypeError(\"Function is not a constructor\")}function c(e,t,i,n){e=0 in arguments?Number(arguments[0]):0,t=1 in arguments?Number(arguments[1]):0,i=2 in arguments?Number(arguments[2]):0,n=3 in arguments?Number(arguments[3]):0,this.right=(this.x=this.left=e)+(this.width=i),this.bottom=(this.y=this.top=t)+(this.height=n),Object.freeze(this)}function d(){t=requestAnimationFrame(d);var s=new WeakMap,p=new Set;o.forEach((function(t){r.get(t).forEach((function(i){var r=t instanceof window.SVGElement,o=a.get(t),d=r?0:parseFloat(o.paddingTop),f=r?0:parseFloat(o.paddingRight),l=r?0:parseFloat(o.paddingBottom),u=r?0:parseFloat(o.paddingLeft),g=r?0:parseFloat(o.borderTopWidth),m=r?0:parseFloat(o.borderRightWidth),w=r?0:parseFloat(o.borderBottomWidth),b=u+f,F=d+l,v=(r?0:parseFloat(o.borderLeftWidth))+m,W=g+w,y=r?0:t.offsetHeight-W-t.clientHeight,E=r?0:t.offsetWidth-v-t.clientWidth,R=b+v,z=F+W,M=r?t.width:parseFloat(o.width)-R-E,O=r?t.height:parseFloat(o.height)-z-y;if(n.has(t)){var k=n.get(t);if(k[0]===M&&k[1]===O)return}n.set(t,[M,O]);var S=Object.create(h.prototype);S.target=t,S.contentRect=new c(u,d,M,O),s.has(i)||(s.set(i,[]),p.add(i)),s.get(i).push(S)}))})),p.forEach((function(e){i.get(e).call(e,s.get(e),e)}))}return s.prototype.observe=function(i){if(i instanceof window.Element){r.has(i)||(r.set(i,new Set),o.add(i),a.set(i,window.getComputedStyle(i)));var n=r.get(i);n.has(this)||n.add(this),cancelAnimationFrame(t),t=requestAnimationFrame(d)}},s.prototype.unobserve=function(i){if(i instanceof window.Element&&r.has(i)){var n=r.get(i);n.has(this)&&(n.delete(this),n.size||(r.delete(i),o.delete(i))),n.size||r.delete(i),o.size||cancelAnimationFrame(t)}},A.DOMRectReadOnly=c,A.ResizeObserver=s,A.ResizeObserverEntry=h,A}; // eslint-disable-line\n", + "mpl.toolbar_items = [[\"Home\", \"Reset original view\", \"fa fa-home icon-home\", \"home\"], [\"Back\", \"Back to previous view\", \"fa fa-arrow-left icon-arrow-left\", \"back\"], [\"Forward\", \"Forward to next view\", \"fa fa-arrow-right icon-arrow-right\", \"forward\"], [\"\", \"\", \"\", \"\"], [\"Pan\", \"Left button pans, Right button zooms\\nx/y fixes axis, CTRL fixes aspect\", \"fa fa-arrows icon-move\", \"pan\"], [\"Zoom\", \"Zoom to rectangle\\nx/y fixes axis, CTRL fixes aspect\", \"fa fa-square-o icon-check-empty\", \"zoom\"], [\"\", \"\", \"\", \"\"], [\"Download\", \"Download plot\", \"fa fa-floppy-o icon-save\", \"download\"]];\n", + "\n", + "mpl.extensions = [\"eps\", \"jpeg\", \"pdf\", \"png\", \"ps\", \"raw\", \"svg\", \"tif\"];\n", + "\n", + "mpl.default_extension = \"png\";/* global mpl */\n", + "\n", + "var comm_websocket_adapter = function (comm) {\n", + " // Create a \"websocket\"-like object which calls the given IPython comm\n", + " // object with the appropriate methods. Currently this is a non binary\n", + " // socket, so there is still some room for performance tuning.\n", + " var ws = {};\n", + "\n", + " ws.close = function () {\n", + " comm.close();\n", + " };\n", + " ws.send = function (m) {\n", + " //console.log('sending', m);\n", + " comm.send(m);\n", + " };\n", + " // Register the callback with on_msg.\n", + " comm.on_msg(function (msg) {\n", + " //console.log('receiving', msg['content']['data'], msg);\n", + " // Pass the mpl event to the overridden (by mpl) onmessage function.\n", + " ws.onmessage(msg['content']['data']);\n", + " });\n", + " return ws;\n", + "};\n", + "\n", + "mpl.mpl_figure_comm = function (comm, msg) {\n", + " // This is the function which gets called when the mpl process\n", + " // starts-up an IPython Comm through the \"matplotlib\" channel.\n", + "\n", + " var id = msg.content.data.id;\n", + " // Get hold of the div created by the display call when the Comm\n", + " // socket was opened in Python.\n", + " var element = document.getElementById(id);\n", + " var ws_proxy = comm_websocket_adapter(comm);\n", + "\n", + " function ondownload(figure, _format) {\n", + " window.open(figure.canvas.toDataURL());\n", + " }\n", + "\n", + " var fig = new mpl.figure(id, ws_proxy, ondownload, element);\n", + "\n", + " // Call onopen now - mpl needs it, as it is assuming we've passed it a real\n", + " // web socket which is closed, not our websocket->open comm proxy.\n", + " ws_proxy.onopen();\n", + "\n", + " fig.parent_element = element;\n", + " fig.cell_info = mpl.find_output_cell(\"
\");\n", + " if (!fig.cell_info) {\n", + " console.error('Failed to find cell for figure', id, fig);\n", + " return;\n", + " }\n", + " fig.cell_info[0].output_area.element.on(\n", + " 'cleared',\n", + " { fig: fig },\n", + " fig._remove_fig_handler\n", + " );\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_close = function (fig, msg) {\n", + " var width = fig.canvas.width / fig.ratio;\n", + " fig.cell_info[0].output_area.element.off(\n", + " 'cleared',\n", + " fig._remove_fig_handler\n", + " );\n", + " fig.resizeObserverInstance.unobserve(fig.canvas_div);\n", + "\n", + " // Update the output cell to use the data from the current canvas.\n", + " fig.push_to_output();\n", + " var dataURL = fig.canvas.toDataURL();\n", + " // Re-enable the keyboard manager in IPython - without this line, in FF,\n", + " // the notebook keyboard shortcuts fail.\n", + " IPython.keyboard_manager.enable();\n", + " fig.parent_element.innerHTML =\n", + " '';\n", + " fig.close_ws(fig, msg);\n", + "};\n", + "\n", + "mpl.figure.prototype.close_ws = function (fig, msg) {\n", + " fig.send_message('closing', msg);\n", + " // fig.ws.close()\n", + "};\n", + "\n", + "mpl.figure.prototype.push_to_output = function (_remove_interactive) {\n", + " // Turn the data on the canvas into data in the output cell.\n", + " var width = this.canvas.width / this.ratio;\n", + " var dataURL = this.canvas.toDataURL();\n", + " this.cell_info[1]['text/html'] =\n", + " '';\n", + "};\n", + "\n", + "mpl.figure.prototype.updated_canvas_event = function () {\n", + " // Tell IPython that the notebook contents must change.\n", + " IPython.notebook.set_dirty(true);\n", + " this.send_message('ack', {});\n", + " var fig = this;\n", + " // Wait a second, then push the new image to the DOM so\n", + " // that it is saved nicely (might be nice to debounce this).\n", + " setTimeout(function () {\n", + " fig.push_to_output();\n", + " }, 1000);\n", + "};\n", + "\n", + "mpl.figure.prototype._init_toolbar = function () {\n", + " var fig = this;\n", + "\n", + " var toolbar = document.createElement('div');\n", + " toolbar.classList = 'btn-toolbar';\n", + " this.root.appendChild(toolbar);\n", + "\n", + " function on_click_closure(name) {\n", + " return function (_event) {\n", + " return fig.toolbar_button_onclick(name);\n", + " };\n", + " }\n", + "\n", + " function on_mouseover_closure(tooltip) {\n", + " return function (event) {\n", + " if (!event.currentTarget.disabled) {\n", + " return fig.toolbar_button_onmouseover(tooltip);\n", + " }\n", + " };\n", + " }\n", + "\n", + " fig.buttons = {};\n", + " var buttonGroup = document.createElement('div');\n", + " buttonGroup.classList = 'btn-group';\n", + " var button;\n", + " for (var toolbar_ind in mpl.toolbar_items) {\n", + " var name = mpl.toolbar_items[toolbar_ind][0];\n", + " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n", + " var image = mpl.toolbar_items[toolbar_ind][2];\n", + " var method_name = mpl.toolbar_items[toolbar_ind][3];\n", + "\n", + " if (!name) {\n", + " /* Instead of a spacer, we start a new button group. */\n", + " if (buttonGroup.hasChildNodes()) {\n", + " toolbar.appendChild(buttonGroup);\n", + " }\n", + " buttonGroup = document.createElement('div');\n", + " buttonGroup.classList = 'btn-group';\n", + " continue;\n", + " }\n", + "\n", + " button = fig.buttons[name] = document.createElement('button');\n", + " button.classList = 'btn btn-default';\n", + " button.href = '#';\n", + " button.title = name;\n", + " button.innerHTML = '';\n", + " button.addEventListener('click', on_click_closure(method_name));\n", + " button.addEventListener('mouseover', on_mouseover_closure(tooltip));\n", + " buttonGroup.appendChild(button);\n", + " }\n", + "\n", + " if (buttonGroup.hasChildNodes()) {\n", + " toolbar.appendChild(buttonGroup);\n", + " }\n", + "\n", + " // Add the status bar.\n", + " var status_bar = document.createElement('span');\n", + " status_bar.classList = 'mpl-message pull-right';\n", + " toolbar.appendChild(status_bar);\n", + " this.message = status_bar;\n", + "\n", + " // Add the close button to the window.\n", + " var buttongrp = document.createElement('div');\n", + " buttongrp.classList = 'btn-group inline pull-right';\n", + " button = document.createElement('button');\n", + " button.classList = 'btn btn-mini btn-primary';\n", + " button.href = '#';\n", + " button.title = 'Stop Interaction';\n", + " button.innerHTML = '';\n", + " button.addEventListener('click', function (_evt) {\n", + " fig.handle_close(fig, {});\n", + " });\n", + " button.addEventListener(\n", + " 'mouseover',\n", + " on_mouseover_closure('Stop Interaction')\n", + " );\n", + " buttongrp.appendChild(button);\n", + " var titlebar = this.root.querySelector('.ui-dialog-titlebar');\n", + " titlebar.insertBefore(buttongrp, titlebar.firstChild);\n", + "};\n", + "\n", + "mpl.figure.prototype._remove_fig_handler = function (event) {\n", + " var fig = event.data.fig;\n", + " if (event.target !== this) {\n", + " // Ignore bubbled events from children.\n", + " return;\n", + " }\n", + " fig.close_ws(fig, {});\n", + "};\n", + "\n", + "mpl.figure.prototype._root_extra_style = function (el) {\n", + " el.style.boxSizing = 'content-box'; // override notebook setting of border-box.\n", + "};\n", + "\n", + "mpl.figure.prototype._canvas_extra_style = function (el) {\n", + " // this is important to make the div 'focusable\n", + " el.setAttribute('tabindex', 0);\n", + " // reach out to IPython and tell the keyboard manager to turn it's self\n", + " // off when our div gets focus\n", + "\n", + " // location in version 3\n", + " if (IPython.notebook.keyboard_manager) {\n", + " IPython.notebook.keyboard_manager.register_events(el);\n", + " } else {\n", + " // location in version 2\n", + " IPython.keyboard_manager.register_events(el);\n", + " }\n", + "};\n", + "\n", + "mpl.figure.prototype._key_event_extra = function (event, _name) {\n", + " var manager = IPython.notebook.keyboard_manager;\n", + " if (!manager) {\n", + " manager = IPython.keyboard_manager;\n", + " }\n", + "\n", + " // Check for shift+enter\n", + " if (event.shiftKey && event.which === 13) {\n", + " this.canvas_div.blur();\n", + " // select the cell after this one\n", + " var index = IPython.notebook.find_cell_index(this.cell_info[0]);\n", + " IPython.notebook.select(index + 1);\n", + " }\n", + "};\n", + "\n", + "mpl.figure.prototype.handle_save = function (fig, _msg) {\n", + " fig.ondownload(fig, null);\n", + "};\n", + "\n", + "mpl.find_output_cell = function (html_output) {\n", + " // Return the cell and output element which can be found *uniquely* in the notebook.\n", + " // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n", + " // IPython event is triggered only after the cells have been serialised, which for\n", + " // our purposes (turning an active figure into a static one), is too late.\n", + " var cells = IPython.notebook.get_cells();\n", + " var ncells = cells.length;\n", + " for (var i = 0; i < ncells; i++) {\n", + " var cell = cells[i];\n", + " if (cell.cell_type === 'code') {\n", + " for (var j = 0; j < cell.output_area.outputs.length; j++) {\n", + " var data = cell.output_area.outputs[j];\n", + " if (data.data) {\n", + " // IPython >= 3 moved mimebundle to data attribute of output\n", + " data = data.data;\n", + " }\n", + " if (data['text/html'] === html_output) {\n", + " return [cell, data, j];\n", + " }\n", + " }\n", + " }\n", + " }\n", + "};\n", + "\n", + "// Register the function which deals with the matplotlib target/channel.\n", + "// The kernel may be null if the page has been refreshed.\n", + "if (IPython.notebook.kernel !== null) {\n", + " IPython.notebook.kernel.comm_manager.register_target(\n", + " 'matplotlib',\n", + " mpl.mpl_figure_comm\n", + " );\n", + "}\n" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "%matplotlib notebook\n", + "import matplotlib.pylab as plt\n", + "\n", + "alphabet = 'abcdefghijklmnopqrstuvwxyz0123456789'\n", + "\n", + "plt.figure()\n", + "\n", + "# FIXME: Your code goes here\n", + "ref_trace = cap_pass_trace(\"\\x00\\n\")[0:100]\n", + "\n", + "for i in alphabet:\n", + " plt.plot(cap_pass_trace(i)[0:100] - ref_trace)\n", + " \n", + "plt.legend(alphabet)\n", + " \n", + "plt.show() " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "OK great - hopefully you now see one major \"difference\". It should look something like this:\n", + " \n", + "\"SPA\n", + " " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "What to do now? Let's make this thing *automatically detect* such a large difference. The idea is to define a *metric* that gives us an estimate on the difference between two traces, i.e. you need to write a function returning a single (integer or floating point) value which reflects this notion. Taking your above loop, modify it to print an indicator of how closely this matches your reference trace. Copy and paste your previous solution and print out the value of our metric for each character:" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n" + ] + } + ], + "source": [ + "import numpy as np\n", + "\n", + "# Define metric for the difference between two traces\n", + "def trace_diff(trace1, trace2):\n", + " \n", + " # FIXME: Your code goes here\n", + " return sum(abs(cap_pass_trace(trace1)[0:100] - cap_pass_trace(trace2)[0:100]))\n", + "\n", + "# FIXME: Your code goes here\n", + "alphabet = 'abcdefghijklmnopqrstuvwxyz0123456789'\n", + " \n", + "for i in alphabet:\n", + " if(trace_diff(\"h\"+i,\"h\" + \"\\x00\\n\")> 2):\n", + " print(i)\n", + " " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now the easy part - modify your above code to automatically print the correct password character. This should be done with a comparison of the computed metric - based on the printed characters, you should see one that is 'higher' than the others. There is basically two solutions to this:\n", + "\n", + "* Compute the metric for all characters and then choose the maximum value\n", + "* Set a threshold somewhere reasonable (say I might use `25.0` based on one run) and choose the first character for which the metric exceeds the threshold\n", + "\n", + "While the first solution is more reliable (the threshold may vary with the measurements or later on with the number of guessed characters), the second one is potentially faster, since we can skip parts of the measurements. If you like, you can try both of them and see what works best for you." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Running a Full Attack" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Finally - let's finish this off. Rather than attacking a single character, we need to attack each character in sequence.\n", + "\n", + "If you go back to the plotting of differences, you can try using the correct first character & wrong second character. The basic idea is exactly the same as before, but now we loop through 5 times (assuming that the password has exactly 5 characters), and just build up the password based on brute-forcing each character." + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "49.734375\n", + "r\n", + "51.01953125\n", + "rb\n", + "51.6015625\n", + "rb4\n", + "49.00390625\n", + "rb4w\n", + "55.69140625\n", + "rb4wo\n", + "Access granted, Welcome!\n", + "https://perso.telecom-paristech.fr/ukuhne/IWCLQFVAWDB2UHBMA3DITK4AOMFEJTMA/\n" + ] + } + ], + "source": [ + "guessed_pw = \"\"\n", + "\n", + "# FIXME: Your code goes here\n", + "# Define metric for the difference between two traces\n", + "def trace_diff(trace1, trace2):\n", + " return sum(abs(trace1 - trace2))\n", + "\n", + "# FIXME: Your code goes here\n", + "alphabet = 'abcdefghijklmnopqrstuvwxyz0123456789'\n", + "\n", + "ref = cap_pass_trace(\"0x00\\n\")\n", + "\n", + "for j in range(5): \n", + " for i in alphabet:\n", + " if(trace_diff(cap_pass_trace(guessed_pw+i),ref) > 20):\n", + " guessed_pw = guessed_pw + i\n", + " print(trace_diff(cap_pass_trace(guessed_pw+i),ref))\n", + " ref = cap_pass_trace(guessed_pw + \"\\x00\\n\")\n", + "\n", + " print(guessed_pw)\n", + " break\n", + " \n", + "print (pass_response(guessed_pw))\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "You should get an output that looks like this:\n", + "\n", + " h\n", + " h4\n", + " h4u\n", + " h4uw\n", + " h4uwe\n", + "\n", + "Only that the real password is not `h4uwe`, but something else. You can test if the final password is correct by asking the device using the function `pass_responce(guessed_pw)`. \n", + "\n", + "Did you find the correct password? Congrats. Otherwise check the hints at the end of this notebook." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Breaking a (Really) Secret Password\n", + "\n", + "
\n", + " This only works with the real ChipWhisperer hardware, not using pre-recorded traces. \n", + "
\n", + "\n", + "Once your code is working on the example, let's use it on another instance of the same firmware, where the password has been changed (and obfuscated, so you can't see it using a hexdump of the binary...). Execute the cell below in order to flash the firmware to the target system:" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Detected known STMF32: STM32F04xxx\n", + "Extended erase (0x44), this can take ten seconds or more\n", + "Attempting to program 12839 bytes at 0x8000000\n", + "STM32F Programming flash...\n", + "STM32F Reading flash...\n", + "Verified flash OK, 12839 bytes\n" + ] + } + ], + "source": [ + "fw_path = 'hex/secret-passwdcheck-CWNANO.hex'\n", + "programmer = cw.programmers.STM32FProgrammer\n", + "cw.program_target(scope, programmer, fw_path)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Once this is done, rerun your code and print the system's response." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Troubleshooting\n", + "### Always get 'h'" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Some common problems you might run into - first, if you get an output which keeps guessing the first character:\n", + "\n", + " h\n", + " hh\n", + " hhh\n", + " hhhh\n", + " hhhhh\n", + "\n", + "Check that when you run the `cap_pass_trace` inside the loop (checking the guessed password), are you updating the prefix of the password? For example, the old version of the code (guessing a single character) looked like this:\n", + "\n", + " trace = cap_pass_trace(c)\n", + "\n", + "But that is always sending our first character only! So we need to send the \"known good password so far\". In the example code something like this:\n", + " \n", + " trace = cap_pass_trace(guessed_pw + c)\n", + "\n", + "Where `guessed_pw` progressively grows with the known good start of the password.\n", + "\n", + "### Always get 'a'\n", + "\n", + "This looks like it's always matching the first character:\n", + "\n", + " h\n", + " ha\n", + " haa\n", + " haaa\n", + " haaaa\n", + "\n", + "Check that you update the `ref_trace` - if you re-use the original reference trace, you won't be looking at a reference where the first N characters are good, and the remaining characters are bad. An easy way to do this is again using the `guessed_pw` variable and appending a null + newline:\n", + "\n", + " trace = cap_pass_trace(guessed_pw + \"\\x00\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "---\n", + "NO-FUN DISCLAIMER: This material is Copyright (C) NewAE Technology Inc., 2015-2020. ChipWhisperer is a trademark of NewAE Technology Inc., claimed in all jurisdictions, and registered in at least the United States of America, European Union, and Peoples Republic of China.\n", + "\n", + "Tutorials derived from our open-source work must be released under the associated open-source license, and notice of the source must be *clearly displayed*. Only original copyright holders may license or authorize other distribution - while NewAE Technology Inc. holds the copyright for many tutorials, the github repository includes community contributions which we cannot license under special terms and **must** be maintained as an open-source release. Please contact us for special permissions (where possible).\n", + "\n", + "THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE." + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.2" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/A1/tp-spa/hex/basic-passwdcheck-CWNANO.hex b/A1/tp-spa/hex/basic-passwdcheck-CWNANO.hex new file mode 100644 index 0000000..378a79a --- /dev/null +++ b/A1/tp-spa/hex/basic-passwdcheck-CWNANO.hex @@ -0,0 +1,305 @@ +:020000040800F2 +:10000000001000201911000861110008611100089A +:100010006111000861110008611100080000000072 +:100020000000000000000000000000006111000856 +:100030006111000800000000611100086111000852 +:1000400000000000000000000000000000000000B0 +:1000500000000000000000000000000000000000A0 +:100060000000000000000000000000000000000090 +:100070000000000000000000000000000000000080 +:100080000000000000000000000000000000000070 +:100090000000000000000000000000000000000060 +:1000A0000000000000000000000000000000000050 +:1000B0000000000000000000000000000000000040 +:1000C0000000000000000000000000000000000030 +:1000D0000000000000000000000000000000000020 +:1000E0000000000000000000000000000000000010 +:1000F0000000000000000000000000000000000000 +:1001000000000000000000000000000000000000EF +:1001100000000000000000000000000000000000DF +:1001200000000000000000000000000000000000CF +:1001300000000000000000000000000000000000BF +:1001400000000000000000000000000000000000AF +:10015000000000000000000000000000000000009F +:10016000000000000000000000000000000000008F +:10017000000000000000000000000000000000007F +:08018000000000000000000077 +:100188000448054B10B5834203D0044B002B00D024 +:10019800984710BD04000020040000200000000063 +:1001A80006480749091A8910CB0F591810B5491084 +:1001B80003D0044B002B00D0984710BD040000204A +:1001C800040000200000000010B5074C2378002B25 +:1001D80009D1FFF7D5FF054B002B02D0044800E0FA +:1001E80000BF0123237010BD0400002000000000A0 +:1001F80064110008054B10B5002B03D004490548CD +:1002080000E000BFFFF7CCFF10BDC04600000000B3 +:10021800080000206411000802B47146490849002A +:10022800095C49008E4402BC7047C046002243085E +:100238008B4274D303098B425FD3030A8B4244D3A6 +:10024800030B8B4228D3030C8B420DD3FF220902E8 +:1002580012BA030C8B4202D31212090265D0030BA7 +:100268008B4219D300E0090AC30B8B4201D3CB039D +:10027800C01A5241830B8B4201D38B03C01A5241DF +:10028800430B8B4201D34B03C01A5241030B8B42E1 +:1002980001D30B03C01A5241C30A8B4201D3CB02CC +:1002A800C01A5241830A8B4201D38B02C01A5241B1 +:1002B800430A8B4201D34B02C01A5241030A8B42B4 +:1002C80001D30B02C01A5241CDD2C3098B4201D3CC +:1002D800CB01C01A524183098B4201D38B01C01A4A +:1002E800524143098B4201D34B01C01A52410309C1 +:1002F8008B4201D30B01C01A5241C3088B4201D370 +:10030800CB00C01A524183088B4201D38B00C01A1C +:10031800524143088B4201D34B00C01A5241411A43 +:1003280000D20146524110467047FFE701B5002050 +:1003380000F006F802BDC0460029F7D076E77047FE +:100348007047C04670B50C4D0C4E761BB61005D0E4 +:10035800002408CD01349847A642FAD100F0FEFEE9 +:10036800074D084E761BB61005D0002408CD013481 +:100378009847A642FAD170BD9C1200089C1200084A +:100388009C120008A0120008F0B5C64600B50F2A56 +:1003980043D90B00032603431E400C000300002E24 +:1003A80040D11500103D2D09AC462D01A8468044CA +:1003B80000E03B00676825685F60E7681D60DF60F4 +:1003C8001F00A56810379D6010344345F1D165467C +:1003D8000F230C2401352D014919134045191442E6 +:1003E80023D08C59AC5104369C1B032CF9D8032418 +:1003F800043B9B0801339B002240ED18C918561E88 +:10040800002A07D0002300E02300CA5C5C1CEA54E1 +:100418009E42F9D104BC9046F0BD0500561E002A44 +:10042800F0D1F7E7561E0500ECE71A00F6E7C046DC +:10043800002382B0054A0193019B934201D902B07F +:100448007047019B01330193F6E7C046FE0F000099 +:1004580010B504002078013400F052F92378002BFD +:10046800F8D110BDF8B504000E0005002B1B9E4204 +:1004780004DC0023A419013C23700AE000F028F9E9 +:100488002F0028700028F9D001350A28EED1002362 +:100498003B70F8BD30B58DB002AC00F05DF800F0EF +:1004A80087F800F0C5F8062220492000FFF76CFF06 +:1004B8001F48FFF7CDFF1F48FFF7CAFF1E48FFF789 +:1004C800C7FF1E48FFF7C4FF1D48FFF7C1FF1D48BF +:1004D800FFF7BEFF1C48FFF7BBFF04AD00F0F0F8C4 +:1004E8001A48FFF7B5FF20212800FFF7BBFF00F0EF +:1004F800DFF80023E15CEA5C914214D10133062B5A +:10050800F8D11348FFF7A4FF0CE0019B01330193D6 +:10051800019B002BF9DDFFF78BFFFFF789FF0D48E3 +:10052800FFF796FFFEE70023F1E7C04696120008A2 +:1005380080110008A3110008C0110008DD1100088F +:10054800FA110008171200081A12000849120008C8 +:100558007C1200086D120008F0B5902700240125D0 +:100568000326042397B0FF0505A9380005930695CF +:100578000794089600F046FB102305A93800059358 +:1005880006950794089600F03DFB05230AA80B93EF +:100598000A960D94139400F0C9F80723210001A8C6 +:1005A800019302950394049400F0A2FA17B0F0BDE9 +:1005B800802170B51B4C8902626988B00A43626168 +:1005C800636990200B400193019BC023DB000393D8 +:1005D80001250223032603A9C00504930595079561 +:1005E800069600F00FFB8021A269C9010A43A261A7 +:1005F800A3690D480B400293029B236BB3431D4331 +:100608000A4B2563036096231B0243600023836023 +:10061800C360036183610C33436100F06BFC08B075 +:1006280070BDC04600100240240000200038014080 +:1006380080201E4AF0B55169800201435161536917 +:1006480087B0034090240093012500260327009BD0 +:100658008023E40501A920000193029503960497DD +:1006680000F0D0FA102301A9200001930295039607 +:10067800049700F0C7FA042301A92000019302950A +:100688000396049700F0BEFA32002000802100F0A3 +:1006980069FB2A002000102100F064FB2A000421D5 +:1006A800200000F05FFB07B0F0BDC046001002401C +:1006B800902010B501228021C00500F053FB10BD29 +:1006C800902010B500228021C00500F04BFB10BD22 +:1006D80037B508256B46DC1D012232232100064868 +:1006E80000F03AFC002801D120783EBD034A136A85 +:1006F8002B431362EEE7C046240000200038014077 +:1007080007B56B46D91D0870024B0122024800F05C +:1007180099FC07BD8813000024000020024B1868CC +:10072800421C1A607047C04620000020F0B50368DC +:1007380085B00500DB072FD42B689B0700D581E027 +:100748002B681B0700D5BCE02B685B0700D5DFE0F2 +:100758002B68DB061AD56A69B54C0423012A00D038 +:100768004BE1616B02260B436363636B1A4362635D +:10077800FFF7D4FF0700636B334200D136E1F8215D +:10078800626BAB698A43DB0013436363296A002900 +:1007980000D059E1002013E00C21A54C62680A4002 +:1007A800042A06D063680B40082B0BD16368DB036F +:1007B80008D523689B03BFD56B68002BBCD10120EB +:1007C80005B0F0BD6B68012B13D1802322685B0252 +:1007D80013432360FFF7A2FF80260700B6022368B1 +:1007E8003342A9D1FFF79AFFC01B6428F7D9032029 +:1007F800E6E7002B16D123688E4A80261340236033 +:1008080023688D4AB60213402360FFF787FF07006D +:100818002368334200D18FE7FFF780FFC01B6428AD +:10082800F6D9E4E7052B05D180232268DB021343C0 +:100838002360CAE723687F4A1340236023687E4AFF +:100848001340C6E70C227A4C6368134206D06368EB +:100858001340082B10D16368DB030DD423689B0772 +:1008680002D5EB68012BAAD1F82122682B698A43AB +:10087800DB001343236063E7EA680123002A0FD0F3 +:100888002268022613432360FFF748FF0700236806 +:100898003342E9D1FFF742FFC01B0228F7D9A6E788 +:1008A800226802269A432260FFF738FF0700236870 +:1008B800334200D144E7FFF731FFC01B0228F6D9C5 +:1008C80095E7EA6901235A4C002A10D0626A022689 +:1008D80013436362FFF722FF0700636A334200D0C5 +:1008E80032E7FFF71BFFC01B0228F6D97FE7626AD1 +:1008F80002269A436262FFF711FF0700636A3342D8 +:1009080000D121E7FFF70AFFC01B0228F6D96EE7DE +:1009180080220021464C5205E3690091134208D118 +:10092800E3691343E361E36913400393039B0123E2 +:1009380000938027414E7F0033683B4206D0AB6866 +:10094800012B13D1226A1343236230E033683B43FF +:100958003360FFF7E3FE019033683B42EFD1FFF7C6 +:10096800DDFE019BC01A6428F6D940E70122002B5E +:1009780014D1236A022793432362236A03329343E1 +:100988002362FFF7CBFE0600236A3B4225D0FFF720 +:10099800C5FE2B4B801B9842F6D928E7052B0BD1B7 +:1009A800216A013B0B432362236A1A432262FFF741 +:1009B800B5FE022706000DE0236A93430422236252 +:1009C800236A9343C0E7FFF7A9FE1D4B801B98429B +:1009D80000D90CE7236A3B42F5D0009B012B00D0DD +:1009E800B6E6E369174A1340E361B1E6FFF796FEFE +:1009F800C01B022800D8BEE6F9E6053203D1626BB7 +:100A08009A436263BBE6626B022613430122636367 +:100A1800636B93436363FFF781FE0700636B3342A5 +:100A280000D1B3E6FFF77AFEC01B0228F6D9DEE64E +:100A380000100240FFFFFEFFFFFFFBFF00700040B9 +:100A480088130000FFFFFFEF0C22264C012063688B +:100A58001340082B00D1B3E62368234A13402360D0 +:100A680002292FD1FFF75AFE80260700B604236813 +:100A7800334221D10F22E36A9343EA6A1343E362C4 +:100A8800696AAB6A62680B43184980250A401343B8 +:100A98006360802322685B0413432360FFF73EFEF4 +:100AA8000600AD0423682B4200D073E6FFF736FE3C +:100AB800801B0228F6D99AE6FFF730FEC01B0228F1 +:100AC800D5D994E6FFF72AFE80250600AD042368F1 +:100AD8002B4200D15EE6FFF721FE801B0228F6D9E3 +:100AE80085E6C04600100240FFFFFFFEFFFFC2FF81 +:100AF800F7B501223E4C060023680F0013408B42D5 +:100B080012D33268930719D4D3071FD4012322685C +:100B18001A40BA425DD833685B0761D4E122354B8D +:100B2800D2031A60002008E0236893430B43236034 +:100B3800236813408B42E4D00120FEBDF0202E49EB +:100B48004B688343B06803434B60DDE72A4D726806 +:100B58002B68012A1AD19B03EED503216B688B43BE +:100B680013436B60FFF7DAFD73680190012B15D111 +:100B78000C226B681340042BC8D0FFF7CFFD019BF4 +:100B8800C01A1E4B9842F3D90320D6E7022A02D195 +:100B98009B01E2D4D0E79B07DFD4CDE7022B12D02C +:100BA8000C226B681342B1D0FFF7B8FD019BC01A45 +:100BB800124B9842F4D9E7E7FFF7B0FD019BC01A42 +:100BC8000E4B9842E0D80C226B681340082BF3D1E7 +:100BD8009CE722689A43226022681A429BD0ABE7BE +:100BE800054A074953680B40F1680B43536095E782 +:100BF800002002400000002000100240881300007E +:100C0800FFF8FFFFF0B50B6887B00393002301914D +:100C1800039ADA4001D107B0F0BD01229A4002924E +:100C28000299039A0A40009200D18CE0019A10219F +:100C3800526816008E43022E0ED107251D40AD00C6 +:100C48000139A940DC08A4000419276A8F430199D7 +:100C58000969A9400F43276203245F00BC40E443AD +:100C68000568013E2540AC4603251540BD40614658 +:100C78000D430560012E0FD801998668CD6826407E +:100C8800BD40354385604668029915098E430121A8 +:100C98000D409D4035434560C56801992C408D68DD +:100CA8008021BD4049052C43C4600A424BD0012134 +:100CB800264C0326A5691E400D43A561A4699D081D +:100CC8000C400594059C0F242149AD00B6006D1811 +:100CD800B4409021AF68C905A743002488420CD0CE +:100CE8001C490134884208D01B490134884204D089 +:100CF8001A490134884200D00234B44000993C4378 +:100D08000E00AC60164CCD4327683E43D10301D496 +:100D18003E002E4026606768009E3E43910301D442 +:100D28003E002E406660A768009E3E43D10201D473 +:100D38003E002E40A660E668009F3743920201D429 +:100D48002E403700E760013362E7C04600100240DA +:100D5800000001400004004800080048000C00485A +:100D680000040140002A01D0816170478162FCE7DC +:100D7800F8B504000E0015001F002268D36933403F +:100D88009B1B59424B41AB4201D0002018E0069B07 +:100D98000133F3D0069B002B13D123680C491A6842 +:100DA80003200A401A609A68A331FF318A439A6087 +:100DB8002200202369321370537000236834237093 +:100DC800F8BDFFF7ABFC069BC01B9842D5D9E4E7FA +:100DD8005FFEFFFF030070B59A681C69056822432F +:100DE8005C69C169224328683B4C0A43204002439E +:100DF8002A606A6839481C6A0240D86802436A60F7 +:100E08009A69A8682243364C204002430320AA600E +:100E1800344A126B02403448845C802212029142A8 +:100E280030D1082C2BD82000FFF7F6F90529162910 +:100E38001F29292924005968E12348081B04C018E0 +:100E4800FFF7F4F980B202000F2300079A43400F1E +:100E58001043E860200070BD5968244B4808C0184A +:100E6800FFF7E4F9002480B2EDE75968E123480868 +:100E78001B04F4E75968802348085B02EFE7012464 +:100E88000020E0E7082C24D82000FFF7C5F9052248 +:100E98000E22182222221D005968E1234808DB038C +:100EA800C018FFF7C3F980B2D3E75968104B480858 +:100EB800C018FFF7BBF980B2E8600024CAE7596898 +:100EC800E1234808DB03F3E75968802348081B023D +:100ED800EEE70124BEE7C046F369FFFFFFCFFFFF3F +:100EE800FFF4FFFF001002407C1100080048E801F1 +:100EF8000024F40070B5041E01D1012070BD050066 +:100F080069352B78DBB2002B02D1020068321370EE +:100F18002423012622682B7013682000B343136032 +:100F2800FFF758FFB042E8D023680A495A68002002 +:100F38000A4008215A609A688A439A601A681643D8 +:100F480022001E602023E0666A3268342B7013701A +:100F58002070D3E7FFF7FFFFF0B51F0003006A33E7 +:100F680016001A78040085B00D000220202A39D115 +:100F78000138002936D0002E34D08022A1685201D1 +:100F8800914204D12269002A01D105422AD12200C6 +:100F9800683211780220012924D001211170002221 +:100FA800E26622321A70FFF7B9FB23008021A2689B +:100FB80058331E805E800390490104338A4215D15C +:100FC8002269002A10D11E4A1A801E8822005A322D +:100FD800108880B2002810D1230020226A33683498 +:100FE8001A70207005B0F0BDFF22EDE7002AECD1A1 +:100FF8002269002AF8D07F22E6E713882021013BE6 +:101008009BB2138020000097039B0022FFF7B0FEDD +:10101800002813D1A268236811008022520191424E +:1010280007D12269002A04D19B8C33402B800235DA +:10103800CCE79B8C33402B700135C7E70320D1E701 +:10104800FF010000F0B5070085B0039369373B78CE +:1010580004000D0016000220202B46D1013800297B +:1010680043D0002A41D08023A2685B019A4204D170 +:101078002369002B01D1014237D1230068331A7844 +:101088000220012A31D001221A700023E36621339D +:101098003B70FFF743FB230050331E805E808026A1 +:1010A80002907601210052310A8892B2002A0DD1AD +:1010B800039B402100932000029BFFF759FE002864 +:1010C80012D1202368343B7020700EE00B88002278 +:1010D800013B9BB20B80039B802100932000029B65 +:1010E800FFF746FE002802D0032005B0F0BDA36834 +:1010F8002268B34208D12369002B05D12B88023519 +:10110800DB05DB0D1385CDE72B7801351385C9E7A2 +:10111800002103E00B4B5B58435004310A480B4B4A +:1011280042189A42F6D30A4A02E0002313600432B6 +:10113800084B9A42F9D300E000BFFFF703F9FFF725 +:10114800A9F9FEE7A412000800000020040000200E +:101158000400002094000020FEE70000F8B5C04617 +:10116800F8BC08BC9E467047F8B5C046F8BC08BC39 +:041178009E467047D8 +:10117C00000408022A2A2A2A2A536166652D6F2D3B +:10118C006D61746963203330303020426F6F746945 +:10119C006E672E2E2E0A00416C69676E696E672091 +:1011AC00626974732E2E2E2E2E2E2E2E5B444F4ED5 +:1011BC00455D0A00436865636B696E672043657320 +:1011CC0069756D20524E472E2E5B444F4E455D0A7D +:1011DC00004D6173717565726164696E6720666C30 +:1011EC006173682E2E2E5B444F4E455D0A0044659C +:1011FC006372797074696E67206461746162617383 +:10120C00652E2E5B444F4E455D0A000A0A0057417D +:10121C00524E494E473A20554E415554484F52492B +:10122C005A4544204143434553532057494C4C2085 +:10123C0042452050554E49534845440A00506C6570 +:10124C0061736520656E7465722070617373776F5E +:10125C00726420746F20636F6E74696E75653A20CA +:10126C000050415353574F5244204641494C0A00B9 +:10127C00416363657373206772616E7465642C20BF +:10128C0057656C636F6D65210A00683070783300A8 +:04129C00FD01000848 +:0412A000D101000870 +:0412A40000127A00BA +:0400000508001119C5 +:00000001FF diff --git a/A1/tp-spa/hex/secret-passwdcheck-CWNANO.hex b/A1/tp-spa/hex/secret-passwdcheck-CWNANO.hex new file mode 100644 index 0000000..0db07e6 --- /dev/null +++ b/A1/tp-spa/hex/secret-passwdcheck-CWNANO.hex @@ -0,0 +1,809 @@ +:020000040800F2 +:1000000000100020B92E0008012F0008012F000861 +:10001000012F0008012F0008012F00080000000038 +:10002000000000000000000000000000012F000898 +:10003000012F000800000000012F0008012F000818 +:1000400000000000000000000000000000000000B0 +:1000500000000000000000000000000000000000A0 +:100060000000000000000000000000000000000090 +:100070000000000000000000000000000000000080 +:100080000000000000000000000000000000000070 +:100090000000000000000000000000000000000060 +:1000A0000000000000000000000000000000000050 +:1000B0000000000000000000000000000000000040 +:1000C0000000000000000000000000000000000030 +:1000D0000000000000000000000000000000000020 +:1000E0000000000000000000000000000000000010 +:1000F0000000000000000000000000000000000000 +:1001000000000000000000000000000000000000EF +:1001100000000000000000000000000000000000DF +:1001200000000000000000000000000000000000CF +:1001300000000000000000000000000000000000BF +:1001400000000000000000000000000000000000AF +:10015000000000000000000000000000000000009F +:10016000000000000000000000000000000000008F +:10017000000000000000000000000000000000007F +:08018000000000000000000077 +:100188000448054B10B5834203D0044B002B00D024 +:10019800984710BDBC000020BC00002000000000F3 +:1001A80006480749091A8910CB0F591810B5491084 +:1001B80003D0044B002B00D0984710BDBC00002092 +:1001C800BC0000200000000010B5074C2378002B6D +:1001D80009D1FFF7D5FF054B002B02D0044800E0FA +:1001E80000BF0123237010BDBC00002000000000E8 +:1001F800042F0008054B10B5002B03D0044905480F +:1002080000E000BFFFF7CCFF10BDC04600000000B3 +:10021800C0000020042F000802B4714649084900B4 +:10022800095C49008E4402BC7047C046002243085E +:100238008B4274D303098B425FD3030A8B4244D3A6 +:10024800030B8B4228D3030C8B420DD3FF220902E8 +:1002580012BA030C8B4202D31212090265D0030BA7 +:100268008B4219D300E0090AC30B8B4201D3CB039D +:10027800C01A5241830B8B4201D38B03C01A5241DF +:10028800430B8B4201D34B03C01A5241030B8B42E1 +:1002980001D30B03C01A5241C30A8B4201D3CB02CC +:1002A800C01A5241830A8B4201D38B02C01A5241B1 +:1002B800430A8B4201D34B02C01A5241030A8B42B4 +:1002C80001D30B02C01A5241CDD2C3098B4201D3CC +:1002D800CB01C01A524183098B4201D38B01C01A4A +:1002E800524143098B4201D34B01C01A52410309C1 +:1002F8008B4201D30B01C01A5241C3088B4201D370 +:10030800CB00C01A524183088B4201D38B00C01A1C +:10031800524143088B4201D34B00C01A5241411A43 +:1003280000D20146524110467047FFE701B5002050 +:1003380000F0F0F802BDC0460029F7D076E7704714 +:1003480003460B437FD4002243088B4274D303092E +:100358008B425FD3030A8B4244D3030B8B4228D3CF +:10036800030C8B420DD3FF22090212BA030C8B42F5 +:1003780002D31212090265D0030B8B4219D300E095 +:10038800090AC30B8B4201D3CB03C01A5241830B1A +:100398008B4201D38B03C01A5241430B8B4201D3CA +:1003A8004B03C01A5241030B8B4201D30B03C01AF3 +:1003B8005241C30A8B4201D3CB02C01A5241830A6D +:1003C8008B4201D38B02C01A5241430A8B4201D39C +:1003D8004B02C01A5241030A8B4201D30B02C01AC6 +:1003E8005241CDD2C3098B4201D3CB01C01A52412D +:1003F80083098B4201D38B01C01A524143098B42B6 +:1004080001D34B01C01A524103098B4201D30B019E +:10041800C01A5241C3088B4201D3CB00C01A5241C3 +:1004280083088B4201D38B00C01A524143088B4288 +:1004380001D34B00C01A5241411A00D20146524121 +:10044800104670475DE0CA0F00D04942031000D340 +:100458004042534000229C4603098B422DD3030A95 +:100468008B4212D3FC22890112BA030A8B420CD3A5 +:10047800890192118B4208D3890192118B4204D3CE +:1004880089013AD0921100E08909C3098B4201D34E +:10049800CB01C01A524183098B4201D38B01C01A88 +:1004A800524143098B4201D34B01C01A52410309FF +:1004B8008B4201D30B01C01A5241C3088B4201D3AE +:1004C800CB00C01A524183088B4201D38B00C01A5B +:1004D8005241D9D243088B4201D34B00C01A524132 +:1004E800411A00D20146634652415B10104601D3BF +:1004F8004042002B00D54942704763465B1000D349 +:10050800404201B5002000F005F802BD0029F8D0EE +:1005180016E770477047C04670B50C4D0C4E761BF9 +:10052800B61005D0002408CD01349847A642FAD168 +:1005380002F0E4FC074D084E761BB61005D00024E7 +:1005480008CD01349847A642FAD170BD643100083D +:10055800643100086431000868310008F0B505000E +:1005680083074AD0541E002A44D0CEB20300032287 +:1005780002E00135013C3DD301332E701342F8D11E +:10058800032C2FD9FF220A40150215432A041543CC +:100598000F2C35D92700103F3F093E01B4461E00F5 +:1005A8001A0010366644156055609560D5601032A3 +:1005B800B242F8D10F260C2201373F012640DB1941 +:1005C8003700224217D03E1FB608B400A4461A00CE +:1005D8001C1D644420C2A242FCD103240136B6008B +:1005E8009B193C40002C05D0C9B21C191970013365 +:1005F8009C42FBD1F0BD3400F4E714000300BFE7D0 +:100608002700E0E7114B70B51C680500A06B0028B7 +:1006180003D000230561436170BD183000F0AAF8CB +:10062800A06300280CD00A4B01220360094B4360E9 +:10063800094B83600B238381002302614361E8E750 +:10064800064B00224221064800F050F858000020CE +:100658000E33CDAB34126DE6ECDE05009C3000089D +:10066800B4300008184B70B51D68AC6B002C0ED068 +:1006780020696169154A164B01F016FD0122002315 +:1006880012184B41580040082261636170BD182060 +:1006980000F070F8041EA8630FD00E4B012203600F +:1006A8000D4B43600D4B83600B2383810023026154 +:1006B800436107480A4A064BE6E70A4B00224E21E7 +:1006C800094800F013F8C046580000202D7F954CCB +:1006D8002DF451580E33CDAB34126DE6ECDE050027 +:1006E8002E7F954C9C300008B430000830B51C00B3 +:1006F8000A4B05001B6885B0D868002A0AD0084B49 +:100708000292019300912B002200064900F020F884 +:1007180000F0BCFD044B1A00F2E7C0465800002068 +:10072800E8300008F8300008F4300008130010B56D +:100738000022FFF7DBFFC0460CB400B583B004AB62 +:1007480004CB019300F01EF903B008BC02B01847AF +:100758000EB400B582B003AB0100054804CB0068B5 +:10076800019300F00FF902B008BC03B01847C04667 +:100778005800002010B5034B0100186800F064F819 +:1007880010BDC0465800002010B5034B0100186882 +:1007980000F004F810BDC0465800002070B50500F0 +:1007A800002915D00C1F2368002B27DB280001F037 +:1007B800ABFA244B1A68002A05D0A2420CD921684A +:1007C8006018824224D0626028001C6001F09EFA02 +:1007D80070BDA34203D81A005368002BF9D11168E1 +:1007E8005018A0421BD027D821686018834207D030 +:1007F80063605460280001F089FAE9E7E418D5E756 +:1008080018685B6884466144216063605460F1E75E +:10081800106852688446614421606260D4E72068A9 +:100828000918501811608342E4D118685B6884463F +:10083800614411605360DDE70C2328002B6001F050 +:1008480065FAC5E7DC000020F8B50323CD1C9D43FD +:10085800083506000C2D2AD20C25A94229D83000CB +:1008680001F052FA2A4F3A68002A0AD013685B1B33 +:1008780004D441E023685B1B1FD522005468002C78 +:10088800F8D17B68002B3DD02900300000F0F0FB48 +:10089800431C2AD00323C41C9C43A04205D0211A20 +:1008A800300000F0E5FB431C1FD0256010E0002D50 +:1008B800D3DA0C2300203360F8BD0B2B05D863680E +:1008C800A2421DD0536003E014002360E4182560A1 +:1008D800300001F01BFA200007220B30231D904343 +:1008E800C21AE9D01B1AA350E6E70C233000336084 +:1008F80001F00CFA0020DFE70B2BE5D81400536851 +:100908003B60E5E70021300000F0B2FB7860BBE710 +:10091800DC000020936810B5013B9360002B04DADB +:100928009469A34207DB0A2905D01368581C106094 +:100938000800197010BD00F0ADFBFBE7F8B5060024 +:100948000F00002B0DD01400D51802E00134AC4282 +:1009580007D021783A003000FFF7DCFF431CF5D1BF +:10096800F8BD0020FCE7C046936810B51400002BC2 +:1009780002D10020536010BD00F08CFE0023A3605C +:100988006360F8E7F0B54E46DE4657464546E0B5A3 +:10099800A1B00490039191461C00002804D08369FB +:1009A8000593002B00D1BEE0AD4B039A9A4200D1CB +:1009B800C0E0AC4B039A9A4200D1CDE0AA4B039A0F +:1009C8009A4200D147E1039A93891B0700D4B9E002 +:1009D80013690593002B00D1B4E0002308AD6B61C7 +:1009E80020336B761033AB762F3B98464B461B78FB +:1009F80007949E4F002B00D189E0252B00D125E1DB +:100A08004E4603E0252B00D1AAE026007378741C1B +:100A1800002BF7D14B46E31A9A4678D053464A46FC +:100A280003990498FFF78AFF431C70D06B695344FD +:100A38006B617378002B6AD00122002352426A60EE +:100A4800443201342B60EB60AB60AB54AB6506E01D +:100A58004346C01B834034002A6813432B60217827 +:100A68000522380001F05EF8661C0028F0D12B68DA +:100A7800B246DA0602D543222021A9541A0702D524 +:100A880043222B21A95421782A2900D06EE0079A05 +:100A9800111D12680791002A00DABAE0EA6061784D +:100AA800A61C2E2900D17AE0714B03221800994622 +:100AB80001F038F8002800D18FE04B46C01A4023D7 +:100AC80083402A68317813432B600622731C6948D7 +:100AD8009946297601F026F8002800D188E0664B6F +:100AE800002B00D18EE007AB0093039A634B2900DB +:100AF800049800E000BF83465B46013307D06B696A +:100B08005B446B614B461B78002B00D075E7039B59 +:100B18009B895B061DD4686921B03CBC9046994608 +:100B2800A246AB46F0BD00F08DFD4D4B039A9A42AC +:100B380000D03EE7049B5B680393039A93891B07E5 +:100B480000D545E70399049800F01AFB002800D166 +:100B580043E701204042DFE7049B9B68039332E7A9 +:100B68004B46E31A9A4600D166E757E70A00303A3F +:100B7800A246092A95D8EB68180001E0340001362E +:100B880083001B1831785B0098180A00303A092A4C +:100B9800F4D9B246E860A61C2E2900D084E7534653 +:100BA80059782A293BD1079B1A1D079252469178FA +:100BB800D61C022294461B68E2446B60002B00DBC3 +:100BC80072E701235B426B60294B032218009946A8 +:100BD80000F0A8FF002800D06FE7B14656463178EC +:100BE80006222448297600F09DFF002800D076E7E9 +:100BF80007AB0093039A214B2900049800F0E4F80E +:100C0800834679E70722079B073393430833079303 +:100C180075E75242EA60022213432B603FE70A005D +:100C28000023303A6B601800092A01D910E01E0031 +:100C380083001B1871785B0098180A00303A731CFF +:100C4800092AF4D99A46023668602DE74C46F3E63D +:100C5800B246013628E7049BDB680393B3E6C04637 +:100C6800642F0008442F0008242F000828310008AA +:100C78003031000834310008000000004509000840 +:100C880010B504001300034A10680A002100FFF79A +:100C980079FE10BD58000020F0B54F464646D646AE +:100CA800C0B51F00089B914698468A680B690600E4 +:100CB8000C00934200DA13004A4613604322A25CF8 +:100CC800002A02D04A460133136023689A065AD58F +:100CD8004B461B6806209A1C4B461A60236819006D +:100CE800184208D1E16800258A1A19218A46190094 +:100CF800A244002A3FDC4323E35C5A1E93418A0640 +:100D08000AD53020E1184331087045215A1C615C2E +:100D1800A2184332023311702200390043323000E6 +:100D2800C047431C19D006232068A26821690340E4 +:100D3800042B30D08A423ADD00239946521A914456 +:100D48001A34002502E001354D4530DA012322002E +:100D580039003000C047431CF5D1012040421CBC7B +:100D680090469946A246F0BD4B46E2681B6801359D +:100D7800D31AAB4220DD0123524639003000C04768 +:100D8800431CF1D1E9E706221A4212D04323E35C5F +:100D98005A1E9341C0E74B46E0681B68C31AD84304 +:100DA800C017184081468A42C8DC002BC8DC0020E6 +:100DB800D5E74A46126895E743232168E35C5A1E43 +:100DC80093418A069DD4A7E7F0B557469A46432330 +:100DD8009C464E464546DE468C446346E0B587B0A1 +:100DE80003930B7E914680460C00109A6E2B00D11F +:100DF800D8E000D871E0732B00D11AE100D881E067 +:100E0800752B00D1FFE0782B00D00BE10B68782020 +:100E18004521605494498B46116840C911601806F1 +:100E280003D4580601D53604360CDA0702D5202239 +:100E3800134323601027002E00D1C2E04323002271 +:100E4800E2546368A360002B00DAC5E0042221683D +:100E580091432160002E00D083E0002B00D0BDE03C +:100E6800039D082F00D18CE0039B5B1B2361534635 +:100E780005AA009321004B464046FFF70DFF431C8F +:100E880022D023692A0049464046D047431C1BD03C +:100E980022680598E368920700D47FE01A1A002AAE +:100EA80000DC7BE026000025193606E0E36805989B +:100EB80001351A1AAA4200DC70E0012332004946C3 +:100EC8004046D047431CF1D10120404207B03CBC0A +:100ED80090469946A246AB46F0BD632B00D184E00C +:100EE8001FD8002B69D0582B00D09BE045216354B4 +:100EF8005E4923688B46116840C91160180600D402 +:100F08008FE792E76F2B7ED0702B00D08AE02023EA +:100F1800096878200B4345212360605452498B4669 +:100F28007AE7642B01D0692B7CD111682368081DEE +:100F380010601D064AD50A681600002A03DB4B4BD1 +:100F48000A279B467DE743222D21A15462687642F9 +:100F5800A260002A02DB042293432360434B0A2742 +:100F68009B46039D00E0060039003000FFF7E4F9D6 +:100F78005B465B5C013D2B70BE42F4D2082F00D06B +:100F880072E72368DB0700D46EE76368226993423F +:100F980000DD69E73023013D2B7065E7984295DA5B +:100FA800180093E7136809681D1D606915601B68C0 +:100FB8000E0601D449064BD418600023039D236113 +:100FC80055E7202322689A43226037E75D06B2D5A9 +:100FD80000228E5E3200B0E7002EC2D15B462500AB +:100FE8001A7842234235E2543BE713682500191D5D +:100FF80011601A684223E254413B4235236143237E +:101008000022E25433E7116820680D1D15600606BA +:1010180001D440061ED40E686F2B1DD0134B0A272F +:101028009B460BE742222500A35401234235236146 +:10103800E5E71368191D11601D6862680021280022 +:1010480000F070FD00280BD0401B60602061D6E7DF +:101058001880B2E70E88DFE7044B08279B46EDE6C9 +:1010680060682061CBE7C046503100083C31000879 +:10107800002370B5064C05000800236001F076F8DF +:10108800431C00D070BD2368002BFBD02B60F9E710 +:1010980058010020F8B505000E001400002802D001 +:1010A8008369002B29D02D4B9C422BD02C4B9C4282 +:1010B80046D02C4B9C424ED0A369A360A3891B0742 +:1010C80026D52369002B23D0FF22F7B26169164089 +:1010D8002268D31A99422ADD0133A1680139A16037 +:1010E800511C2160177062699A422BD0A389DB07D3 +:1010F80001D50A2E26D03000F8BD00F0A3FA174B10 +:101108009C42D3D16C68A369A360A3891B07D8D478 +:101118002100280000F034F8002819D1FF222369A3 +:10112800F7B2616916402268D31A9942D4DC2100CB +:10113800280000F04DF900280AD122680123CCE7E5 +:10114800AC68B9E72100280000F042F90028D2D0A5 +:1011580001267642CFE7EC68AEE7C046642F000868 +:10116800442F0008242F000810B5044B0A001B6800 +:1011780001001800FFF78EFF10BDC0465800002080 +:101188003E4B70B51D6806000C00002D02D0AB69FF +:10119800002B1BD03A4B9C421ED03A4B9C424CD061 +:1011A800394B9C4260D00C23E25E93B2190719D5E3 +:1011B8002169002921D0DA072ED50023A3606369AD +:1011C80000205B42A36100292ED070BD280000F0EA +:1011D80039FA2B4B9C42E0D16C680C23E25E93B247 +:1011E8001907E5D4D90641D55B0728D42169082316 +:1011F8001343A3819BB20029DDD1A0228020920055 +:1012080080001A408242D6D02100300000F042FC13 +:10121800A3892169DA07D0D400229B0700D4626928 +:10122800A26000200029D0D10C22A35E1A06CCD5DA +:1012380040221343A3810138C7E7AC68B3E7616B69 +:1012480000290AD023004433994204D03000FFF724 +:10125800A5FA0C23E25E0023636324239A43002348 +:10126800216963602160C2E7EC689CE70923336069 +:10127800402301201A43A2814042A6E758000020DB +:10128800642F0008442F0008242F000810B50620FA +:1012980000F0F4FD012000F07FFFC046F0B5C6461F +:1012A80000B58B8980460C001A0745D44A68002A85 +:1012B80063DDE56A002D3BD04246414616680022B0 +:1012C8000A60216ADA045CD4012300224046A84758 +:1012D800431C61D0A389E56A216A5B0706D5636868 +:1012E800C01A636B002B01D0236CC01A00230200C4 +:1012F8004046A847431C46D143461B680C21625E02 +:10130800002B56D01D2B01D0162B5DD10023636016 +:10131800236923604346616B1E60002908D02300BF +:101328004433994202D04046FFF738FA00236363FA +:10133800002004BC9046F0BD0E69002EF8D00A6863 +:101348000E60951B00229B0700D14A69A260002D00 +:1013580004DCEDE736182D1A002DE9DD2B003200EC +:10136800216A4046A76AB8470028F3DC40220120DA +:10137800A38940421343A381DBE70A6C002A98DC67 +:10138800D6E7606DA9E70023636023692360A3891A +:10139800DB04BFD56065BDE743461B68002B99D0C9 +:1013A8001D2B0DD0162B0BD04022A3891343A381EC +:1013B800BFE7636023692360D304ABD56065A9E701 +:1013C800434600201E60B4E740231A43A281B0E7D9 +:1013D8000B6970B505000C00002B16D0002802D050 +:1013E8008369002B15D00E4B9C4210D00D4B9C42AC +:1013F80012D00D4B9C4211D00C22A35E002B04D0BE +:1014080021002800FFF74AFF00E0002070BD6C684B +:10141800F2E700F017F9E6E7AC68EDE7EC68EBE710 +:10142800642F0008442F0008242F000810B5011E5F +:1014380004D0054B1868FFF7CBFF10BD034B0449D8 +:10144800186800F0D9FAF8E758000020202F0008A3 +:10145800D91300080020704710B5024900F0CCFAF3 +:1014680010BDC046D91300080020704770B5682425 +:101478004A1E54430E0021007431FFF7E5F9051E9A +:1014880009D000232200036046600C30A86068324F +:101498000021FFF763F8280070BDC0461E4B70B5E9 +:1014A8001D680600AB69002B27D048356B68AC680F +:1014B800013B03D51CE06834013B19D30C21625E63 +:1014C800002AF8D100252000144B65662560656068 +:1014D800A560E36025616561A561082200215C3093 +:1014E800FFF73CF86563A563A564E564200070BD5B +:1014F8002C68002C05D02500D8E7280000F010F84B +:10150800D3E704213000FFF7B1FF041E2860F2D1B1 +:101518000C233360EAE7C046202F00080100FFFFD4 +:10152800F0B5D6464F464646384BC0B583620023D1 +:101538008364C3640365364B82B01B68050001935E +:10154800984260D02800FFF7A9FF68602800FFF7DD +:10155800A5FFA8602800FFF7A1FF6E680024E860D7 +:1015680004233000746634607460B460F3603461DE +:101578007461B461082200215C30FEF7EFFF254B4F +:10158800254F9A467362254B37639946B362244BBD +:101598003662F362AE6898463000224B7466346057 +:1015A8007460B460F36034617461B461082200212E +:1015B8005C30FEF7D3FF534673624B46B362434633 +:1015C8003763F3623662EE68174B3000F360746677 +:1015D80034607460B46034617461B46108220021BD +:1015E8005C30FEF7BBFF534673624B46B36243461B +:1015F800F362012336623763AB6102B01CBC9046CC +:101608009946A246F0BD012383619BE76114000857 +:10161800202F0008111F0008A91F00083D1F0008FF +:101628007D1F0008090001001200020010B5034BDD +:101638000349186800F0E0F910BDC046202F0008E3 +:10164800D9130008836910B5002B01D1FFF768FF93 +:1016580010BDC0467047C0467047C0467047C04678 +:101668007047C04610B5034B0349186800F0A2F94B +:1016780010BDC046580000205D14000810B5034B8B +:101688000349186800F096F910BDC04658000020BC +:1016980071140008F0B54546DE4657464E46E0B59B +:1016A800936883B000900C009046002B6DD08B8916 +:1016B8001A0700D471E00A69002A00D16DE0424699 +:1016C80016689A0700D475E0A36A00279A46B54BB6 +:1016D80000259946216A002D16D02B004D4500D9CA +:1016E800B04B3A000098D047002800DCD5E04346CC +:1016F8009B683F182D1A181A4346986045D0A36A6C +:10170800216A9A46002DE8D1376875680836E2E7FD +:101718004B461B689A464B465F6808239C46E14443 +:10172800002FF5D03A000A21504600F0FBF90028B6 +:1017380000D1CEE053460130C61A3300BB469F4263 +:1017480000D99B46206822696369904204D9A2683F +:101758009D18AB4500DD92E05B4500DDF9E0A56A28 +:101768005246216A0098A847051E00DC95E0761BC2 +:101778000120002E00D1E4E043469B68AA447F1B69 +:101788005D1B43469D6000D095E0002003B03CBC43 +:1017980090469946A246AB46F0BD21000098FFF757 +:1017A800EFFC002800D0F9E04246A38916689A07A2 +:1017B80000D589E7DA0778D4002291468022920082 +:1017C80000279346A5682068002F53D05A46134235 +:1017D80000D181E0AA46BD4200D9AFE09022D200F4 +:1017E80013422ED02169451AAC4660690195420022 +:1017F8001218D00F8218781C5210604492469042FA +:1018080001D9824602005B0500D4AFE011000098C0 +:10181800FFF71AF8051E00D1BAE0019A216900F015 +:10182800C1F9A389604A134080221343A381524619 +:10183800019B2561E818BA463D00D31A2060626111 +:10184800A3605246494600F001FAA3685D1BA560F3 +:101858003D00002723685344236043469B68A944FE +:101868005D1B43469D6000D18FE7A5682068A3896A +:10187800002FABD13268776891460836A4E7514605 +:101888002A0000F0E3F9236821005B19236000981F +:10189800FFF79EFD002800D169E70C22A35E4022D5 +:1018A80001201343A381404270E70023B146002082 +:1018B8009A4600271E00002F00D129E7002800D0F3 +:1018C8003BE73A000A21504600F02CF9002800D0E6 +:1018D80030E77B1C1E0031E72369834217D3636915 +:1018E8009A46BB4213D8314B38009F4200D9304842 +:1018F8005146FEF725FD53464A464343216A009860 +:10190800A56AA8470028C8DD05007F1BA5E7BD42DA +:1019180000D93D002A00494600F098F9A3682268DA +:101928005B1B5219A3602260002BEED121000098A6 +:10193800FFF74EFD0028B0D17F1B8EE73D00BA4669 +:101948007FE721000098FFF743FD002800D113E747 +:10195800A3E75A46514600F079F95A46A3685D460E +:101968009B1AA36023685B44236000E7009800F09B +:10197800CFF9051E00D05AE7009D21692800FEF71F +:101988000DFF8022A3899343743A1BB22A6086E72D +:101998000C23009A13600C22A35E80E701204042CA +:1019A800F4E6C04600FCFF7F7FFBFFFFFEFFFF7FE2 +:1019B800FFFFFF7FF0B5C646483000B588460700F0 +:1019C8000026002813D07B68BC685D1E0CD4A38950 +:1019D800012B06D90E22A35E013302D02000C04796 +:1019E80006436834013DF2D23F68002FEBD1300046 +:1019F80004BC9046F0BDC046F8B54746CE4680B513 +:101A080007004837804689460026002F14D07B6897 +:101A1800BC685D1E0DD4A389012B07D90E22A35ED5 +:101A2800013303D021004046C84706436834013DCE +:101A3800F1D23F68002FEAD130000CBC904699469D +:101A4800F8BDC04670B50C001D000E23C95E96B0E7 +:101A58001600002914DB6A4600F0CEFA00280FDBD6 +:101A6800F022019B12021340094A944663445A42E9 +:101A780053412B608023DB003360002016B070BD1B +:101A880000232B60A3891B06F4D540233360F4E7B9 +:101A980000E0FFFF70B58B8982B006000C009B0741 +:101AA80007D523004733236023610123636102B014 +:101AB80070BD01AB6A46FFF7C5FF0099050030000D +:101AC800FEF7C2FE002810D08022154BB362A3890E +:101AD80020601343009A1BB26261019AA3812061BE +:101AE800002A0CD12B43A381E1E70C22A35E9A05BF +:101AF800DDD40322934302221343A381D1E70E23AB +:101B0800E15E300000F08CFA002802D10C22A35EBE +:101B1800E8E70322A3899343012213431BB2E1E7B9 +:101B28006114000870B5CDB2830734D0531E002A63 +:101B38001BD00278AA4219D0032404E0013B14D335 +:101B48000278AA4212D001302042F7D1032B0ED8D6 +:101B5800002B0AD00278AA4208D0C31802E0027803 +:101B6800AA4203D001308342F9D1002070BDFF2280 +:101B78000C06240C114021430C04084E0C43026847 +:101B880007496240511891433142E3D1043B043084 +:101B9800032BF4D8DCE71300D8E7C04680808080A8 +:101BA800FFFEFEFEF0B5C64600B50F2A43D90B006E +:101BB800032603431E400C000300002E40D11500ED +:101BC800103D2D09AC462D01A846804400E03B009D +:101BD800676825685F60E7681D60DF601F00A568AB +:101BE80010379D6010344345F1D165460F230C240E +:101BF80001352D01491913404519144223D08C5938 +:101C0800AC5104369C1B032CF9D80324043B9B08D5 +:101C180001339B002240ED18C918561E002A07D030 +:101C2800002300E02300CA5C5C1CEA549E42F9D100 +:101C380004BC9046F0BD0500561E002AF0D1F7E717 +:101C4800561E0500ECE71A00F6E7C046F0B5C64692 +:101C580000B588420CD98B18984209D2531E002A25 +:101C680003D0CA5CC254013BFBD204BC9046F0BD11 +:101C78000F2A0CD80500561E002AF6D0002300E0D3 +:101C88002300CA5C5C1CEA549E42F9D1EDE70B00C4 +:101C9800032603431E400C000300002E2ED115001E +:101CA800103D2D09AC462D01A846804400E02B00CC +:101CB8001D00276810351F6067685F60A7689F6010 +:101CC800E7681034DF604345F1D165460F230C24E3 +:101CD80001352D01491913404519144211D08C5969 +:101CE800AC5104369C1B032CF9D80324043B9B08F5 +:101CF80001339B00ED18C9182240BCE7561E0500A9 +:101D0800BCE71A00B7E7C0467047C0467047C046F0 +:101D1800F8B507000C00150000291BD0002A15D0C3 +:101D280000F0A4F92600A84201D33000F8BD29002C +:101D38003800FEF789FD061EF7D021002A00FFF7BC +:101D480031FF21003800FEF729FDEEE7FEF726FDFA +:101D58000026EAE71100FEF777FD0600E5E7C04632 +:101D680010B580210400FEF76FFD6064002807D0DD +:101D780002000023803208C09042FCD1002010BD30 +:101D880001204042FBE7C046426C10B50023002A00 +:101D980001D0180010BDFFF7E3FF0300F9E7C046C4 +:101DA80070B505000C0016001F2907D8436C002BDE +:101DB80009D0A4001B1918681E6070BD16230360A3 +:101DC80001204042F9E7FFF7CBFF002801D16B6CF7 +:101DD800EFE701204042F0E770B505000C001F292D +:101DE80020D8436C002B0ED08A009B181A68002A52 +:101DF80009D0012A14D0511C0ED0002120001960EE +:101E08009047002070BD280000F07AF822000100F9 +:101E1800280000F061F8F5E7162303600120F1E7D8 +:101E28000020EFE71623036001204042EAE7C0469E +:101E380070B505000C001F291DD8436C002B10D06D +:101E4800A2009B181A68002A09D0511C11D0012A37 +:101E58000DD00021200019609047002070BD01209E +:101E6800FCE7FFF77DFF002805D16B6CE8E703204E +:101E7800F4E70220F2E701204042EFE710B5034BF8 +:101E880001001868FFF7A8FF10BDC04658000020E1 +:101E980010B5044B0A001B6801001800FFF780FF0B +:101EA80010BDC04658000020054B10B51B68002027 +:101EB8005A6C002A00D010BD1800FFF751FFFAE74E +:101EC8005800002010B5034B01001868FFF7B0FF59 +:101ED80010BDC04658000020002370B5074C05000F +:101EE80008001100236000F029F9431C00D070BDE0 +:101EF8002368002BFBD02B60F9E7C046580100206F +:101F080010B500F00BF910BD70B50C000E25495F37 +:101F180000F0B6F8002803DB636D1B18636570BD1D +:101F2800A389024A1340A381F9E7C046FFEFFFFFE8 +:101F380000207047F8B516001F000C228B5E0C00BD +:101F480005000E22895EDA0508D4094A28001340E4 +:101F5800A38132003B0000F029F8F8BD00220223DB +:101F680000F070F80C22A35E0E22A15EEDE7C046D9 +:101F7800FFEFFFFF70B50C000E25495F00F062F817 +:101F8800431C06D08023A2895B011343A3816065AB +:101F980070BDA389014A1340A381F9E7FFEFFFFF52 +:101FA80010B50E23C95E00F015F810BD70B5050018 +:101FB800080011000022064C22601A0000F0E4F824 +:101FC800431C00D070BD2368002BFBD02B60F9E7C1 +:101FD80058010020002370B5064C05000800236056 +:101FE80000F08CF8431C00D070BD2368002BFBD098 +:101FF8002B60F9E758010020002370B5074C050055 +:1020080008001100236000F081F8431C00D070BD67 +:102018002368002BFBD02B60F9E7C046580100204D +:10202800002370B5064C05000800236000F07EF818 +:10203800431C00D070BD2368002BFBD02B60F9E750 +:102048005801002070B50500080011000022064C58 +:1020580022601A0000F07AF8431C00D070BD236893 +:10206800002BFBD02B60F9E7580100200B1F1B68E1 +:10207800181F002B00DB70470B58C018FBE7C04641 +:1020880070B50500080011000022064C22601A00F5 +:1020980000F064F8431C00D070BD2368002BFBD00F +:1020A8002B60F9E758010020F0B5CE4647461504E5 +:1020B8002D0C2E0080B50704140C3F0C9946030C18 +:1020C8007E435D43674363437F19340CE4199C46A0 +:1020D800A54203D980235B029846C4444B46434338 +:1020E8005143250C36046544360C2404A4195B19A5 +:1020F800591820000CBC90469946F0BD5822012082 +:10210800014B40421A6070475801002058220120B4 +:10211800014B40421A6070475801002058220120A4 +:10212800014B40421A607047580100205822024B68 +:1021380000201A607047C04658010020582201202C +:10214800014B40421A607047580100205822012074 +:10215800014B40421A607047580100205822012064 +:10216800014B40421A60704758010020044A136826 +:10217800002B03D01818106018007047014BF9E7BE +:10218800E40000206001002058220120014B404259 +:102198001A60704758010020FEE7C046002382B04D +:1021A800054A0193019B934201D902B07047019BF4 +:1021B80001330193F6E7C046FE0F00000378002BB9 +:1021C80000D17047033B03700130F7E710B50400F6 +:1021D8002078013400F064F92378002BF8D110BD81 +:1021E800F8B504000E0005002B1B9E4204DC0023FA +:1021F800A419013C23700AE000F03AF92F00287076 +:102208000028F9D001350A28EED100233B70F8BD2B +:1022180030B58BB000F070F800F09AF800F0D8F8FC +:10222800294C02AD2000FFF7C9FFA01DFFF7C6FF2C +:102238002648FFF7CBFF2648FFF7C8FFFFF7AEFF9A +:102248002448FFF7C3FFFFF7A9FF2348FFF7BEFFA6 +:10225800FFF7A4FF2148FFF7B9FFFFF79FFF2048CA +:10226800FFF7B4FF1F48FFF7B1FF00F0F9F81E4869 +:10227800FFF7ACFF20212800FFF7B2FF00F0E8F8D5 +:102288000023E15CEA5C914217D10133062BF8D1B7 +:102298001648FFF79BFFA01DFFF798FF0CE0019B76 +:1022A80001330193019B8B42F9DBFFF777FFFFF7BF +:1022B80075FF0F48FFF78AFFFEE7FEF7D3F90D49D0 +:1022C800FEF724F90023ECE700000020842F000823 +:1022D800A72F0008C42F0008E12F0008FE2F0008D0 +:1022E8001B3000081E3000084D3000088030000800 +:1022F80071300008A0860100F0B590270024012560 +:102308000326042397B0FF0505A938000593069511 +:102318000794089600F046FB102305A9380005939A +:1023280006950794089600F03DFB05230AA80B9331 +:102338000A960D94139400F0C9F80723210001A808 +:10234800019302950394049400F0A2FA17B0F0BD2B +:10235800802170B51B4C8902626988B00A436261AA +:10236800636990200B400193019BC023DB0003931A +:1023780001250223032603A9C005049305950795A3 +:10238800069600F00FFB8021A269C9010A43A261E9 +:10239800A3690D480B400293029B236BB3431D4373 +:1023A8000A4B2563036096231B0243600023836066 +:1023B800C360036183610C33436100F06BFC08B0B8 +:1023C80070BDC04600100240E800002000380140FF +:1023D80080201E4AF0B5516980020143516153695A +:1023E80087B0034090240093012500260327009B13 +:1023F8008023E40501A92000019302950396049720 +:1024080000F0D0FA102301A9200001930295039649 +:10241800049700F0C7FA042301A92000019302954C +:102428000396049700F0BEFA32002000802100F0E5 +:1024380069FB2A002000102100F064FB2A00042117 +:10244800200000F05FFB07B0F0BDC046001002405E +:10245800902010B501228021C00500F053FB10BD6B +:10246800902010B500228021C00500F04BFB10BD64 +:1024780037B508256B46DC1D0122322321000648AA +:1024880000F03AFC002801D120783EBD034A136AC7 +:102498002B431362EEE7C046E800002000380140F5 +:1024A80007B56B46D91D0870024B0122024800F09F +:1024B80099FC07BD88130000E8000020024B18684B +:1024C800421C1A607047C046D8000020F0B5036867 +:1024D80085B00500DB072FD42B689B0700D581E06A +:1024E8002B681B0700D5BCE02B685B0700D5DFE035 +:1024F8002B68DB061AD56A69B54C0423012A00D07B +:102508004BE1616B02260B436363636B1A4362639F +:10251800FFF7D4FF0700636B334200D136E1F8219F +:10252800626BAB698A43DB0013436363296A002942 +:1025380000D059E1002013E00C21A54C62680A4044 +:10254800042A06D063680B40082B0BD16368DB03B1 +:1025580008D523689B03BFD56B68002BBCD101202D +:1025680005B0F0BD6B68012B13D1802322685B0294 +:1025780013432360FFF7A2FF80260700B6022368F3 +:102588003342A9D1FFF79AFFC01B6428F7D903206B +:10259800E6E7002B16D123688E4A80261340236075 +:1025A80023688D4AB60213402360FFF787FF0700B0 +:1025B8002368334200D18FE7FFF780FFC01B6428F0 +:1025C800F6D9E4E7052B05D180232268DB02134303 +:1025D8002360CAE723687F4A1340236023687E4A42 +:1025E8001340C6E70C227A4C6368134206D063682E +:1025F8001340082B10D16368DB030DD423689B07B5 +:1026080002D5EB68012BAAD1F82122682B698A43ED +:10261800DB001343236063E7EA680123002A0FD035 +:102628002268022613432360FFF748FF0700236848 +:102638003342E9D1FFF742FFC01B0228F7D9A6E7CA +:10264800226802269A432260FFF738FF07002368B2 +:10265800334200D144E7FFF731FFC01B0228F6D907 +:1026680095E7EA6901235A4C002A10D0626A0226CB +:1026780013436362FFF722FF0700636A334200D007 +:1026880032E7FFF71BFFC01B0228F6D97FE7626A13 +:1026980002269A436262FFF711FF0700636A33421A +:1026A80000D121E7FFF70AFFC01B0228F6D96EE721 +:1026B80080220021464C5205E3690091134208D15B +:1026C800E3691343E361E36913400393039B012325 +:1026D80000938027414E7F0033683B4206D0AB68A9 +:1026E800012B13D1226A1343236230E033683B4342 +:1026F8003360FFF7E3FE019033683B42EFD1FFF709 +:10270800DDFE019BC01A6428F6D940E70122002BA0 +:1027180014D1236A022793432362236A0332934323 +:102728002362FFF7CBFE0600236A3B4225D0FFF762 +:10273800C5FE2B4B801B9842F6D928E7052B0BD1F9 +:10274800216A013B0B432362236A1A432262FFF783 +:10275800B5FE022706000DE0236A93430422236294 +:10276800236A9343C0E7FFF7A9FE1D4B801B9842DD +:1027780000D90CE7236A3B42F5D0009B012B00D01F +:10278800B6E6E369174A1340E361B1E6FFF796FE40 +:10279800C01B022800D8BEE6F9E6053203D1626BF9 +:1027A8009A436263BBE6626B0226134301226363AA +:1027B800636B93436363FFF781FE0700636B3342E8 +:1027C80000D1B3E6FFF77AFEC01B0228F6D9DEE691 +:1027D80000100240FFFFFEFFFFFFFBFF00700040FC +:1027E80088130000FFFFFFEF0C22264C01206368CE +:1027F8001340082B00D1B3E62368234A1340236013 +:1028080002292FD1FFF75AFE80260700B604236855 +:10281800334221D10F22E36A9343EA6A1343E36206 +:10282800696AAB6A62680B43184980250A401343FA +:102838006360802322685B0413432360FFF73EFE36 +:102848000600AD0423682B4200D073E6FFF736FE7E +:10285800801B0228F6D99AE6FFF730FEC01B022833 +:10286800D5D994E6FFF72AFE80250600AD04236833 +:102878002B4200D15EE6FFF721FE801B0228F6D925 +:1028880085E6C04600100240FFFFFFFEFFFFC2FFC3 +:10289800F7B501223E4C060023680F0013408B4217 +:1028A80012D33268930719D4D3071FD4012322689F +:1028B8001A40BA425DD833685B0761D4E122354BD0 +:1028C800D2031A60002008E0236893430B43236077 +:1028D800236813408B42E4D00120FEBDF0202E492E +:1028E8004B688343B06803434B60DDE72A4D726849 +:1028F8002B68012A1AD19B03EED503216B688B4301 +:1029080013436B60FFF7DAFD73680190012B15D153 +:102918000C226B681340042BC8D0FFF7CFFD019B36 +:10292800C01A1E4B9842F3D90320D6E7022A02D1D7 +:102938009B01E2D4D0E79B07DFD4CDE7022B12D06E +:102948000C226B681342B1D0FFF7B8FD019BC01A87 +:10295800124B9842F4D9E7E7FFF7B0FD019BC01A84 +:102968000E4B9842E0D80C226B681340082BF3D129 +:102978009CE722689A43226022681A429BD0ABE700 +:10298800054A074953680B40F1680B43536095E7C4 +:10299800002002405400002000100240881300006C +:1029A800FFF8FFFFF0B50B6887B003930023019190 +:1029B800039ADA4001D107B0F0BD01229A40029291 +:1029C8000299039A0A40009200D18CE0019A1021E2 +:1029D800526816008E43022E0ED107251D40AD0009 +:1029E8000139A940DC08A4000419276A8F4301991A +:1029F8000969A9400F43276203245F00BC40E443F0 +:102A08000568013E2540AC4603251540BD4061469A +:102A18000D430560012E0FD801998668CD682640C0 +:102A2800BD40354385604668029915098E430121EA +:102A38000D409D4035434560C56801992C408D681F +:102A48008021BD4049052C43C4600A424BD0012176 +:102A5800264C0326A5691E400D43A561A4699D085F +:102A68000C400594059C0F242149AD00B6006D1853 +:102A7800B4409021AF68C905A743002488420CD010 +:102A88001C490134884208D01B490134884204D0CB +:102A98001A490134884200D00234B44000993C43BA +:102AA8000E00AC60164CCD4327683E43D10301D4D9 +:102AB8003E002E4026606768009E3E43910301D485 +:102AC8003E002E406660A768009E3E43D10201D4B6 +:102AD8003E002E40A660E668009F3743920201D46C +:102AE8002E403700E760013362E7C046001002401D +:102AF800000001400004004800080048000C00489D +:102B080000040140002A01D0816170478162FCE71E +:102B1800F8B504000E0015001F002268D369334081 +:102B28009B1B59424B41AB4201D0002018E0069B49 +:102B38000133F3D0069B002B13D123680C491A6884 +:102B480003200A401A609A68A331FF318A439A60C9 +:102B580022002023693213705370002368342370D5 +:102B6800F8BDFFF7ABFC069BC01B9842D5D9E4E73C +:102B78005FFEFFFF030070B59A681C690568224371 +:102B88005C69C169224328683B4C0A4320400243E0 +:102B98002A606A6839481C6A0240D86802436A6039 +:102BA8009A69A8682243364C204002430320AA6051 +:102BB800344A126B02403448845C802212029142EB +:102BC80030D1082C2BD82000FDF726FB0529162923 +:102BD8001F29292924005968E12348081B04C01823 +:102BE800FDF724FB80B202000F2300079A43400F31 +:102BF8001043E860200070BD5968244B4808C0188D +:102C0800FDF714FB002480B2EDE75968E12348087A +:102C18001B04F4E75968802348085B02EFE70124A6 +:102C28000020E0E7082C24D82000FDF7F5FA05225B +:102C38000E22182222221D005968E1234808DB03CE +:102C4800C018FDF7F3FA80B2D3E75968104B48086B +:102C5800C018FDF7EBFA80B2E8600024CAE75968AB +:102C6800E1234808DB03F3E75968802348081B027F +:102C7800EEE70124BEE7C046F369FFFFFFCFFFFF81 +:102C8800FFF4FFFF001002401C2F00080048E80175 +:102C98000024F40070B5041E01D1012070BD0500A8 +:102CA80069352B78DBB2002B02D102006832137031 +:102CB8002423012622682B7013682000B343136075 +:102CC800FFF758FFB042E8D023680A495A68002045 +:102CD8000A4008215A609A688A439A601A6816431B +:102CE80022001E602023E0666A3268342B7013705D +:102CF8002070D3E7FFF7FFFFF0B51F0003006A332A +:102D080016001A78040085B00D000220202A39D157 +:102D18000138002936D0002E34D08022A168520113 +:102D2800914204D12269002A01D105422AD1220008 +:102D3800683211780220012924D001211170002263 +:102D4800E26622321A70FFF7B9FB23008021A268DD +:102D580058331E805E800390490104338A4215D19E +:102D68002269002A10D11E4A1A801E8822005A326F +:102D7800108880B2002810D1230020226A336834DA +:102D88001A70207005B0F0BDFF22EDE7002AECD1E3 +:102D98002269002AF8D07F22E6E713882021013B28 +:102DA8009BB2138020000097039B0022FFF7B0FE20 +:102DB800002813D1A2682368110080225201914291 +:102DC80007D12269002A04D19B8C33402B8002351D +:102DD800CCE79B8C33402B700135C7E70320D1E744 +:102DE800FF010000F0B5070085B0039369373B7811 +:102DF80004000D0016000220202B46D101380029BE +:102E080043D0002A41D08023A2685B019A4204D1B2 +:102E18002369002B01D1014237D1230068331A7886 +:102E28000220012A31D001221A700023E3662133DF +:102E38003B70FFF743FB230050331E805E808026E3 +:102E480002907601210052310A8892B2002A0DD1EF +:102E5800039B402100932000029BFFF759FE0028A6 +:102E680012D1202368343B7020700EE00B880022BA +:102E7800013B9BB20B80039B802100932000029BA7 +:102E8800FFF746FE002802D0032005B0F0BDA36876 +:102E98002268B34208D12369002B05D12B8802355B +:102EA800DB05DB0D1385CDE72B7801351385C9E7E5 +:102EB800002103E00B4B5B58435004310A480B4B8D +:102EC80042189A42F6D30A4A02E0002313600432F9 +:102ED800084B9A42F9D300E000BFFDF71DFBFFF74E +:102EE80097F9FEE76C31000800000020BC000020C4 +:102EF800BC0000205C010020FEE70000F8B5C046D9 +:102F0800F8BC08BC9E467047F8B5C046F8BC08BC7B +:042F18009E4670471A +:102F1C00000408025C00002000000000000000001B +:102F2C000000000000000000000000000000000095 +:102F3C000000000000000000000000000000000085 +:102F4C000000000000000000000000000000000075 +:102F5C000000000000000000000000000000000065 +:102F6C000000000000000000000000000000000055 +:102F7C0000000000000000002A2A2A2A2A53616659 +:102F8C00652D6F2D6D6174696320333030302042B4 +:102F9C006F6F74696E672E2E2E0A00416C69676E16 +:102FAC00696E6720626974732E2E2E2E2E2E2E2E95 +:102FBC005B444F4E455D0A00436865636B696E6701 +:102FCC002043657369756D20524E472E2E5B444F1E +:102FDC004E455D0A004D6173717565726164696E71 +:102FEC006720666C6173682E2E2E5B444F4E455DD8 +:102FFC000A0044656372797074696E672064617449 +:10300C0061626173652E2E5B444F4E455D0A000A6A +:10301C000A005741524E494E473A20554E4155549D +:10302C00484F52495A454420414343455353205736 +:10303C00494C4C2042452050554E49534845440A72 +:10304C0000506C6561736520656E746572207061EB +:10305C007373776F726420746F20636F6E74696E14 +:10306C0075653A200050415353574F524420464106 +:10307C00494C0A00416363657373206772616E7417 +:10308C0065642C2057656C636F6D65210A00000028 +:10309C005245454E54206D616C6C6F6320737563A3 +:1030AC0063656564656400002E2E2F2E2E2F2E2E48 +:1030BC002F2E2E2F2E2E2F2E2E2F2E2E2F2E2E2F1E +:1030CC006E65776C69622F6C6962632F7374646CC4 +:1030DC0069622F72616E642E630000002C2066758D +:1030EC006E6374696F6E3A20000000006173736543 +:1030FC007274696F6E2022257322206661696C657B +:10310C00643A2066696C6520222573222C206C6938 +:10311C006E65202564257325730A0000232D302B42 +:10312C0020000000686C4C0065666745464700004F +:10313C0030313233343536373839414243444546E1 +:10314C0000000000303132333435363738396162A3 +:08315C006364656600000000D9 +:04316400FD01000861 +:04316800D101000889 +:10316C007565377A72006B777773763D3232736898 +:10317C007576723177686F68667270307364756CCF +:10318C00767768666B31697532786E786B716832F8 +:10319C004C5A464F544959445A474535584B45505B +:1031AC004436474C574E3744525049484D5750447B +:1031BC003200000000127A005C00002000000000C9 +:1031CC00642F0008442F0008242F00080000000082 +:1031DC0000000000000000000000000000000000E3 +:1031EC0000000000000000000000000000000000D3 +:1031FC0000000000000000000000000000000000C3 +:10320C0000000000000000000000000000000000B2 +:0C321C00000000000000000000000000A6 +:0400000508002EB908 +:00000001FF diff --git a/A1/tp-spa/img/passwdcheck-main.png b/A1/tp-spa/img/passwdcheck-main.png new file mode 100644 index 0000000..603eec9 Binary files /dev/null and b/A1/tp-spa/img/passwdcheck-main.png differ diff --git a/A1/tp-spa/img/passwdcheck.c.html b/A1/tp-spa/img/passwdcheck.c.html new file mode 100644 index 0000000..51a3872 --- /dev/null +++ b/A1/tp-spa/img/passwdcheck.c.html @@ -0,0 +1,370 @@ + + + + + passwdcheck.c + + + +
+ /*
+   This file is part of the ChipWhisperer Example Targets
+   Copyright (C) 2012-2015 NewAE Technology Inc.
+ 
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+ 
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+ 
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+ 
+ #include "hal.h"
+ #include <stdint.h>
+ #include <stdlib.h>
+ #include <stdio.h>
+ 
+ #define BUFLEN 64
+ 
+ static void delay_2_ms(void);
+ 
+ void my_puts(char *c)
+ {
+   do {
+     putch(*c);
+ 
+   } while (*++c);
+ }
+ 
+static void delay_2_ms()
+{
+  for (volatile unsigned int i=0; i < 0xfff; i++ ){
+    ;
+  }
+}
+
+void my_read(char *buf, int len)
+{
+  for(int i = 0; i < len; i++) {
+    while (buf[i] = getch(), buf[i] == '\0');
+
+    if (buf[i] == '\n') {
+      buf[i] = '\0';
+      return;
+    }
+  }
+  buf[len - 1] = '\0';
+}
+
+int main(void)
+{
+  platform_init();
+  init_uart();
+
+  char passwd[32];
+  char correct_passwd[] = "xxxxx";
+
+  while(1){
+
+    my_puts("*****Safe-o-matic 3000 Booting...\n");
+
+    //Give them one last warning
+    my_puts("WARNING: UNAUTHORIZED ACCESS WILL BE PUNISHED\n");
+
+    //Get password
+    my_puts("Please enter password to continue: ");
+    my_read(passwd, 32);
+
+    uint8_t passbad = 0;
+    for(uint8_t i = 0; i < sizeof(correct_passwd); i++){
+      if (correct_passwd[i] != passwd[i]){
+        passbad = 1;
+        break;
+      }
+    }
+
+    if (passbad){
+      delay_2_ms();
+      delay_2_ms();
+      my_puts("Wrong password. Access denied!\n");
+      my_puts("\n");
+      led_error(1);
+    } else {
+      my_puts("Access granted, welcome!\n");
+      led_ok(1);
+    }
+
+    //All done;
+    while(1);
+  }
+
+  return 1;
+}
+
+
+
+ + diff --git a/A1/tp-spa/img/spa_password_diffexample.png b/A1/tp-spa/img/spa_password_diffexample.png new file mode 100644 index 0000000..cb9c718 Binary files /dev/null and b/A1/tp-spa/img/spa_password_diffexample.png differ diff --git a/A1/tp-spa/img/spa_password_h_vs_0_overview.png b/A1/tp-spa/img/spa_password_h_vs_0_overview.png new file mode 100644 index 0000000..fb8181b Binary files /dev/null and b/A1/tp-spa/img/spa_password_h_vs_0_overview.png differ diff --git a/A1/tp-spa/img/spa_password_h_vs_0_zoomed.png b/A1/tp-spa/img/spa_password_h_vs_0_zoomed.png new file mode 100644 index 0000000..ec8a613 Binary files /dev/null and b/A1/tp-spa/img/spa_password_h_vs_0_zoomed.png differ diff --git a/A1/tp-spa/img/spa_password_list_char1.png b/A1/tp-spa/img/spa_password_list_char1.png new file mode 100644 index 0000000..034c144 Binary files /dev/null and b/A1/tp-spa/img/spa_password_list_char1.png differ diff --git a/A1/tp-spa/passwdcheck.c b/A1/tp-spa/passwdcheck.c new file mode 100644 index 0000000..56278ef --- /dev/null +++ b/A1/tp-spa/passwdcheck.c @@ -0,0 +1,101 @@ +/* + This file is part of the ChipWhisperer Example Targets + Copyright (C) 2012-2015 NewAE Technology Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "hal.h" +#include +#include +#include + +#define BUFLEN 64 + +static void delay_2_ms(void); + +void my_puts(char *c) +{ + do { + putch(*c); + + } while (*++c); +} + +static void delay_2_ms() +{ + for (volatile unsigned int i=0; i < 0xfff; i++ ){ + ; + } +} + +void my_read(char *buf, int len) +{ + for(int i = 0; i < len; i++) { + while (buf[i] = getch(), buf[i] == '\0'); + + if (buf[i] == '\n') { + buf[i] = '\0'; + return; + } + } + buf[len - 1] = '\0'; +} + +int main(void) +{ + platform_init(); + init_uart(); + + char passwd[32]; + char correct_passwd[] = "xxxxx"; + + while(1){ + + my_puts("*****Safe-o-matic 3000 Booting...\n"); + + //Give them one last warning + my_puts("WARNING: UNAUTHORIZED ACCESS WILL BE PUNISHED\n"); + + //Get password + my_puts("Please enter password to continue: "); + my_read(passwd, 32); + + uint8_t passbad = 0; + for(uint8_t i = 0; i < sizeof(correct_passwd); i++){ + if (correct_passwd[i] != passwd[i]){ + passbad = 1; + break; + } + } + + if (passbad){ + delay_2_ms(); + delay_2_ms(); + my_puts("Wrong password. Access denied!\n"); + my_puts("\n"); + led_error(1); + } else { + my_puts("Access granted, welcome!\n"); + led_ok(1); + } + + //All done; + while(1); + } + + return 1; +} + + diff --git a/A1/tp-spa/requirements.txt b/A1/tp-spa/requirements.txt new file mode 100644 index 0000000..8ac75b1 --- /dev/null +++ b/A1/tp-spa/requirements.txt @@ -0,0 +1,8 @@ +ipython +jupyter_client +jupyter +jupyter_contrib_nbextensions +nbparameterise +matplotlib +numpy + diff --git a/A1/tp-spa/scripts/Setup_CW308_87C51.ipynb b/A1/tp-spa/scripts/Setup_CW308_87C51.ipynb new file mode 100644 index 0000000..a98ac61 --- /dev/null +++ b/A1/tp-spa/scripts/Setup_CW308_87C51.ipynb @@ -0,0 +1,87 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import chipwhisperer as cw\n", + "\n", + "try:\n", + " if not scope.connectStatus:\n", + " scope.con()\n", + "except NameError:\n", + " scope = cw.scope()\n", + "\n", + "try:\n", + " if SS_VER == \"SS_VER_2_1\":\n", + " target_type = cw.targets.SimpleSerial2\n", + " elif SS_VER == \"SS_VER_2_0\":\n", + " raise OSError(\"SS_VER_2_0 is deprecated. Use SS_VER_2_1\")\n", + " else:\n", + " target_type = cw.targets.SimpleSerial\n", + "except:\n", + " SS_VER=\"SS_VER_1_1\"\n", + " target_type = cw.targets.SimpleSerial\n", + "\n", + "try:\n", + " target = cw.target(scope, target_type)\n", + "except:\n", + " print(\"INFO: Caught exception on reconnecting to target - attempting to reconnect to scope first.\")\n", + " print(\"INFO: This is a work-around when USB has died without Python knowing. Ignore errors above this line.\")\n", + " scope = cw.scope()\n", + " target = cw.target(scope, target_type)\n", + "\n", + "\n", + "print(\"INFO: Found ChipWhisperer😍\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "scope.default_seutp()\n", + "target.baud = 4800\n", + "#Reset chip - this is NEEDED for device to start.\n", + "#Also you can reset it \n", + "def reset_target(scope):\n", + " scope.io.tio3 = False\n", + " time.sleep(0.05)\n", + " scope.io.tio3 = True\n", + " time.sleep(0.05)\n", + " scope.io.tio3 = False\n", + " \n", + "reset_target(scope)\n", + "\n", + "print(\"**************************************************************\")\n", + "print(\"Use jumpers on H1/H3/H5 to select application. \")\n", + "print(\"Default should work by opening terminal & see testing printed.\")\n", + "print(\"Call reset_8751() to reset target (needed when changing jumpers\")" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/A1/tp-spa/scripts/Setup_CW308_CEC1702.ipynb b/A1/tp-spa/scripts/Setup_CW308_CEC1702.ipynb new file mode 100644 index 0000000..34ce7f6 --- /dev/null +++ b/A1/tp-spa/scripts/Setup_CW308_CEC1702.ipynb @@ -0,0 +1,94 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import chipwhisperer as cw\n", + "\n", + "try:\n", + " if not scope.connectStatus:\n", + " scope.con()\n", + "except NameError:\n", + " scope = cw.scope()\n", + "\n", + "try:\n", + " if SS_VER == \"SS_VER_2_1\":\n", + " target_type = cw.targets.SimpleSerial2\n", + " elif SS_VER == \"SS_VER_2_0\":\n", + " raise OSError(\"SS_VER_2_0 is deprecated. Use SS_VER_2_1\")\n", + " else:\n", + " target_type = cw.targets.SimpleSerial\n", + "except:\n", + " SS_VER=\"SS_VER_1_1\"\n", + " target_type = cw.targets.SimpleSerial\n", + "\n", + "try:\n", + " target = cw.target(scope, target_type)\n", + "except:\n", + " print(\"INFO: Caught exception on reconnecting to target - attempting to reconnect to scope first.\")\n", + " print(\"INFO: This is a work-around when USB has died without Python knowing. Ignore errors above this line.\")\n", + " scope = cw.scope()\n", + " target = cw.target(scope, target_type)\n", + "\n", + "\n", + "print(\"INFO: Found ChipWhisperer😍\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "print (\"***********************************************\")\n", + "print (\"1. Ensure J3 on UFO Board routines CLKFB to HS1/IN\")\n", + "\n", + "scope.gain.gain = 40\n", + "scope.gain.mode = \"high\"\n", + "scope.adc.samples = 400\n", + "scope.adc.offset = 0\n", + "scope.adc.basic_mode = \"rising_edge\"\n", + "scope.clock.clkgen_src = \"extclk\"\n", + "scope.clock.clkgen_mul = 8\n", + "scope.clock.clkgen_div = 2\n", + "scope.clock.adc_src = \"clkgen_x1\"\n", + "scope.trigger.triggers = \"tio4\"\n", + "scope.io.tio1 = \"serial_rx\"\n", + "scope.io.tio2 = \"serial_tx\"\n", + "scope.io.hs2 = None\n", + "\n", + "ext_freq = scope.clock.freq_ctr\n", + "print(\"Input frequency of %d Hz\" % ext_freq)\n", + "\n", + "if ext_freq > 11850000 and ext_freq < 12150000:\n", + " print(\"CLK frequency in expected range.\")\n", + "else:\n", + " print(\"WARNING: CLK frequency outside of expected range.\")" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/A1/tp-spa/scripts/Setup_CW308_D2000.ipynb b/A1/tp-spa/scripts/Setup_CW308_D2000.ipynb new file mode 100644 index 0000000..acd93a2 --- /dev/null +++ b/A1/tp-spa/scripts/Setup_CW308_D2000.ipynb @@ -0,0 +1,106 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import chipwhisperer as cw\n", + "\n", + "try:\n", + " if not scope.connectStatus:\n", + " scope.con()\n", + "except NameError:\n", + " scope = cw.scope()\n", + "\n", + "try:\n", + " if SS_VER == \"SS_VER_2_1\":\n", + " target_type = cw.targets.SimpleSerial2\n", + " elif SS_VER == \"SS_VER_2_0\":\n", + " raise OSError(\"SS_VER_2_0 is deprecated. Use SS_VER_2_1\")\n", + " else:\n", + " target_type = cw.targets.SimpleSerial\n", + "except:\n", + " SS_VER=\"SS_VER_1_1\"\n", + " target_type = cw.targets.SimpleSerial\n", + "\n", + "try:\n", + " target = cw.target(scope, target_type)\n", + "except:\n", + " print(\"INFO: Caught exception on reconnecting to target - attempting to reconnect to scope first.\")\n", + " print(\"INFO: This is a work-around when USB has died without Python knowing. Ignore errors above this line.\")\n", + " scope = cw.scope()\n", + " target = cw.target(scope, target_type)\n", + "\n", + "\n", + "print(\"INFO: Found ChipWhisperer😍\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "print(\"***********************************************\")\n", + "print(\"1. Ensure J3 on UFO Board routines CLKFB to HS1/IN\")\n", + "print (\"2. Confirm baud settings\")\n", + " \n", + "scope.gain.gain = 45\n", + "scope.adc.samples = 25000\n", + "scope.adc.offset = 0\n", + "scope.adc.basic_mode = \"rising_edge\"\n", + "scope.clock.clkgen_freq = 7370000\n", + "scope.clock.adc_src = \"extclk_x1\"\n", + "scope.trigger.triggers = \"tio4\"\n", + "#TX/RX backwards from XMEGA\n", + "scope.io.tio1 = \"serial_tx\"\n", + "scope.io.tio2 = \"serial_rx\"\n", + "scope.io.hs2 = None\n", + "\n", + "#Sample delay - you may need to increase this!\n", + "time.sleep(0.5)\n", + "\n", + "ext_freq = scope.clock.freq_ctr\n", + "\n", + "if ext_freq > 10:\n", + "\n", + " baud = int((115200 / 32E6) * ext_freq)\n", + " print(\"Based on extclk of %d Hz, setting baud to %d\" % (ext_freq, baud))\n", + " target.baud = baud\n", + " \n", + "else:\n", + " raise IOError(\"Did not detect external clock from D2000. Confirm jumpers and rerun, or increase delay before sample.\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/A1/tp-spa/scripts/Setup_CW308_ESP32.ipynb b/A1/tp-spa/scripts/Setup_CW308_ESP32.ipynb new file mode 100644 index 0000000..958d798 --- /dev/null +++ b/A1/tp-spa/scripts/Setup_CW308_ESP32.ipynb @@ -0,0 +1,112 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import chipwhisperer as cw\n", + "\n", + "try:\n", + " if not scope.connectStatus:\n", + " scope.con()\n", + "except NameError:\n", + " scope = cw.scope()\n", + "\n", + "try:\n", + " if SS_VER == \"SS_VER_2_1\":\n", + " target_type = cw.targets.SimpleSerial2\n", + " elif SS_VER == \"SS_VER_2_0\":\n", + " raise OSError(\"SS_VER_2_0 is deprecated. Use SS_VER_2_1\")\n", + " else:\n", + " target_type = cw.targets.SimpleSerial\n", + "except:\n", + " SS_VER=\"SS_VER_1_1\"\n", + " target_type = cw.targets.SimpleSerial\n", + "\n", + "try:\n", + " target = cw.target(scope, target_type)\n", + "except:\n", + " print(\"INFO: Caught exception on reconnecting to target - attempting to reconnect to scope first.\")\n", + " print(\"INFO: This is a work-around when USB has died without Python knowing. Ignore errors above this line.\")\n", + " scope = cw.scope()\n", + " target = cw.target(scope, target_type)\n", + "\n", + "\n", + "print(\"INFO: Found ChipWhisperer😍\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "scope.gain.gain = 55\n", + "scope.gain.mode = 'high'\n", + "scope.adc.samples = 5000\n", + "scope.adc.offset = 0\n", + "scope.adc.basic_mode = \"rising_edge\"\n", + "scope.clock.clkgen_freq = 7372800\n", + "scope.clock.adc_src = \"clkgen_x4\"\n", + "scope.clock.adc_phase = 128\n", + "scope.trigger.triggers = \"tio4\"\n", + "scope.io.tio1 = \"serial_rx\"\n", + "scope.io.tio2 = \"serial_tx\"\n", + "scope.io.tio3 = True #Run condition\n", + "scope.io.pdic = False #SPI forwarding off\n", + "scope.io.hs2 = \"clkgen\"\n", + "\n", + "target.baud = 38400\n", + "\n", + "print(\"\\n***ESP 32 Target Usage Notes***\")\n", + "print(\" Call set_bootloader to enter BOOTLOADER so external USB-Serial cable will work.\")\n", + "print(\" Call set_run to enter RUN mode.\")\n", + "print(\" Jumper TDI to GND to disable boot-up messages (reduce noise if looking at boot decryption).\")\n", + "\n", + "\n", + "def set_bootloader():\n", + " scope.io.tio3 = False\n", + " scope.io.tio1 = None\n", + " scope.io.tio2 = None\n", + " \n", + " #Toggle reset\n", + " scope.io.nrst = False\n", + " time.sleep(0.05)\n", + " scope.io.nrst = None #Pulls high by default\n", + "\n", + "def set_run():\n", + " scope.io.tio3 = True\n", + " scope.io.tio1 = \"serial_rx\"\n", + " scope.io.tio2 = \"serial_tx\"\n", + " \n", + " #Toggle reset\n", + " scope.io.nrst = False\n", + " time.sleep(0.05)\n", + " scope.io.nrst = None #Pulls high by default" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/A1/tp-spa/scripts/Setup_CW308_MPC5748G.ipynb b/A1/tp-spa/scripts/Setup_CW308_MPC5748G.ipynb new file mode 100644 index 0000000..caf8986 --- /dev/null +++ b/A1/tp-spa/scripts/Setup_CW308_MPC5748G.ipynb @@ -0,0 +1,84 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import chipwhisperer as cw\n", + "\n", + "try:\n", + " if not scope.connectStatus:\n", + " scope.con()\n", + "except NameError:\n", + " scope = cw.scope()\n", + "\n", + "try:\n", + " if SS_VER == \"SS_VER_2_1\":\n", + " target_type = cw.targets.SimpleSerial2\n", + " elif SS_VER == \"SS_VER_2_0\":\n", + " raise OSError(\"SS_VER_2_0 is deprecated. Use SS_VER_2_1\")\n", + " else:\n", + " target_type = cw.targets.SimpleSerial\n", + "except:\n", + " SS_VER=\"SS_VER_1_1\"\n", + " target_type = cw.targets.SimpleSerial\n", + "\n", + "try:\n", + " target = cw.target(scope, target_type)\n", + "except:\n", + " print(\"INFO: Caught exception on reconnecting to target - attempting to reconnect to scope first.\")\n", + " print(\"INFO: This is a work-around when USB has died without Python knowing. Ignore errors above this line.\")\n", + " scope = cw.scope()\n", + " target = cw.target(scope, target_type)\n", + "\n", + "\n", + "print(\"INFO: Found ChipWhisperer😍\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "scope.gain.gain = 45\n", + "scope.adc.samples = 5000\n", + "scope.adc.offset = 0\n", + "scope.adc.basic_mode = \"rising_edge\"\n", + "scope.clock.clkgen_freq = 16000000\n", + "scope.clock.adc_src = \"clkgen_x4\"\n", + "scope.trigger.triggers = \"tio4\"\n", + "scope.io.tio1 = \"serial_rx\"\n", + "scope.io.tio2 = \"serial_tx\"\n", + "scope.io.hs2 = \"clkgen\"\n", + "\n", + "target.baud = 38400\n", + "\n", + "print(\"Ensure CW308 Board has +5.0V power supply\")" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/A1/tp-spa/scripts/Setup_Generic.ipynb b/A1/tp-spa/scripts/Setup_Generic.ipynb new file mode 100644 index 0000000..1eb9b1b --- /dev/null +++ b/A1/tp-spa/scripts/Setup_Generic.ipynb @@ -0,0 +1,104 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import chipwhisperer as cw\n", + "\n", + "try:\n", + " if not scope.connectStatus:\n", + " scope.con()\n", + "except NameError:\n", + " scope = cw.scope()\n", + "\n", + "try:\n", + " if SS_VER == \"SS_VER_2_1\":\n", + " target_type = cw.targets.SimpleSerial2\n", + " elif SS_VER == \"SS_VER_2_0\":\n", + " raise OSError(\"SS_VER_2_0 is deprecated. Use SS_VER_2_1\")\n", + " else:\n", + " target_type = cw.targets.SimpleSerial\n", + "except:\n", + " SS_VER=\"SS_VER_1_1\"\n", + " target_type = cw.targets.SimpleSerial\n", + "\n", + "try:\n", + " target = cw.target(scope, target_type)\n", + "except:\n", + " print(\"INFO: Caught exception on reconnecting to target - attempting to reconnect to scope first.\")\n", + " print(\"INFO: This is a work-around when USB has died without Python knowing. Ignore errors above this line.\")\n", + " scope = cw.scope()\n", + " target = cw.target(scope, target_type)\n", + "\n", + "\n", + "print(\"INFO: Found ChipWhisperer😍\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "if \"STM\" in PLATFORM or PLATFORM == \"CWLITEARM\" or PLATFORM == \"CWNANO\":\n", + " prog = cw.programmers.STM32FProgrammer\n", + "elif PLATFORM == \"CW303\" or PLATFORM == \"CWLITEXMEGA\":\n", + " prog = cw.programmers.XMEGAProgrammer\n", + "elif \"neorv32\" in PLATFORM.lower():\n", + " prog = cw.programmers.NEORV32Programmer\n", + "elif PLATFORM == \"CW308_SAM4S\":\n", + " prog = cw.programmers.SAM4SProgrammer\n", + "else:\n", + " prog = None" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import time\n", + "time.sleep(0.05)\n", + "scope.default_setup()\n", + "def reset_target(scope):\n", + " if PLATFORM == \"CW303\" or PLATFORM == \"CWLITEXMEGA\":\n", + " scope.io.pdic = 'low'\n", + " time.sleep(0.1)\n", + " scope.io.pdic = 'high_z' #XMEGA doesn't like pdic driven high\n", + " time.sleep(0.1) #xmega needs more startup time\n", + " elif \"neorv32\" in PLATFORM.lower():\n", + " raise IOError(\"Default iCE40 neorv32 build does not have external reset - reprogram device to reset\")\n", + " else: \n", + " scope.io.nrst = 'low'\n", + " time.sleep(0.05)\n", + " scope.io.nrst = 'high_z'\n", + " time.sleep(0.05)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.5" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/A1/tp-spa/scripts/Setup_Notduino.ipynb b/A1/tp-spa/scripts/Setup_Notduino.ipynb new file mode 100644 index 0000000..a234b0d --- /dev/null +++ b/A1/tp-spa/scripts/Setup_Notduino.ipynb @@ -0,0 +1,80 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import chipwhisperer as cw\n", + "\n", + "try:\n", + " if not scope.connectStatus:\n", + " scope.con()\n", + "except NameError:\n", + " scope = cw.scope()\n", + "\n", + "try:\n", + " if SS_VER == \"SS_VER_2_1\":\n", + " target_type = cw.targets.SimpleSerial2\n", + " elif SS_VER == \"SS_VER_2_0\":\n", + " raise OSError(\"SS_VER_2_0 is deprecated. Use SS_VER_2_1\")\n", + " else:\n", + " target_type = cw.targets.SimpleSerial\n", + "except:\n", + " SS_VER=\"SS_VER_1_1\"\n", + " target_type = cw.targets.SimpleSerial\n", + "\n", + "try:\n", + " target = cw.target(scope, target_type)\n", + "except:\n", + " print(\"INFO: Caught exception on reconnecting to target - attempting to reconnect to scope first.\")\n", + " print(\"INFO: This is a work-around when USB has died without Python knowing. Ignore errors above this line.\")\n", + " scope = cw.scope()\n", + " target = cw.target(scope, target_type)\n", + "\n", + "\n", + "print(\"INFO: Found ChipWhisperer😍\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "scope.gain.gain = 45\n", + "scope.adc.samples = 3000\n", + "scope.adc.offset = 1250\n", + "scope.adc.basic_mode = \"rising_edge\"\n", + "scope.clock.clkgen_freq = 7370000\n", + "scope.clock.adc_src = \"clkgen_x4\"\n", + "scope.trigger.triggers = \"tio4\"\n", + "scope.io.tio1 = \"serial_tx\"\n", + "scope.io.tio2 = \"serial_rx\"\n", + "scope.io.hs2 = \"clkgen\"" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/A1/tp-spa/traces/lab2_1b_passwords_full.p b/A1/tp-spa/traces/lab2_1b_passwords_full.p new file mode 100644 index 0000000..c3e73b0 Binary files /dev/null and b/A1/tp-spa/traces/lab2_1b_passwords_full.p differ diff --git a/A1/tp-spa/traces/password_hw.ipynb b/A1/tp-spa/traces/password_hw.ipynb new file mode 100644 index 0000000..ca215d8 --- /dev/null +++ b/A1/tp-spa/traces/password_hw.ipynb @@ -0,0 +1,109 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Flash target\n", + "\n", + "import chipwhisperer as cw\n", + "\n", + "PLATFORM='CWNANO'\n", + "\n", + "try:\n", + " %run \"scripts/Setup_Generic.ipynb\"\n", + "except:\n", + " %run \"../scripts/Setup_Generic.ipynb\"\n", + "scope.adc.samples = 1000\n", + "\n", + "programmer = cw.programmers.STM32FProgrammer\n", + "try:\n", + " fw_path = 'hex/basic-passwdcheck-CWNANO.hex'\n", + " cw.program_target(scope, programmer, fw_path)\n", + "except FileNotFoundError:\n", + " fw_path = '../hex/basic-passwdcheck-CWNANO.hex'\n", + " cw.program_target(scope, programmer, fw_path)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "def serial_read():\n", + " res = ''\n", + " num_char = target.in_waiting()\n", + " while num_char > 0:\n", + " res += target.read(num_char, 10)\n", + " time.sleep(0.01)\n", + " num_char = target.in_waiting()\n", + " return res" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "scrolled": true + }, + "outputs": [], + "source": [ + "def cap_pass_trace(password):\n", + " if not password.endswith('\\n'):\n", + " password += '\\n'\n", + " reset_target(scope)\n", + " ret = serial_read()\n", + " scope.arm()\n", + " target.flush()\n", + " target.write(password)\n", + " ret = scope.capture()\n", + " if ret:\n", + " print('Timeout happened during acquisition') \n", + " trace = scope.get_last_trace()\n", + " return trace" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "def pass_response(password):\n", + " if not password.endswith('\\n'):\n", + " password += '\\n'\n", + " reset_target(scope)\n", + " ret = serial_read()\n", + " target.flush()\n", + " target.write(password)\n", + " time.sleep(0.1)\n", + " res = serial_read()\n", + " return res" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.2" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/A1/tp-spa/traces/password_sim.ipynb b/A1/tp-spa/traces/password_sim.ipynb new file mode 100644 index 0000000..d5456fa --- /dev/null +++ b/A1/tp-spa/traces/password_sim.ipynb @@ -0,0 +1,82 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import pickle\n", + "import random\n", + "import time\n", + "\n", + "traces_to_load = pickle.load(open(\"traces/lab2_1b_passwords_full.p\", \"rb\"))\n", + "known_passwd = \"h0px3\"\n", + "\n", + "def cap_pass_trace(pass_guess):\n", + " global traces_to_load, known_passwd\n", + " \n", + " if pass_guess.endswith(\"\\n\") is False:\n", + " raise ValueError(\"Password guess must end with \\\\n\")\n", + " \n", + " pass_guess = pass_guess.strip(\"\\n\")\n", + " \n", + " trylist = \"abcdefghijklmnopqrstuvwxyz0123456789 \\x00\"\n", + " \n", + " if len(pass_guess) > 5:\n", + " raise ValueError(\"Only guesses up to 5 chars recorded, sorry about that.\")\n", + " \n", + " for a in pass_guess:\n", + " if a not in trylist:\n", + " raise ValueError(\"Part of guess (%c) not in recorded enumeration list (%s)\"%(a, trylist))\n", + " \n", + " #Only recorded is correct passwords\n", + " recorded_pw = \"\"\n", + " for i in range(0, len(pass_guess)):\n", + " if known_passwd[i] != pass_guess[i]:\n", + " recorded_pw += \" \"\n", + " else:\n", + " recorded_pw += pass_guess[i]\n", + " \n", + " time.sleep(0.05)\n", + " \n", + " return traces_to_load[recorded_pw][random.randint(0, 99)][:1000]\n", + "\n", + "\n", + "def pass_response(pass_guess):\n", + " if pass_guess.strip(\"\\n\") == known_passwd:\n", + " return \"Access granted, welcome!\"\n", + " else:\n", + " return \"Wrong password. Access denied!\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.2" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}