-1

I'm looking for a module / script to generate 64bit hex addresses in order

something like

0000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000001 0000000000000000000000000000000000000000000000000000000000000002 0000000000000000000000000000000000000000000000000000000000000003 0000000000000000000000000000000000000000000000000000000000000004 0000000000000000000000000000000000000000000000000000000000000005 0000000000000000000000000000000000000000000000000000000000000006 0000000000000000000000000000000000000000000000000000000000000007 0000000000000000000000000000000000000000000000000000000000000008 0000000000000000000000000000000000000000000000000000000000000009 000000000000000000000000000000000000000000000000000000000000000a 000000000000000000000000000000000000000000000000000000000000000b 000000000000000000000000000000000000000000000000000000000000000c 000000000000000000000000000000000000000000000000000000000000000d 000000000000000000000000000000000000000000000000000000000000000e 000000000000000000000000000000000000000000000000000000000000000f 0000000000000000000000000000000000000000000000000000000000000010 0000000000000000000000000000000000000000000000000000000000000011 0000000000000000000000000000000000000000000000000000000000000012 0000000000000000000000000000000000000000000000000000000000000013 0000000000000000000000000000000000000000000000000000000000000014 0000000000000000000000000000000000000000000000000000000000000015 0000000000000000000000000000000000000000000000000000000000000016 0000000000000000000000000000000000000000000000000000000000000017 0000000000000000000000000000000000000000000000000000000000000018 0000000000000000000000000000000000000000000000000000000000000019 000000000000000000000000000000000000000000000000000000000000001a 000000000000000000000000000000000000000000000000000000000000001b 000000000000000000000000000000000000000000000000000000000000001c 000000000000000000000000000000000000000000000000000000000000001d 000000000000000000000000000000000000000000000000000000000000001e 000000000000000000000000000000000000000000000000000000000000001f

John
  • 1,081
  • 1
  • 9
  • 34
  • Maybe a duplicate of https://stackoverflow.com/questions/1267283/how-can-i-pad-a-value-with-leading-zeros – Jim B. Jan 02 '18 at 20:58
  • @JimBaldwin it's not a matter of padding. It's a matter of generating incremental 64bit HEX addresses – John Jan 02 '18 at 20:59
  • the examples you are typing in is not 64 bit. it is a 64digit hex string. 16^64, i am not sure if long long would even handle that, you need to be looking at some similar to BigInteger class in java or similar – Ji_in_coding Jan 02 '18 at 21:10
  • @Ji_in_coding yeah maybe I'm a bit confused. Not my area of expertise. I want to get 64digit hex strings in order like the sequence above and increment so far that eventually i would get something like this 364957f65727f26434fd9ed59d110c16d26c799ec28f817a250d1a9c6bf8e588 – John Jan 02 '18 at 21:16
  • @John, actually on Chrome, the max supported number is far greater than 16^64. you can get that max value by typing this in your browser console. Number.MAX_VALUE.toString(16). So, the padding + increment method would theoretically work in your use case. – Ji_in_coding Jan 02 '18 at 21:17
  • @John, I have just perform a test. in browser console type in this code. var x = parseInt('364957f65727f26434fd9ed59d110c16d26c799ec28f817a250d1a9c6bf8‌​e588', 16); x.toString(16); You will see a loss of precision. So, your number is way too large. You should search for some big number javascript library. – Ji_in_coding Jan 02 '18 at 21:23
  • Number.MAX_SAFE_INTEGER.toString(16) is 1fffffffffffff – Jim B. Jan 02 '18 at 21:23
  • @Ji_in_coding thanks for your support. I don't think I have the necessary knowledge for this. It seems I don't even know what I'm searching for.. I just know I need 64 digit hex strings. But I don't want the randomly, I want them ordered – John Jan 02 '18 at 21:31
  • @John, then the next question you should ask is, what is the likelihood of your numbers getting that large? if the likelihood is low, or it might take a long time before the number get that large. you can use Jim's answer to get past the current phase and work on the rest of your application. Just make a note that if the number gets too big, loss of precision will happen. Like I mentioned before, you need some kind of big number library. there are plenty out there. Ask google – Ji_in_coding Jan 02 '18 at 21:36
  • @john Have a look at the solution I have provided and mark it as answer if that's what you wanted. – RICKY KUMAR Jan 02 '18 at 22:02
  • @RICKYKUMAR the problem is Number can't represent 64 hex digits. That's why we had to break it down into 8 sections. – Jim B. Jan 02 '18 at 22:03

3 Answers3

2

You use this to generate in the way you want.

var from = 0;
var to = 0x1f;
for(var i = from; i<= to;i++) {
  console.log(i.toString(16).padStart(64, "0"));
}
Olian04
  • 6,480
  • 2
  • 27
  • 54
RICKY KUMAR
  • 643
  • 4
  • 11
0

UPDATE2: code to generate a random 64-digit hex number string:

let x = '';
for (i=0; i<64; i++) {
    x += Math.trunc((Math.random() * 16)).toString(16);
}

UPDATE: this is absurd, but it should work:

let pad = '00000000';
for (let d7=0; d7<0x100; d7++) {
  for (let d6=0; d6<0x100; d6++) {
    for (let d5=0; d6<0x100; d5++) {
      for (let d4=0; d6<0x100; d4++) {
        for (let d3=0; d6<0x100; d3++) {
          for (let d2=0; d6<0x100; d2++) {
            for (let d1=0; d6<0x100; d1++) {
              for (let d0=0; d6<0x100; d0++) {
                console.log(
                  (pad + d7.toString(16)).slice(-8) 
                  + (pad + d6.toString(16)).slice(-8)
                  + (pad + d5.toString(16)).slice(-8)
                  + (pad + d4.toString(16)).slice(-8)
                  + (pad + d3.toString(16)).slice(-8)
                  + (pad + d2.toString(16)).slice(-8)
                  + (pad + d1.toString(16)).slice(-8)
                  + (pad + d0.toString(16)).slice(-8))
              }
            }
          }
        }
      }
    }
  }
}
Jim B.
  • 4,512
  • 3
  • 25
  • 53
  • how do I make it go continuously? from 0 to w/e is on the end? – John Jan 02 '18 at 21:08
  • The limit is set to 0x20 in my example (matching your post). You can make that a variable, or also do this with an infinite while loop, or a bunch of different ways. – Jim B. Jan 02 '18 at 21:10
  • but would i be able to get something like this? 364957f65727f26434fd9ed59d110c16d26c799ec28f817a250d1a9c6bf8e588 – John Jan 02 '18 at 21:12
  • Updated to support 64-bit numbers. But you are showing 256-bit numbers. Do you really mean 256-bit? – Jim B. Jan 02 '18 at 21:21
  • I really have no idea. maybe this is way above my understanding. I just know I need 64 digit hex strings. But I don't want the randomly, I want them ordered – John Jan 02 '18 at 21:30
  • The code above is running, but it will take years to verify. :-P – Jim B. Jan 02 '18 at 21:31
  • yeah I think that worked.. pasted that by mistake in the console and chrome almost caught fire. I'll try to put it in node and maybe do chunks at a time. thanks for help – John Jan 02 '18 at 21:34
  • ok so I tried this over 1000 iterations and I end up with too many 0. no way this code would generate a string like 364957f65727f26434fd9ed59d110c16d26c799ec28f817a250d1a9c6bf8e583 – John Jan 03 '18 at 09:22
  • Are you just looking for random numbers? – Jim B. Jan 03 '18 at 17:14
  • as I said before, no. I'm looking for an ordered sequence – John Jan 05 '18 at 09:53
  • You're never going to get to a large number like that in order on any computer that will exist for the next 20 years. If you can be a little more clear on what you want, we might be able to help. – Jim B. Jan 06 '18 at 18:22
0

Without using a big number library, you could create a class that extends Array with a constructor that takes the hex string representation of a number and provide increment (inc) and string conversion (toString) class methods. E.G.

const MAX_BITS = 256;                      // bits for 64 hex digits
const USHORTS = Math.ceil(MAX_BITS / 16);  // handled 16 bits at a time 

class U256 extends Array {
    constructor( hexString) {
        super();
        for( var i = hexString.length; i > 0; i-=4) {
             var ushortHex = hexString.substring (i, i-4);
             this.push( parseInt(ushortHex, 16));      
        }
        while( this.length < USHORTS) {
             this.push(0);
        }
    }
    inc() {
          for( var i = 0; i < USHORTS; ++i) {
              var ushort = this[i];
              ++ushort;
              if(ushort < 0x10000) {
                 this[i] = ushort;
                 break;
              }
              this[i]=0;
          }
          return this;
    }
    toString() {
        var hex64 = "";
        for( var i = USHORTS; i--;) {
            var hex4 = this[i].toString(16);
            hex64 += hex4.padStart(4, '0');
        }
        return hex64;              
    }
}

var u256 = new U256( "FFFFFFFFFFFFFF");
for( var i = 0; i < 20; ++i) {
    console.log( u256.toString())
    u256.inc();
}
traktor
  • 17,588
  • 4
  • 32
  • 53