ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 103 Weeks Ago, 3 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 09 May 2017 My Price 9.00

#Define a class RC4

Help please!

Can someone write the code below in Java Language? Its in Ruby.

=========================================================================================

#Define a class RC4

class RC4

     #Define function initialize() with string as argument

     def initialize(str)

    

          #Begin

          begin

         

          #Display message

raise SyntaxError, "RC4: Key supplied is blank" if str.eql?('')

         

          #Call initialize_state()

          initialize_state(str)

         

          #Set q1 and q2 as 0

          @q1, @q2 = 0, 0

          end

         

     #End of function

     end

     #Define function encrypt!()

     def encrypt!(text)

    

          #Set index as 0

          index = 0

          #Loop until length of text

          while index < text.length

          #Set q1

          @q1 = (@q1 + 1) % 256

         

          #Set q2

          @q2 = (@q2 + @state[@q1]) % 256

         

          #State q1 and q2

          @state[@q1], @state[@q2] = @state[@q2], @state[@q1]

         

          #Set byte of text

text.setbyte(index, text.getbyte(index) ^ @state[(@state[@q1] + @state[@q2]) % 256])

         

          #Increment index

          index += 1

         

          #End of loop

          end

         

          #Text

          text

         

     #End of function

     end

     alias_method :decrypt!, :encrypt!

     #Define encrypt()

     def encrypt(text)

          #Call encrypt!()

          encrypt!(text.dup)

     end

     alias_method :decrypt, :encrypt

     private

     # Modified initial state

     INITIAL_STATE = (0..255).to_a

     # Define initialize_state()

     def initialize_state(key)

          #Set i, j as 0

          i = j = 0

          #Set state

          @state = INITIAL_STATE.dup

          #Set key length

          key_length = key.length

          #Loop until 256

          while i < 256

          #Compute j

j = (j + @state[i] + key.getbyte(i % key_length)) % 256

          @state[i], @state[j] = @state[j], @state[i]

         

          #Increment i

          i += 1

        end

     end

end

Answers

(11)
Status NEW Posted 09 May 2017 08:05 AM My Price 9.00

-----------

Attachments

file 1494318195-Solutions file 2.docx preview (51 words )
H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly -----------onl-----------ine----------- an-----------d g-----------ive----------- yo-----------u e-----------xac-----------t f-----------ile----------- an-----------d t-----------he -----------sam-----------e f-----------ile----------- is----------- al-----------so -----------sen-----------t t-----------o y-----------our----------- em-----------ail----------- th-----------at -----------is -----------reg-----------ist-----------ere-----------d o-----------n -----------THI-----------S W-----------EBS-----------ITE-----------. ----------- Th-----------ank----------- yo-----------u -----------
Not Rated(0)