GithubHelp home page GithubHelp logo

Comments (3)

cyrildever avatar cyrildever commented on September 25, 2024

Hi @anthonylau,
Actually, the library doesn't provide a way to do it directly.

You should do it yourself by using some sort of wrapping function, eg. if you want a 10-digit length number with 0 padding:

const pad10Zero = (numberToPad: number): string => numberToPad.toString().padStart(10, '0')
const encryptedNumber = 987654
// 0000987654
console.log(pad10Zero(encryptedNumber))

Beware that the encrypted padded number is now a string, not a number anymore. It is just meant to be used in text, not for calculus.

Hope it helps.

from feistel-cipher.

anthonylau avatar anthonylau commented on September 25, 2024

Hi @cyrildever,

Thanks for the reply. What I want to know is the max. length of the encryptedNumber() result for a given input. So that I can have a fixed length output which never exceed the predefined size. For example,

encryptNumber(1).toString().padStart(5); // output: 00123
encryptNumber(2).toString().padStart(5); // output: 123456 , exceed length 5 which is unexpected

My use case is, encrypt a number and within a certain range. For example, given input 1234, the output should be within 0-99999.

from feistel-cipher.

cyrildever avatar cyrildever commented on September 25, 2024

Hi @anthonylau,
Unfortunately, there is no way to predetermine that considering the library don't know what's coming into it. But, normally, an incoming 6-figure number should return a 6-figure max number (considering 123456 could return 123, ie. 000123). Tell me if you see it otherwise.
So, it all depends on your knowledge of your incoming data.

from feistel-cipher.

Related Issues (2)

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.