Académique Documents
Professionnel Documents
Culture Documents
Key=80000000000000000000
IV=00000000000000000000
Keystream=38EB86FF730D7A9CAF8DF13A4420540D
Key=00400000000000000000
IV=00000000000000000000
Keystream=61208D286BC1DC431171EDA5CAF79D95
Key=00002000000000000000
IV=00000000000000000000
Keystream=C8F9031DABF8DB03FF120D05512B5F24
Key=00000010000000000000
IV=00000000000000000000
Keystream=F7E523040E86EA2C46A2BE705BFC6259
Source Code
class Trivium:
def __init__(self, key, iv):
"""in the beginning we need to transform the key as well as
the IV.
Afterwards we initialize the state."""
self.state = None
self.counter = 0
self.key = key # self._setLength(key)
self.iv = iv # self._setLength(iv)
# Initialize state
# len 100
init_list = list(map(int, list(self.key)))
init_list += list(repeat(0, 20))
# len 84
init_list += list(map(int, list(self.iv)))
init_list += list(repeat(0, 4))
# len 111
init_list += list(repeat(0, 108))
init_list += list([1, 1, 1])
self.state = deque(init_list)
def keystream(self):
"""output keystream
only use this when you know what you are doing!!"""
while self.counter < 2**64:
self.counter += 1
yield self._gen_keystream()
def _gen_keystream(self):
"""this method generates triviums keystream"""
self.state.rotate(1)
self.state[0] = s_3
self.state[100] = s_1
self.state[184] = s_2
return out
import sys
k1="0F62B5085BAE0154A7FA"
i1="288FF65DC42B92F960C7"
for i in range(1):
keystream = []
for j in range(128):
keystream.append(next_key_bit())
print "Stream: "+bits_to_hex(keystream)
def _hex_to_bytes(s):
return [_allbytes[s[i:i+2].upper()] for i in range(0, len(s),
2)]
def hex_to_bits(s):
return [(b >> i) & 1 for b in _hex_to_bytes(s)
for i in range(8)]
def bits_to_hex(b):
return "".join(["%02X" % sum([b[i + j] << j for j in range(8)])
for i in range(0, len(b), 8)])
if __name__ == "__main__":
main()