Exemple #1
0
    def test_change(self):
        out = StringIO.StringIO()
        diph.encrypt_first('foo', self.A, out=out)
        cipher_text_1 = out.getvalue()

        out = StringIO.StringIO()
        diph.encrypt('foo', self.A_change, cipher_text_1, out=out)
        cipher_text_2 = out.getvalue()

        self.assertTrue(cipher_text_1 != cipher_text_2)
Exemple #2
0
    def test_decrypt(self):
        out = StringIO.StringIO()
        diph.encrypt_first('foo', self.A, out=out)
        cipher_text = out.getvalue()

        out = StringIO.StringIO()
        diph.decrypt('foo', cipher_text, out=out)
        plain_text = out.getvalue()

        self.assertEquals(self.A, plain_text)
Exemple #3
0
    def test_conflict_print(self):
        out = StringIO.StringIO()
        diph.encrypt_first('foo', self.A, out=out)
        cipher_text_1 = out.getvalue()

        out = StringIO.StringIO()
        diph.encrypt('foo', self.A_change, cipher_text_1, out=out)
        cipher_text_2a = out.getvalue()

        out = StringIO.StringIO()
        diph.encrypt('foo', self.A_change2, cipher_text_1, out=out)
        cipher_text_2b = out.getvalue()

        print cipher_text_2a
        print cipher_text_2b
Exemple #4
0
    def test_no_counter_reuse_on_removal(self):
        """Removing lines from the end of the file makes it easy to
        reuse counters. Test that.
        """

        counters = {}

        out = StringIO.StringIO()
        diph.encrypt_first('foo', self.A, out=out)
        cipher_text_1 = out.getvalue()

        #print cipher_text_1

        for line in cipher_text_1.split('\n'):
            if line.startswith('?c'):
                c, cnt, ciph = line.split()
                counters[cnt] = ciph

        out = StringIO.StringIO()
        diph.encrypt('foo', self.A_remove, cipher_text_1, out=out)
        cipher_text_2 = out.getvalue()

        #print cipher_text_2

        for line in cipher_text_2.split('\n'):
            if line.startswith('?c'):
                c, cnt, ciph = line.split()
                if cnt in counters:
                    self.assertEquals(counters[cnt], ciph)

        out = StringIO.StringIO()
        diph.encrypt('foo', self.A_remove_append, cipher_text_2, out=out)
        cipher_text_3 = out.getvalue()

        #print cipher_text_3

        for line in cipher_text_3.split('\n'):
            if line.startswith('?c'):
                c, cnt, ciph = line.split()
                if cnt in counters:
                    self.assertEquals(counters[cnt], ciph)
Exemple #5
0
    def test_pragma(self):
        out = StringIO.StringIO()
        diph.encrypt_first('foo', self.A_pragma, out=out)
        cipher_text_1 = out.getvalue()

        self.assertTrue('?m 9000' in cipher_text_1)