GithubHelp home page GithubHelp logo

Comments (3)

Milou314 avatar Milou314 commented on June 28, 2024

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.

Milou314 avatar Milou314 commented on June 28, 2024

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.

emulbreh avatar emulbreh commented on June 28, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.