23.11.2013 Views

Obfuscation of Abstract Data-Types - Rowan

Obfuscation of Abstract Data-Types - Rowan

Obfuscation of Abstract Data-Types - Rowan

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 6. THE MATRIX OBFUSCATED 109<br />

Matrix (α)<br />

Matrix α ::= List (List α) ∧ (∀ mss :: Matrix α • valid mss)<br />

scale :: α → Matrix α → Matrix α<br />

add :: (Matrix α,Matrix α) → Matrix α<br />

transpose :: Matrix α → Matrix α<br />

mult :: (Matrix α,Matrix α) → Matrix α<br />

(!!!) :: Matrix α → N × N → α<br />

transpose · transpose = id<br />

transpose · add = add · cross(transpose, transpose)<br />

transpose · (scale s) = (scale s) · transpose<br />

(add (M,N)) !!! (r,c) = (M !!! (r,c)) + (N !!! (r,c))<br />

transpose (mult (M,N)) = mult (transpose N, transpose M)<br />

add (M,N) = add (N,M)<br />

∣<br />

Figure 6.1: <strong>Data</strong>-type for Matrices<br />

it into four n×n matrices but by padding a matrix with zeros, this method can<br />

be adapted for more general matrices.<br />

We must ensure that when we obfuscate these operations we do not change<br />

the complexity.<br />

6.2.1 Definitions <strong>of</strong> the operations<br />

We now define operations to match the data-type given in Figure 6.1. Two <strong>of</strong><br />

our definitions will use the function zipWith — the definition below contains a<br />

catch-all to deal with the situation where one <strong>of</strong> the lists is empty:<br />

zipWith f (x : xs) (y : ys) = f x y : (zipWith f xs ys)<br />

zipWith f = [ ]<br />

For brevity, we define the infix operation (⊗) to correspond to zipWith ( +).<br />

We define the matrix operations functionally as follows:<br />

scale a mss = map (map (a×)) mss<br />

add (mss,nss) = zipWith (zipWith (+)) mss nss<br />

transposemss = foldr1 (⊗) (map (map wrap) mss)<br />

where wrap x = [x]<br />

mult (mss,nss) = map (row nss) mss<br />

where row nss xs = map (dotp xs) (transpose nss)<br />

dotp ms ns = sum (zipWith (×) ms ns)<br />

mss !!! (r,c) = (mss !! r) !! c

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!