Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with using A5/1 and RC4 cipher using R programming. I know how they work on paper/in theory, but I'm having trouble actually

I need help with using A5/1 and RC4 cipher using R programming. I know how they work on paper/in theory, but I'm having trouble actually implementing them in code. I've listed the steps I need to follow. I've finished parts 1 through 7 and part 9 but I'm struggling with parts 8 and 10.

1. Find the 8 bit binary number for the following characters: A, t, @, 17, 9, & [hint: use binary() in package compositions].

2. Find the decimal numbers for the following: "00010110", "00011101", "01011011", "01100101", "00001010", "01100100".

3. For the seed: "MHID9870"

a) Create the UTF8 encoding.

b) Create the 8 bit binary form for the results of a).

c) Split the strings into individual bits.

d) Unlist the result of c).

e) Put the results of d) into one integer vector.

4. Fill three variables x, y, and z with the results of 3 such that x gets the first 19, y gets the next 22, and z gets the last 23 bits. Initialize an integer vector k of length 128.

5. Find the majority value for x[9], y[11] and z[11].

6. Write code for the following: if x steps then shift x to the right by 1 bit. Next assign the appropriate value to x[1]. Do the same for y and z.

7. Create key stream bit by XOR-in the appropriate bits from x, y, and z vectors.

8. Write a function for the above and create a 128 bit key stream with the seed mentioned in question 3. You function should contain two parameters: a seed and a key length.

9. Create an integer vector S with values from 1-5. Swap elements 1 and 4. [Hint: use the swap() function in package seqinr.

10. Implement RC4 for generating key streams. You function should contain two parameters: a seed and a key length.

My code:

#---

#title: 'IS 471: Spring 2018'

#subtitle: Homework 3

#author: Patrick Griffin (UJ72290)

output:

#1

binary(utf8ToInt("A"), mb=7)

binary(utf8ToInt("t"), mb=7)

binary(utf8ToInt("@"),mb=7)

binary(17, mb=7)

binary(9, mb=7)

binary(utf8ToInt("&"), mb=7)

#2

unbinary("01100101")

unbinary("00011101")

unbinary("01011011")

unbinary("01100101")

unbinary("00001010")

unbinary("01100100")

#3

int0 <- utf8ToInt("MHID9870")

bin0 <- binary(int0)

int0 <- unlist(strsplit(bin0, ""))

#4

x <- c(int0[1:19])

y <- c(int0[20:41])

z <- c(int0[42:64])

#5

my_mode <- function(v)

{

freq_count <- table(v)

max_idx <- which.max(freq_count)

m <- names(max_idx)

return(m)

}

maj <- my_mode(c(x[9],y[11],z[11]))

#6

# if x steps

if(x[9]==maj)

{

#calculate value of x[1] **BEFORE** for-loop

x[1] <- xor(x[13],x[16],x[17],x[18])

for(i in x[length(x):2])

{

x[i]=x[i-1]

}

}

#if y steps

if(y[11]==maj)

{

#calculate value of y[1] **BEFORE** for-loop

y[1] <- xor(y[20],y[21])

for(i in y[length(y):2])

{

y[i] <- y[i-1]

}

}

#if z steps

if(z[11]==maj)

{

#calculate value of z[1] **BEFORE** for-loop

z[1] <- xor(z[7],z[20],z[21],z[22])

for(i in z[length(z):2])

{

z[i]=z[i-1]

}

}

#7

#create keystream

keystream <- xor(x[18],y[21],z[22])

#8

#create function to make a 128 bit keystream given a seed and key length

function createKeystream(seed, keylength)

{

keystream[1:128] <- 0

# make binary vector of seed

int1 <- utf8ToInt(seed)

bin1 <- binary(int0)

int1 <- unlist(strsplit(bin0, ""))

# make x, y, and z vectors

x <- c(int0[1:19])

y <- c(int0[20:41])

z <- c(int0[42:64])

# Loop finds majority, steps the corresponding vectors, and calculates keystream bits

for(i=1:128)

{

maj <- my_mode(c(x[9],y[11],z[11]))

if(x[9]==maj)

{

x[1] <- xor(x[13],x[16],x[17],x[18])

for(j in x[length(x):2])

{

x[j]=x[j-1]

}

} #end if (x)

if(y[11]==maj)

{

y[1] <- xor(y[20],y[21])

for(k in y[length(y):2])

{

y[k] <- y[k-1]

}

} #end if (y)

if(z[11]==maj)

{

z[1] <- xor(z[7],z[20],z[21],z[22])

for(l in z[length(z):2])

{

z[l]=z[l-1]

}

} #end if (z)

keystream[i] <- xor(x[18],y[21],z[22])

} #end for-loop

return(keystream)

} #end function

#9

S <- 1:5

Swap(S[1],S[4])

#10

rc4 <- function(seed, key_length)

{

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

LOQ 14-4: What developmental stages did Freud propose?

Answered: 1 week ago

Question

3. What are the current trends in computer hardware platforms?

Answered: 1 week ago