nxn application to cryptography

Upload: soulsealer

Post on 02-Jun-2018

234 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/10/2019 nxn application to cryptography

    1/34

    ENGG2013 Unit 10

    n n determinant and

    an application to cryptographyFeb, 2011.

  • 8/10/2019 nxn application to cryptography

    2/34

    YesterdayA formula

    for matrix inverse using cofactors

    kshum ENGG2013 2

    Suppose that det Ais nonzero.Three steps in computing above formula

    1. for i,j = 1,2,3, replace each aijby cofactor Cij2. Take the transpose of the resulting matrix.

    3. divide by the determinant of A.

    Usually called the adjoint of A

    cofactors

  • 8/10/2019 nxn application to cryptography

    3/34

    Outline

    nxn determinant

    Caesar Cipher

    Modulo arithmetic Hill Cipher

    kshum ENGG2013 3

  • 8/10/2019 nxn application to cryptography

    4/34

    DETERMINANT IN GENERAL

    kshum ENGG2013 4

  • 8/10/2019 nxn application to cryptography

    5/34

    A pattern

    Arrange the products so that the first

    subscripts are in ascending order.

    All possible orderings of the second subscripts

    appear once and only once.kshum ENGG2013 5

  • 8/10/2019 nxn application to cryptography

    6/34

    Transposition

    A transpositionis an exchange of two objects

    in a list of objects.

    kshum ENGG2013 6

    A B C D

    A C B D

    Examples:

    2 1 4 5 3

    1 2 4 5 3

    Transposition is another

    mathematical term, and is

    not the same as matrix tranpose.

  • 8/10/2019 nxn application to cryptography

    7/34

    Another pattern

    The sign of each term is closely related to the

    number of transpositions required to obtain

    the second subscripts, starting from (1,2) for

    the 2x2 case or (1,2,3) for the 3x3 case.kshum ENGG2013 7

  • 8/10/2019 nxn application to cryptography

    8/34

    The sign

    Let p(1), p(2), , p(n) be an order of 1,2,,n.

    For example p(1)=3, p(2) = 2, p(3)=1 is an ordering

    of 1, 2, 3.

    Starting from (1,2,,n), if we need an oddno.

    of transpositions to get ( p(1), p(2), , p(n) ),

    we define the sign of (p(1), p(2),,p(n)) be1.

    Otherwise, if we need an evenno. of

    transpositions to get ( p(1), p(2), , p(n) ), we

    define the sign of (p(1), p(2),,p(n)) be +1.

    kshum ENGG2013 8

  • 8/10/2019 nxn application to cryptography

    9/34

    Definition of nn determinant

    The summation is over all n! possible

    orderings p= ( p(1), p(2), , p(n) ) of 1,2,,n.

    There are n! terms.

    sgn(p) is either +1 or1, usually called the

    signature or signumof p.

    kshum ENGG2013 9

    http://en.wikipedia.org/wiki/Determinant

    1

    http://en.wikipedia.org/wiki/Determinanthttp://en.wikipedia.org/wiki/Determinant
  • 8/10/2019 nxn application to cryptography

    10/34

    Properties of determinant

    Determinant of nn identity matrix equals 1.

    Exchange two rows (or columns)multiply

    determinant by1.

    Multiply a row (or a column) by a constant k

    multiply the determinant by k.

    Add a constant multiple of a row (column) to

    another row (column)no change

    Additive property as in the 33 and 22 case.

    kshum ENGG2013 10

  • 8/10/2019 nxn application to cryptography

    11/34

    Cofactor and the adjoint formula

    for matrix inverse Cofactors are defined in a similar way as in the 3x3 case.

    The cofactor of the (i,j)-entry of a matrix A, denoted by Cij, isdefined as (1)i+jAij, where A is the determinant of the sub-matrix obtained by removing the i-th row and the j-th column.

    We have similar expansion along a row or a column (alsocalled the Laplace expansion) as in the 3x3 case.

    The adjoint formula:

    kshum ENGG2013 11

    nxn identityA adjoint of A

    The formula in this form holds when det A= 0 also

    transpose

  • 8/10/2019 nxn application to cryptography

    12/34

    CAESAR CIPHER

    kshum ENGG2013 12

  • 8/10/2019 nxn application to cryptography

    13/34

    Caesar and his army

    kshum ENGG2013 13

    ATTACK

    Soldier carrying the

    message ATTACK

    Message may be intercepted

    by enemy

  • 8/10/2019 nxn application to cryptography

    14/34

    Caesar cipher

    kshum ENGG2013 14

    http://en.wikipedia.org/wiki/Caesar_cipher

    ATTACK

    Soldier carrying the

    encrypted message

    DWWDFN

    The encrypted message

    looks random and meaningless

    http://en.wikipedia.org/wiki/Caesar_cipherhttp://en.wikipedia.org/wiki/Caesar_cipher
  • 8/10/2019 nxn application to cryptography

    15/34

    Private key encryption

    kshum ENGG2013 15

    Plain text Encryption

    function Ciphertext

    Plain text Decryptionfunction Ciphertext

    Key

    key

    The value of key is keptsecret

  • 8/10/2019 nxn application to cryptography

    16/34

    Mathematical description

    kshum ENGG2013 16

    ATTACK Shift to the right

    by 3 DWWDFN

    ATTACK Shift to the leftby 3 DWWDFN

    Key =3

    Key = 3

    Caesar cipher is not secure

    enough, because the numberof keys is too small.

  • 8/10/2019 nxn application to cryptography

    17/34

    MODULO ARITHMETIC

    kshum ENGG2013 17

  • 8/10/2019 nxn application to cryptography

    18/34

    Mod 12

    Clock arithmetic

    kshum ENGG2013 18

    121

    2

    9 3

    6

    4

    57

    8

    10

    11

    6+8= 2 mod 12

    5+12 = 5 mod 12

  • 8/10/2019 nxn application to cryptography

    19/34

    Mod 7

    Week arithmetic

    kshum ENGG2013 19

    6

    1+9 = 3 mod 7

    2+3 = 5 mod 7

    Sun Mon Tue Wed Thr Fri Sat

    1

    2 3 4 5 6 7 8

    9 10 11 12 13 14 15

    16 17 18 19 20 21 2223 24 25 26 27 28 29

    30 31

    0 1 2 3 4 5 6

  • 8/10/2019 nxn application to cryptography

    20/34

    Mod 60

    arithmetic

    kshum ENGG2013 20

    http://www.h

    ko.gov.h

    k/gts/time/stemsandbranchesc.h

    tm

    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

    Year of rabbit

    http://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htmhttp://www.hko.gov.hk/gts/time/stemsandbranchesc.htm
  • 8/10/2019 nxn application to cryptography

    21/34

    Mod nformal definition

    nis a fixed positive integer

    Definition: amod nis the remainder of aafter

    division by n.

    Example: 25 = 1 mod 12.

    Addition and multiplication: If the sum or

    product of two integers is larger than or equal

    to n, divide by n and take the remainder.

    Example: 2+10 = 0 mod 12.

    Example: 25 = 3 mod 12.kshum ENGG2013 21

  • 8/10/2019 nxn application to cryptography

    22/34

    More examples

    10 mod 7 = 3

    4+5 mod 7 = 2

    6+7 mod 7 = 6 27 mod 7 = 0

    kshum ENGG2013 22

  • 8/10/2019 nxn application to cryptography

    23/34

    Mod 26

    A B C D E F G H I J K L M

    0 1 2 3 4 5 6 7 8 9 10 11 12

    kshum ENGG2013 23

    N O P Q R S T U V W X Y Z13 14 15 16 17 18 19 20 21 22 23 24 25

    Fix a one-to-one correspondence between the English alphabets

    and the integers mod 26.

    Caesars cipher: shifting a letter to the right by 3

    is the same as adding 3 in mod 26 arithmetic.

  • 8/10/2019 nxn application to cryptography

    24/34

    Examples of mod 26 calculations

    3+19 = ? mod 26

    13+20 = ? mod 26

    34 = ? Mod 26

    134 = ? Mod 26

    kshum ENGG2013 24

    A B C D E F G H I J K L M

    0 1 2 3 4 5 6 7 8 9 10 11 12

    N O P Q R S T U V W X Y Z

    13 14 15 16 17 18 19 20 21 22 23 24 25

  • 8/10/2019 nxn application to cryptography

    25/34

    Peculiar phenomena

    in modulo arithmetic

    Non-zero times non-zero may be zero

    49 = 0 mod 12

    22 = 0 mod 4

    Multiplicative inverse may not exist

    Cannot find an integer x such that 4x = 1 mod 12.

    4-1does not exist mod 12.

    kshum ENGG2013 25

  • 8/10/2019 nxn application to cryptography

    26/34

    No fraction in modulo arithmetic

    In mod 12, dont write 1/3 or 3-1because it

    does not exist.

    But 5-1is well-defined mod 12, because we

    can solve 5x=1 mod 12.

    Indeed, we have 55 = 1 mod 12.

    Therefore 5-1 = 5 mod 12.

    kshum ENGG2013 26

    FractionFact from number theory:multiplicative inverse of x mod n exists

    if and only the gcd of x and n is 1.

  • 8/10/2019 nxn application to cryptography

    27/34

    HILL CIPHER

    kshum ENGG2013 27

  • 8/10/2019 nxn application to cryptography

    28/34

    Hill cipher

    Invented by L. S. Hill in 1929. Inputs : String of English letters, A,B,,Z.

    An nnmatrix K, with entries drawn from 0,1,,25.(The matrix Kserves as the secret key. )

    Divide the input string into blocks of size n. Identify A=0, B=1, C=2, , Z=25.

    Encryption: Multiply each block by Kand thenreduce mod 26.

    Decryption: multiply each block by the inverse ofK, and reduce mod 26.

    kshum ENGG2013 28

    http://en.wikipedia.org/wiki/Hill_cipher

    http://en.wikipedia.org/wiki/Hill_cipherhttp://en.wikipedia.org/wiki/Hill_cipher
  • 8/10/2019 nxn application to cryptography

    29/34

    Note

    The decryption must be the inverse function of

    the encryption function.

    It is required that K-1K= Inmod 26.

    Provided that det(K) has a multiplicative inversemod 26, i.e., if det(K) and n has no common

    factor, the inverse of Kcan be computed by the

    adjoint formula for matrix inverse. Inverse of an integer mod 26 can be obtained by

    trial and error.

    kshum ENGG2013 29

  • 8/10/2019 nxn application to cryptography

    30/34

    Example

    Plain text: LOVE, Secret Key: LO

    VE

    2, 3, 16, 5 are transformed to cipher text

    CDQF

    kshum ENGG2013 30

    A B C D E F G H I J K L M

    0 1 2 3 4 5 6 7 8 9 10 11 12

    N O P Q R S T U V W X Y Z

    13 14 15 16 17 18 19 20 21 22 23 24 25

  • 8/10/2019 nxn application to cryptography

    31/34

    How to decode?

    Given CDQF, and the encryption matrix

    How do we decrypt?

    We need to compute the inverse of

    Remind that all arithmetic are mod 26. There

    is no fraction and care should be taken in

    computing multiplicative inverse mod 26.

    kshum ENGG2013 31

  • 8/10/2019 nxn application to cryptography

    32/34

    Determinant

    The determinant of equals 20(7)-3(15),

    which is 17 mod 26.

    Find the multiplicative inverse of 17 mod 26,

    i.e., find integer x such that 17x = 1 mod 26.

    Just try all 26 possibilities for x:

    kshum ENGG2013 32

    171 = 17 mod 26

    172= 8 mod 26173 = 25 mod 26

    174 = 16 mod 26

    175 = 7 mod 26

    176 = 24 mod 26

    177 = 15 mod 26

    178 = 6 mod 26

    179= 23 mod 261710 = 14 mod 26

    1711 = 5 mod 26

    1712 = 22 mod 26

    1713 = 13 mod 26

    1714 = 4 mod 26

    1715 = 21 mod 26

    1716= 12 mod 261717 = 3 mod 26

    1718 = 20 mod 26

    1719 = 11 mod 26

    1720 = 2 mod 26

    1721 = 19 mod 26

    1722 = 10 mod 261723= 1 mod 26

    1724 = 18 mod 26

    1725 = 9 mod 26

    170 = 0 mod 26

  • 8/10/2019 nxn application to cryptography

    33/34

    Computing the inverse mod 26

    From 1723= 1 mod 26, we know that the

    multiplicative inverse of 17 mod 26 is 23.

    Using the formula for 2 2 matrix inverse

    we get

    kshum ENGG2013 33

    Replace (17)-1mod 26 by 23

  • 8/10/2019 nxn application to cryptography

    34/34

    Decryption

    Given the ciphertext CDQF, we decrypt by

    multiplying by

    From the table in p.23, 11, 14, 21, 4 is LOVE.

    kshum ENGG2013 34