summaryrefslogtreecommitdiff
path: root/Wireless_Communications_and_Networking_by_V._Garg/ch13.ipynb
blob: fec2620255e23c484c15be165f4d6f3f8d0073eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
{
 "metadata": {
  "name": "",
  "signature": "sha256:0963e656a45b56e87c82b1b894058e0c0c5d5a3acfd1e2f8850678ef319681b0"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 13: Security in Wireless Systems"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 13.1, Page 424"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "#Two prime numbers\n",
      "p=5;\n",
      "q=7;\n",
      "\n",
      "#Calculations\n",
      "n=p*q;\n",
      "z=(p-1)*(q-1);\n",
      "e=5\n",
      "d=29\n",
      "\n",
      "#Results\n",
      "print 'Public keys is (%d, %d)'%(n,e);\n",
      "print 'Private key is (%d, %d)'%(n,d);\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Public keys is (35, 5)\n",
        "Private key is (35, 29)\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 13.2, Page 425"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "p=23; #prime number that both parties agreed upon\n",
      "g=5;# g is primitive mod p\n",
      "a=6;  #party A choosen number\n",
      "b=15;  #party B choosen number\n",
      "\n",
      "#Calculations&Results\n",
      "print 'Party A sends to party B as (g**a mod p) = %d'%(g**a%23);\n",
      "print 'Party B sends to party A as (g**b mod p) = %d'%(g**b%23);\n",
      "print 'Party A computes secret key as ((g**b modp)**a mod p) = %d'%(((g**b%23)**a)%p);\n",
      "print 'Party B computes secret key as ((g**a modp)**b mod p) = %d'%(((g**a%23)**b)%p);"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Party A sends to party B as (g**a mod p) = 8\n",
        "Party B sends to party A as (g**b mod p) = 19\n",
        "Party A computes secret key as ((g**b modp)**a mod p) = 2\n",
        "Party B computes secret key as ((g**a modp)**b mod p) = 2\n"
       ]
      }
     ],
     "prompt_number": 2
    }
   ],
   "metadata": {}
  }
 ]
}