A Python library and command-line utility to encrypt short plaintext bytes using an enhanced XOR algorithm.
Generating a new key and testing the encryption:
from ByteSpinner import Spinner
# generate new symmetric key, write to file
sp = Spinner.generate()
f = open('my_secret_key.json', 'w')
f.write(sp.dumps())
f.close()
# encrypt some text
plaintext = bytearray(b'Testing ByteSpinner encryption.')
ciphertext = sp.encrypt(plaintext)
assert plaintext != ciphertext
# decrypt and check
plaintext_check = sp.decrypt(ciphertext)
assert plaintext == plaintext_check
Reading the key and displaying the properties:
from ByteSpinner import Spinner
# read previous key
f = open('my_secret_key.json', 'r')
sp = Spinner.loads(f.read())
f.close()
# print properties
print('XOR base length: %d' % sp.num_bytes)
print('Iterations: %d' % sp.num_iterations)
Generating a new key:
bytespinner gen my_secret_key.json
Show key properties:
bytespinner info my_secret_key.json
Encrypt a plaintext file:
echo "Testing ByteSpinner encryption." > plaintext.txt
bytespinner enc my_secret_key.json plaintext.txt ciphertext.out
Decrypt back to plaintext and check the result:
bytespinner dec my_secret_key.json ciphertext.out plaintext_check.txt
diff plaintext.txt plaintext_check.txt