Question
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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started