-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathexample.py
More file actions
31 lines (22 loc) · 756 Bytes
/
example.py
File metadata and controls
31 lines (22 loc) · 756 Bytes
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
#!/usr/bin/env python3
"""Example usage of the FFX library."""
import ffx
def main():
# Set up parameters
radix = 2
blocksize = 2 ** 10 # 1024 bits
# Create key, tweak, and message
K = ffx.FFXInteger('0' * 128, radix=radix, blocksize=128)
T = ffx.FFXInteger('0' * blocksize, radix=radix, blocksize=blocksize)
X = ffx.FFXInteger('0' * blocksize, radix=radix, blocksize=blocksize)
# Create FFX encrypter
ffx_obj = ffx.new(K.to_bytes(16), radix=radix)
# Encrypt and decrypt
C = ffx_obj.encrypt(T, X)
Y = ffx_obj.decrypt(T, C)
print(f"Plaintext: {X}")
print(f"Ciphertext: {C}")
print(f"Decrypted: {Y}")
print(f"\nRoundtrip successful: {X == Y}")
if __name__ == "__main__":
main()