Rename SecureInbox to SecureMail, since it is used for not only ingoing but also...
[easyotp.git] / cotp.py
blob9476f683124b21c938250c1dd699bd3fc9ea9b5e
1 #!/bin/env python
2 import popen2
4 def decode(ct):
5 o, i, e = popen2.popen3("./cotp -d")
6 i.write(ct)
7 i.close()
8 pt = o.read()
9 errors = e.read()
10 if errors:
11 raise errors
12 return pt
14 # TODO: support padname
15 def encode(pt):
16 o, i, e = popen2.popen3("./cotp -e")
17 i.write(pt)
18 i.close()
19 ct = o.read()
20 errors = e.read()
21 if errors:
22 raise errors
23 return ct
25 if __name__ == "__main__":
26 ct = encode("hello world")
27 print ct
28 pt = decode(ct)
29 print pt
30 assert pt == "hello world", "decode failed to match"