Giter Club home page Giter Club logo

Comments (11)

Jitsusama avatar Jitsusama commented on July 20, 2024

Hello @zackshapiro,

That method would work for a lot of the logic, but once you get to multiplication it would get harder. I do have the double width operations defined, so you could just depend on this project and wrap around those operations to get what you want; assuming that you don’t want to be able to perform double width 256-bit arithmetic.

from uint128.

zackshapiro avatar zackshapiro commented on July 20, 2024

Thanks for getting back to me so fast! I don't need to do any arithmetic, I just need to represent numbers in UInt128 and public/private key pairs as UInt256

from uint128.

Jitsusama avatar Jitsusama commented on July 20, 2024

Oh, then you could probably just compose a struct from this struct having an upper and lower value like mine.

Are you wanting to store as 256bit numbers and present as a string?

BTW; my double width operations didn’t do what I thought, so it would take a bit of work to make a similar 256bit library.

from uint128.

zackshapiro avatar zackshapiro commented on July 20, 2024

Are you wanting to store as 256bit numbers and present as a string?

Yeah, exactly. In my project I need to have a 256 bit seed, run it through a hashing algorithm to get a key pair and then do another hashing operation with the public key. Eventually I'll need to do a string operation on one of them but that's all I'm using them for

from uint128.

Jitsusama avatar Jitsusama commented on July 20, 2024

You’d probably want to create a new struct, using a higher and lower value of 128 bit UInts and include your hashing algorithm as a method.

Take a look at my string methods when you’re ready to represent the numbers as strings, as I believe my method will work on any sized integer count. You might need to introduce your own bit shifting methods as well, as I don’t recall off the top of my head what my string method relies on.

from uint128.

zackshapiro avatar zackshapiro commented on July 20, 2024

Got it. Thanks @Jitsusama.

I've never worked at the bit level before so I'm a bit intimidated by all this but I'll figure it out.

Working on the struct now

from uint128.

Jitsusama avatar Jitsusama commented on July 20, 2024

_valueToString is the method for my String conversion.

It will require a division method instead of a bit shift, but that probably depends on a bit shift method. I’d have to dig to remember.

It can be a bit hairy. I started writing this library when I wanted to natively store IPv6 addresses. I soon found myself down a rabbit hole 😀

from uint128.

zackshapiro avatar zackshapiro commented on July 20, 2024

@Jitsusama Here's my implementation,

https://gist.github.com/zackshapiro/848a2c1efeda9a34b89b8b5648a7c24c

I took all of the UInt128s and turned them into UInt256s, all the 64s and doubled them, all the 127s and replaced them with 255s

Would you mind taking a look and seeing how that looks since you're much more familiar with the implementation? I'm still digesting :)

I left 2 comments at the bottom of my gist with open questions, if I needed to do anything more in two spots.

The multipliedFullWidth is a doozy of a method, but sounds like I may be able to cut it - in needed - since it doesn't fit my project's needs

from uint128.

Jitsusama avatar Jitsusama commented on July 20, 2024

The multipliedFillWidth method will need significant changes in order to handle 256 bits of math. It’s basically performing long multiplication as you might do on paper, but instead of handling each decimal digit, it’s doing it in chunks of digits. I don’t have my MacBook with me (I’m on a business trip), so I can’t play much, but I would strongly recommend writing out some XCTestCases for scenarios you need to be able to handle and then use breakpoints to start figuring out where things break down. Unfortunately there is a lot of interdependency on arithmetic methods to perform tasks as the only way to do more “advanced” arithmetic is by composing simpler arithmetic, which all has to be handled by your library.

from uint128.

zackshapiro avatar zackshapiro commented on July 20, 2024

Got it working!

Thanks for your help Joel

from uint128.

Jitsusama avatar Jitsusama commented on July 20, 2024

That’s great to hear, and you are most welcome!

from uint128.

Related Issues (17)

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.