aboutsummaryrefslogtreecommitdiffstats
path: root/wrappers/swig/tests/block.py
blob: 593937c810cd08e6b413a06cdc19f0cb79037b5d (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
45
46
47
48
49
50
51
52
#!/usr/bin/python

import botan, base64

class MyCipher(botan.BlockCipher):
    def __init__(self):
        botan.BlockCipher.__init__(self, 16, 16, 32, 8)
    def encrypt(self, val):
        print "encrypt", val
        return val.swapcase()
    def decrypt(self, val):
        print "decrypt", val
        return val.swapcase()
    def set_key(self, key):
        print "set_key", key
    def clone(self):
        print "cloning"
        return MyCipher()
    def name(self):
        print "naming"
        return "MyCipher"

cipher = botan.BlockCipher("AES-128")

print cipher.block_size
print cipher.keylength_min
print cipher.keylength_max
print cipher.keylength_mod
print cipher.name()

for kl in range(1, 128):
    if cipher.valid_keylength(kl):
        print "1",
    else:
        print "0",
print
key = botan.SymmetricKey(16)

cipher.set_key(key)
ciphertext = cipher.encrypt("ABCDEFGH12345678")
print base64.b16encode(ciphertext)

cipher2 = cipher.clone()
cipher2.set_key(key)

plaintext = cipher2.decrypt(ciphertext)
print plaintext

botan.get_info(cipher)

mycipher = MyCipher()
botan.get_info(mycipher)