Question: Test case generation for Plain text, cipher text for grain 1 2 8 AEAD stream cipher python code is not working....... import numpy as np
Test case generation for Plain text, cipher text for grainAEAD stream cipher python code is not working.......
import numpy as np
class GrainAEAD:
def initself key, iv:
self.lfsr npzeros dtypenpuint
self.nfsr npzeros dtypenpuint
keybits nparrayintb for b in formatkeyb dtypenpuint
ivbits nparrayintb for b in formativb dtypenpuint
self.nfsr: keybits
self.lfsr: ivbits
self.lfsr: # Set remaining bits to
self.initialize
def fself s:
return s s s s s s
def gself b:
return b b b b bb & b
b & bb & bb & b
b & bb & bb & b
def hself b:
return b b b b b b b
b & bb & bb & b
b & bb & bb & b
def initializeself:
for in range:
fout self.fselflfsr
gout self.gselfnfsr
hout self.hselfnfsr
self.lfsr nprollselflfsr
self.nfsr nprollselfnfsr
self.lfsr fout hout
self.nfsr gout hout
def getkeystreambyteself:
keystream
for i in range:
fout self.fselflfsr
gout self.gselfnfsr
hout self.hselfnfsr
self.lfsr nprollselflfsr
self.nfsr nprollselfnfsr
self.lfsr fout
self.nfsr gout
keystream hout i
return keystream
def encryptself plaintext:
if isinstanceplaintext str:
plaintext plaintext.encode
ciphertext bytearray
for byte in plaintext:
keystreambyte self.getkeystreambyte
ciphertext.appendbyte keystreambyte
return bytesciphertext
def decryptself ciphertext:
return self.encryptciphertext
def generatetestvectors:
key xABCDEFABCDEF
iv xABCDEF
cipher GrainAEADkey iv
testvectors
plaintexts
"Hello, World!",
"Cryptography",
"Secret Message",
"Confidential",
"Secure Data",
"Test Vector
"Private Info",
"Protected",
"Classified",
"Important",
"Data Stream",
"Encryption",
"Algorithm",
"Security",
"Privacy",
"Information",
"Sensitive",
"Top Secret",
"Restricted",
"Final Test"
for plaintext in plaintexts:
cipher GrainAEADkey iv
ciphertext cipher.encryptplaintext
testvectors.append
'plaintext': plaintext,
'ciphertext': ciphertext.hex
'length': lenplaintext
return testvectors
testvectors generatetestvectors
printGrainAEAD Test Vectors:"
print
printfPlaintext:Ciphertext:Length:
print
for vector in testvectors:
printfvectorplaintext::vectorciphertext::vectorlength:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
