Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you fix this code? I have 3 Errors and I don't know how to fix them. my code: def KSA(key): keylength = len(key) S

Can you fix this code? I have 3 Errors and I don't know how to fix them.

my code:

def KSA(key): keylength = len(key) S = range(256) j = 0 for i in range(256): j = (j + S[i] + key[i % keylength]) % 256 S[i], S[j] = S[j], S[i] # swap return S def PRGA(S): i = 0 j = 0 while True: i = (i + 1) % 256 j = (j + S[i]) % 256 S[i], S[j] = S[j], S[i] # swap K = S[(S[i] + S[j]) % 256] yield K def RC4(key): S = KSA(key) return PRGA(S) if __name__ == '__main__': # test vectors are from http://en.wikipedia.org/wiki/RC4 # ciphertext should be BBF316E8D940AF0AD3 key = 'Key' plaintext = 'Plaintext' # ciphertext should be 1021BF0420 #key = 'Wiki' #plaintext = 'pedia' # ciphertext should be 45A01F645FC35B383552544B9BF5 #key = 'Secret' #plaintext = 'Attack at dawn' def convert_key(s): return [ord(c) for c in s] key = convert_key(key) keystream = RC4(key) import sys for c in plaintext: sys.stdout.write("%02X" % (ord(c) ^ keystream.next())) print

output:

Traceback (most recent call last): File "C:/Users/Lenovo/PycharmProjects/python_courses/1DV501-assing3/ASS1computer/cryp.py", line 50, in keystream = RC4(key) File "C:/Users/Lenovo/PycharmProjects/python_courses/1DV501-assing3/ASS1computer/cryp.py", line 27, in RC4 S = KSA(key) File "C:/Users/Lenovo/PycharmProjects/python_courses/1DV501-assing3/ASS1computer/cryp.py", line 9, in KSA S[i], S[j] = S[j], S[i] # swap TypeError: 'range' object does not support item assignment

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

Recommended Textbook for

Hands On Database

Authors: Steve Conger

1st Edition

013610827X, 978-0136108276

More Books

Students also viewed these Databases questions