aboutsummaryrefslogtreecommitdiffstats
path: root/wrappers/swig/tests/encrypt.py
blob: 9896777d4a836e6b5ecd884f9e83b5a93376176e (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
#!/usr/bin/python

import sys, botan

def encrypt(input):
    cipher_key = botan.SymmetricKey("AABB")
    print cipher_key.length
    cipher_key = botan.SymmetricKey("AABBCCDD")
    print cipher_key.length

    cipher = botan.Filter("ARC4", key = cipher_key)
    
    pipe = botan.Pipe(cipher, botan.Filter("Hex_Encoder"))

    pipe.start_msg()
    pipe.write(input)
    pipe.end_msg()

    str = pipe.read_all()
    print str
    return str

def decrypt(input):
    pipe = botan.Pipe(botan.Filter("Hex_Decoder"),
                      botan.Filter("ARC4",
                                   key = botan.SymmetricKey("AABBCCDD")))

    pipe.process_msg(input)
    return pipe.read_all()

def main():
    ciphertext = encrypt("hi chappy")
    print ciphertext
    print decrypt(ciphertext)

if __name__ == "__main__":
    sys.exit(main())