|
|
|
@ -1,10 +1,10 @@
|
|
|
|
|
import random
|
|
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
|
import onetimepad as OT
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestOneTimePad(unittest.TestCase):
|
|
|
|
|
msg = ('HOWMUCHCHUCKCOULDAWOODCHUCKCHUCKIFA'
|
|
|
|
|
'WOODCHUCKCOULDCHUCKWOOD' * 50)
|
|
|
|
|
|
|
|
|
|
def test_mk_as_alpha_excludes_j(self):
|
|
|
|
|
self.assertTrue('J' not in OT._AS_ALPHA.values())
|
|
|
|
@ -20,14 +20,40 @@ class TestOneTimePad(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def test_two_out_of_every_three_lines_are_empty_on_new_pad(self):
|
|
|
|
|
pad = OT.create_pad(2000)
|
|
|
|
|
for i, line in enumerate(pad.splitlines()):
|
|
|
|
|
lineno = i + 3
|
|
|
|
|
if not lineno % 3:
|
|
|
|
|
for lineno, line in enumerate(pad.splitlines()):
|
|
|
|
|
line = line.strip()
|
|
|
|
|
if OT._is_padline(lineno):
|
|
|
|
|
self.assertTrue(bool(len(line)),
|
|
|
|
|
'line {0} is non-empty'.format(lineno))
|
|
|
|
|
'pad line {0} is non-empty'.format(lineno))
|
|
|
|
|
elif OT._is_txtline(lineno):
|
|
|
|
|
self.assertFalse(bool(len(line)),
|
|
|
|
|
'text line {0} is empty'.format(lineno))
|
|
|
|
|
elif OT._is_cypherline(lineno):
|
|
|
|
|
self.assertFalse(bool(len(line)),
|
|
|
|
|
'cypher line {0} is empty'.format(lineno))
|
|
|
|
|
else:
|
|
|
|
|
raise NotImplementedError(lineno)
|
|
|
|
|
|
|
|
|
|
def test_padfill_leaves_every_third_line_empty(self):
|
|
|
|
|
msg = self.msg[:]
|
|
|
|
|
pad = OT.create_pad(len(msg))
|
|
|
|
|
filled = OT._padfill(msg, pad)
|
|
|
|
|
# print filled
|
|
|
|
|
# raise Exception
|
|
|
|
|
self.assertTrue(bool(filled))
|
|
|
|
|
for lineno, line in enumerate(filled.splitlines()):
|
|
|
|
|
line = line.strip()
|
|
|
|
|
if OT._is_cypherline(lineno):
|
|
|
|
|
self.assertFalse(bool(len(line)),
|
|
|
|
|
'line {0} is empty'.format(lineno))
|
|
|
|
|
elif OT._is_txtline(lineno):
|
|
|
|
|
self.assertTrue(bool(len(line)),
|
|
|
|
|
'text line {0} is non-empty'.format(lineno))
|
|
|
|
|
elif OT._is_padline(lineno):
|
|
|
|
|
self.assertTrue(bool(len(line)),
|
|
|
|
|
'pad line {0} is non-empty'.format(lineno))
|
|
|
|
|
else:
|
|
|
|
|
raise NotImplementedError(lineno)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|