Comments (3)
Ok, meanwhile I added some print commands to the souce code. The problem with integer encryptions is, that there is a leading zero
"03853168"
since in the library the integer is converted to string and than encrypted with alphabet "01234656789".
Unfortunately there is no workaround for this because only the integer is given back but no additional information. The user has to check, whether the encryption has the same length as the original or not, keep this in mind and add the leading zero before decrytion (how???). Another workaround would be to remove the "0" from the alphabet. Finally all integer could be converted to string before encryption. Another solution could be to tell pyffx the maximum length of an integer, i.e.
e = pyffx.Integer(b'encrypt',digits=10)
Internally too short values could be enhanced by leading zeros.
from pyffx.
So I finally changed the file "codecs.py" like this:
class Integer(String):
def __init__(self, ffx, **kwargs):
try:
digits = kwargs['digits']
self.digits = digits
del kwargs['digits']
except:
print
print "pyffx.Integer usage: pyffx.Integer(key,digits=val)"
raise
super(Integer, self).__init__(ffx, string.digits, **kwargs)
def pack(self, v):
vString = str(v)
zeros = self.digits-len(vString)
if zeros<0:
print
print "pyffx.Integer: value '%s' longer than %i digits ..." % (vString,self.digits)
raise
vString = zeros*'0'+vString
return super(Integer, self).pack(vString)
def unpack(self, v, t):
return int(super(Integer, self).unpack(v, t))
Now it's working:
import pyffx
print "Integer:"
e = pyffx.Integer(b'encrypt',digits=10)
val = 12345678
print val
enc = e.encrypt(val)
print enc
dec = e.decrypt(enc)
print dec
print
results in
Integer:
12345678
8706078674
12345678
from pyffx.
Thanks for the report! I simply made length
required for all codecs since it's unclear how padding should even work for non-integers. Please reopen if this change doesn't solve your issue.
from pyffx.
Related Issues (10)
- Apparent issues with cipher quality HOT 1
- counter i is reset to 0 for each round HOT 2
- Integer codec does not preserve length HOT 1
- pycrypto dependency should be updated to pycryptodome HOT 1
- Installation Error on Centos 7(Python 3.6)
- pip install encoding issue in setup.py on Windows HOT 5
- ValueError for capital letters and special characters HOT 1
- how can I exlude the combination of \n and \r characters in the encrypted result? HOT 2
- Are there guaranteed to be no collisions when using hashlib.sha1? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyffx.