|
|
@ -23,40 +23,43 @@ class TestOneTimePad(unittest.TestCase):
|
|
|
|
'{1}, actual={2}'.format(self._padsize,
|
|
|
|
'{1}, actual={2}'.format(self._padsize,
|
|
|
|
width, actual))
|
|
|
|
width, actual))
|
|
|
|
|
|
|
|
|
|
|
|
def test_two_out_of_every_three_lines_are_empty_on_new_pad(self):
|
|
|
|
def test_is_padline(self):
|
|
|
|
pad = OT.create_pad_lines(2000)
|
|
|
|
for lineno in PADLINES:
|
|
|
|
for lineno, line in enumerate(pad):
|
|
|
|
self.assertTrue(OT._is_padline(lineno),
|
|
|
|
line = line.strip()
|
|
|
|
'line {0} is padline'.format(lineno))
|
|
|
|
if OT._is_padline(lineno):
|
|
|
|
for lineno in TEXTLINES:
|
|
|
|
self.assertTrue(bool(len(line)),
|
|
|
|
self.assertFalse(OT._is_padline(lineno),
|
|
|
|
'pad line {0} is non-empty'.format(lineno))
|
|
|
|
'line {0} is not padline'.format(lineno))
|
|
|
|
elif OT._is_txtline(lineno):
|
|
|
|
for lineno in CIPHERLINES:
|
|
|
|
self.assertFalse(bool(len(line)),
|
|
|
|
self.assertFalse(OT._is_padline(lineno),
|
|
|
|
'text line {0} is empty'.format(lineno))
|
|
|
|
'line {0} is not padline'.format(lineno))
|
|
|
|
elif OT._is_cipherline(lineno):
|
|
|
|
|
|
|
|
self.assertFalse(bool(len(line)),
|
|
|
|
def test_is_textline(self):
|
|
|
|
'cipher line {0} is empty'.format(lineno))
|
|
|
|
for lineno in TEXTLINES:
|
|
|
|
else:
|
|
|
|
self.assertTrue(OT._is_textline(lineno),
|
|
|
|
raise NotImplementedError(lineno)
|
|
|
|
'line {0} is textline'.format(lineno))
|
|
|
|
|
|
|
|
for lineno in PADLINES:
|
|
|
|
def test_padfill_leaves_every_third_line_empty(self):
|
|
|
|
self.assertFalse(OT._is_textline(lineno),
|
|
|
|
msg = self.msg[:]
|
|
|
|
'line {0} is not textline'.format(lineno))
|
|
|
|
pad = OT.create_pad(len(msg))
|
|
|
|
for lineno in CIPHERLINES:
|
|
|
|
filled = OT._padfill(msg, pad)
|
|
|
|
self.assertFalse(OT._is_textline(lineno),
|
|
|
|
self.assertTrue(bool(filled))
|
|
|
|
'line {0} is not textline'.format(lineno))
|
|
|
|
for lineno, line in enumerate(filled):
|
|
|
|
|
|
|
|
line = line.strip()
|
|
|
|
def test_is_cipherline(self):
|
|
|
|
if OT._is_cipherline(lineno):
|
|
|
|
for lineno in CIPHERLINES:
|
|
|
|
self.assertFalse(bool(len(line)),
|
|
|
|
self.assertTrue(OT._is_cipherline(lineno),
|
|
|
|
'line {0} is empty'.format(lineno))
|
|
|
|
'line {0} is cipherline'.format(lineno))
|
|
|
|
elif OT._is_txtline(lineno):
|
|
|
|
for lineno in PADLINES:
|
|
|
|
self.assertTrue(bool(len(line)),
|
|
|
|
self.assertFalse(OT._is_cipherline(lineno),
|
|
|
|
'text line {0} is non-empty'.format(lineno))
|
|
|
|
'line {0} is not cipherline'.format(lineno))
|
|
|
|
elif OT._is_padline(lineno):
|
|
|
|
for lineno in TEXTLINES:
|
|
|
|
self.assertTrue(bool(len(line)),
|
|
|
|
self.assertFalse(OT._is_cipherline(lineno),
|
|
|
|
'pad line {0} is non-empty'.format(lineno))
|
|
|
|
'line {0} is not cipherline'.format(lineno))
|
|
|
|
else:
|
|
|
|
|
|
|
|
raise NotImplementedError(lineno)
|
|
|
|
|
|
|
|
|
|
|
|
PADLINES = (1, 4, 7, 10, 13, 16, 19, 22, 25)
|
|
|
|
|
|
|
|
TEXTLINES = (2, 5, 8, 11, 14, 17, 20, 23, 26)
|
|
|
|
|
|
|
|
CIPHERLINES = (3, 6, 9, 12, 15, 18, 21, 24, 27)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
if __name__ == '__main__':
|
|
|
|