emulbreh / pyffx Goto Github PK
View Code? Open in Web Editor NEWpure Python format preserving encryption
License: MIT License
pure Python format preserving encryption
License: MIT License
Minor issue, pip install pyffx
fails in Windows environment. Cloning from github and running setup.py worked fine.
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\phi\AppData\Local\Temp\pip-install-wohp0tb6\pyffx\setup.py", line 6, in <module>
description = f.read()
File "c:\users\phi\appdata\local\programs\python\python36-32\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 368: character maps to <undefined>
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\phi\AppData\Local\Temp\pip-install-wohp0tb6\pyffx\
Not able to encrypt a string with capital letters or Special characters in the string.
Please find the log when I was trying to encrypt a String "Testtesttest12" with a capital letter.
Traceback (most recent call last):
File "leap_data_encryption.py", line 41, in
df['enc_DEVICE_TYPE']=df['DEVICE_TYPE'].apply(encrypt)
File "/opt/usr/local/lib/python3.6/site-packages/pandas/core/series.py", line 3591, in apply
mapped = lib.map_infer(values, f, convert=convert_dtype)
File "pandas/_libs/lib.pyx", line 2217, in pandas._libs.lib.map_infer
File "leap_data_encryption.py", line 30, in encrypt
print(eS.encrypt('Testtesttest12'))
File "/opt/usr/local/lib/python3.6/site-packages/pyffx/codecs.py", line 15, in encrypt
return self.unpack(self.ffx.encrypt(self.radix, self.pack(v)), type(v))
File "/opt/usr/local/lib/python3.6/site-packages/pyffx/codecs.py", line 42, in pack
raise ValueError('non-alphabet character: %s' % e)
ValueError: non-alphabet character: 'T'
The Integer codec does not preserve length if the pre-unpack encoded string contains leading 0's as those get stripped by the conversion to int.
i = pyffx.Integer(b'secret-key', length=5)
assert 4 == len(str(i.encrypt(1234)))
class IntegerIrreversable(pyffx.Integer):
def unpack(self, v, t):
return int(super(pyffx.Integer, self).unpack(v, t).lstrip('0').ljust(self.length, '9'))
i2 = IntegerIrreversable(b'secret-key', length=5)
for num in range(1000, 9999):
assert 5 == len(str(i2.encrypt(num)))
Line 26 in 1e7f289
In reading the accompanying doc on this: https://medium.com/asecuritysite-when-bob-met-alice/ffx-schemes-for-format-preserving-encryption-a2a7aa4f1377 I noticed that the counter is reset each round. Works fine removing the initialization and allows the value to be carried.
It is ok if my encrypted result has "]" and "n" separately. But that creates problems during rendering in java and python - new lines and other ...
Can I prevent the encrypted results to produce the following sequence of chars?
"\n" and "\r"
Thanks,
Radu
This:
import pyffx
print "Integer:"
e = pyffx.Integer(b'encrypt')
val = 12345678
print val
enc = e.encrypt(val)
print enc
dec = e.decrypt(enc)
print dec
print
results in:
Integer:
12345678
3853168
7841194
So: What's wrong with this? Even longer keys sometimes work and sometimes fail?!
Just installed pyffx
and noticed that pycrypto
was installed as well.
pycrypto
is a defunct project and has been continued by pycryptodome. This project should be updated to use pycryptodome
instead (should be a drop replacement)
/venvs/jkopay/bin/python3.6 setup.py install
Traceback (most recent call last):
File "setup.py", line 6, in
description = f.read()
File "/usr/lib64/python3.6/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 305: ordinal not in range(128)
The README.rst contains non-ascii characters which failed the f.read() .
It seems this cache is outdated, it is not consistent with the code on github repo, which has already fix the issue by adding encoding='utf-8' in file opening.
I'm still not sure exactly how the library works, but if it uses hashlib.sha1
, is there an very small chance of a collision, or a zero chance?
I was testing an implementation of shuffling lists using pyffx, in an attempt to avoid holding the entire shuffled list in memory. One of my implementations is as follows:
def shuffle_generator(sequence):
key = secrets.token_bytes()
cipher = pyffx.Sequence(key, alphabet=sequence, length=1)
for i in sequence:
yield cipher.encrypt([i])[0]
In tests, this quickly proved to be a terrible shuffle. The result was always a rotation of the input - for example, list(shuffle_generator(range(5)))
could produce [2, 3, 4, 0, 1]
or [0, 1, 2, 3, 4]
, but never [0, 4, 2, 3, 1]
.
Am I using pyffx wrong in some way I'm not realizing?
I'm on pyffx 0.3.0 and Python 3.8.3.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.