summaryrefslogtreecommitdiffstats
path: root/botan/wrappers/swig/tests/block2.py
blob: 5faccaf9a312ce5098345e2e1d054c6ca234f9ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/python

import botan, base64

class MyCipher(botan.BlockCipherImpl):
    def __init__(self):
        botan.BlockCipherImpl.__init__(self, 8, 8, 16, 1)

    def name(self):
        return "MyCipher"

    def encrypt(self, input):
        return input.swapcase()

    def decrypt(self, input):
        return input.swapcase()

    def set_key(self, key):
        print "Got key",key

def test(cipher):
    print
    print cipher
    print "Testing", cipher.name()
    print cipher.block_size
    print cipher.keylength_min, cipher.keylength_max, cipher.keylength_mod
    for i in range(1, 64):
        if cipher.valid_keylength(i):
            print "1",
        else:
            print "0",
    print
    cipher.set_key(botan.SymmetricKey(16))
    ciphertext = cipher.encrypt("aBcDeFgH" * (cipher.block_size / 8))
    print repr(ciphertext)
    print cipher.decrypt(ciphertext)

def main():
    test(botan.BlockCipher("Blowfish"))
    test(MyCipher())
    test(botan.BlockCipher("AES"))

if __name__ == "__main__":
    main()