Private key does not satisfy the curve requirements (ie. it is invalid); - ethereum

Can Anyone help me, please? It gives me the error "throw new Error('Private key does not satisfy the curve requirements (i.e., it is invalid)');" it's been 5 days of debugging the code but still no luck; please correct the code and resend it.
const Wallet = require("ethereumjs-wallet");
var possible = "abcdef1234567890";
var basePrivateKey =
"0x09e8568e418bcb88662b7d0094db85b24177ad68ae715dc871d07a5ef4c2a1";
var charsMissing = 66 - basePrivateKey.length;
var targetPublicAddress = " 0x3fFacFff9858168c4E0c34C6f88Eb9e6F8576c6B";
var missingPart = "";
for (var i = 0; i < charsMissing; i++) {
missingPart = missingPart.concat(i);
}
var maxVal = parseInt(missingPart, 16);
console.log(
` \n searching for address : ${targetPublicAddress} \n base private key : ${basePrivateKey} \n missing chars : ${charsMissing} \n it will be quiet now. if you don't see anything below me, it's working on finding your key. \n If you see something below that doesn't say 'FOUND KEY!', you have an error \n `
);
function makeHexString(numb) {
var hex = numb.toString(16);
for (var i = 0; i < charsMissing - hex.length; i++) hex = "0" + hex;
return hex;
}
for (var i = 0; i <= maxVal; i++) {
for (var j = 0; j <= basePrivateKey.length; j++) {
// console.log(" i : " + i + " : j : " + j + "\n");
var endPrivateKey = makeHexString(i);
var privateKeyGuess = [
basePrivateKey.substring(0, j) +
endPrivateKey +
basePrivateKey.substring(j, basePrivateKey.length),
];
var wallet = Wallet.fromPrivateKey(Buffer.from(privateKeyGuess, "hex"));
var publicAddress = util.bufferToHex(wallet.getAddress());
if (publicAddress.toLowerCase() == targetPublicAddress.toLowerCase()) {
console.log(
`Found Private Key: ${privateKeyGuess}\n matching address \n \n \n \n`
);
process.exit();
}
}
if (i % 100000 === 0) {
console.log("checked", i, "keys");
}
}

Length of the basePrivateKey that you shared is 62 hex characters (prepended by 0x) which is 248 bits.
However the expected length is 64 hex characters (prepended by 0x), or 256 bits. In other words, your key is invalid because it's too short.

Related

Get an array of all Numbers inside a String

How can I get an array of all Numbers (if any) inside a String?
So that this:
var txt: String = "So 1 and 22 plus33 = (56) and be4 100 is 99!";
trace(getNumAry(txt));
Output this:
1,22,33,56,4,100,99
Regular Expressions is the answer you are looking for. You need something like that (not tested, yet the idea should be correct):
var source:String = "So 1 and 22 plus33 = (56) and be4 100 is 99!"
// The pattern \d+ instructs to find one or more consequent decimal digits.
// That also means that before each match there will be a non-digit character
// or the beginning of the text, and after the match will also be a non-digit
// or the end of the text.
// The [g]lobal flag is for searching multiple matches.
var re:RegExp = /\d+/g;
// Search for all the matches.
var result:Array = source.match(re);
Without the elaborate commenting the code could be reduced to this simple one-liner:
var result:Array = "So 1 and 22 plus33 = (56) and be4 100 is 99!".match(/\d+/g);
Please keep in mind that this search will return an Array of Strings so if you want them as ints you need to take some additional steps.
This is the working solution I have come up with:
function getNumAry(txt:String):Array {
var res:Array = new Array();
var str: String = ""
//Non-Number Chars to Dot
for (var i:int = 0; i < txt.length; i++) {
if(isNum(txt.substr(i,1))){
str += txt.substr(i, 1);
} else {
str += ".";
}
}
trace(txt);
trace(str);
//Spaces to Dot
str = str.split(" ").join(".")
trace(str);
//Dots to Single Dot
while (str.indexOf("..") != -1) {
str = str.split("..").join(".");
}
trace(str);
//Remove first Dot
if (str.indexOf(".") == 0 ) {
str = str.substr(1);
}
trace(str);
//Remove last Dot
if (str.lastIndexOf(".") == str.length-1 ) {
str = str.substr(0,str.length-1);
}
trace(str);
//get Nums if any
if (str != "" && str != ".") {
res = str.split(".");
}
return res;
}
function isNum(chr: String):Boolean {
return !isNaN(Number(chr));
}
if you run this:
var txt: String = "So 1 and 22 plus33 = (56) and be4 100 is 99!";
trace(getNumAry(txt));
This is the step-by-step trace of what you get:
So 1 and 22 plus33 = (56) and be4 100 is 99!
.. 1 ... 22 ....33 . .56. ... ..4 100 .. 99.
...1.....22.....33....56........4.100....99.
.1.22.33.56.4.100.99.
1.22.33.56.4.100.99.
1.22.33.56.4.100.99
1,22,33,56,4,100,99
Wondering if there has been an easier way?! :)

Read binary file with extendscript

Limited to using Extendscript in Photoshop I'm trying to write and then read in the same binary file.
I can write the file okay, but I'm not sure where I'm going wrong with the read part.
The data will be RGB colours in hex, so I'll either want to return the data from the read function as array or a string. Only I can't even get it to tell me the file just written exists. And I'm not sure if I should be using seek() or read(). Confused.
var f = new File("D:\\temp\\bin.act");
var w = write_binary(f);
var r = read_binary(w);
alert(r);
function write_binary(afile)
{
afile.encoding = "BINARY";
afile.open ("w");
for(i = 0; i < 256; i++)
{
afile.write(String.fromCharCode (i));
}
afile.close();
}
function read_binary(afile)
{
var f = new File(afile);
f.open("r");
f.encoding = "BINARY";
//var data = f.read();
//if(f.exists) alert(afile);
//alert (data);
var arr = [];
for (var i = 0; i < f.length; i+=4)
{
f.seek(i, 0);
var hex = f.readch().charCodeAt(0).toString(16);
if(hex.length === 1) hex = "0" + hex;
arr.push(hex);
}
return arr;
}
You can read it like this:
// Open binary file
var afile = "/Users/mark/StackOverflow/data.bin"
var f = new File(afile);
f.open("r");
f.encoding = "BINARY";
alert('OK');
var hexstring=""
while (true){
var b = f.readch().charCodeAt(0);
if(f.eof){break;}
var hex = b.toString(16);
if(hex.length === 1) hex = "0" + hex;
hexstring += hex;
}
alert(hexstring);
The corresponding writing part of this answer is here.

Hash txt strings in GAS, incorrect line ending

I want hash (md5) some txt strings in GAS, and have a problem, may be
incorrect line ending.
Example:
test
test
correct hash 76ce9f441de2ed5de337d391ad4516b7
using GAS i getting wrong hash: e8230113fbba92427c1c41cf34a80c13
function test() {
var data = 'test\
test';
Logger.log(data.MD5());
return (data.MD5());
}
String.prototype.MD5 = function(charset, toByte) {
charset = charset || Utilities.Charset.UTF_8;
var digest = Utilities.computeDigest(Utilities.DigestAlgorithm.MD5, this, charset);
if (toByte) return digest;
var __ = '';
for (i = 0; i < digest.length; i++) {
var byte = digest[i];
if (byte < 0) byte += 256;
var bStr = byte.toString(16);
if (bStr.length == 1) bStr = '0' + bStr;
__ += bStr;
}
return __;
}
As already #Ameen mentioned you are checking different strings
function test(){
var s1 = 'test\ntest';
var s2 = 'test\r\ntest';
Logger.log(s1.MD5() === '76ce9f441de2ed5de337d391ad4516b7');
Logger.log(s2.MD5() === '76ce9f441de2ed5de337d391ad4516b7');
}
[19-03-22 18:03:11:441 MSK] false
[19-03-22 18:03:11:442 MSK] true
A string containing "\r\n" for non-Unix platforms, or a string containing "\n" for Unix platforms.
It seems you're working under Windows.

Execute Code as Fast as Possible

I am using node.js with my WebStorm IDE to parse a large JSON file (~500 megabytes). Here is my code:
fs = require("fs");
fs.readFile('C:/Users/.../Documents/AAPL.json', 'utf8', function (err,data) {
for (i = 0; i < 1000; i++) {
var hex = JSON.parse(data)[i]._source.layers.data["data.data"];
var askPrice = parseInt(hex.substring(215, 239).split(":").reverse().join(""),16);
var bidPrice = parseInt(hex.substring(192, 215).split(":").reverse().join(""),16);
var symbol = hex.substring(156, 179);
var timestamp = hex.substring(132, 155);
var askSize = hex.substring(240, 251);
var bidSize = hex.substring(180, 191);
var price = String((+bidPrice+askPrice)/2);
var realprice = price.slice(0, price.length - 4) + "." + price.slice(price.length - 4);
function hex2a(hexx) {
var hex = hexx.toString();
var str = '';
for (var i = 0; i < hex.length; i += 2)
str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
return str;
}
if(JSON.parse(data)[i]._source.layers.data["data.len"] == 84 && realprice.length == 8 && +realprice <154 && +realprice >145) {
console.log(i + " " + hex2a(symbol.replace(/:/g, "")) + " sold for " + realprice + " at " + parseInt(timestamp.split(":").reverse().join(""), 16));
}
}
});
The problem I am running into however is that my IDE is parsing this file at an extremely slow speed, roughly 1 iteration a second. I do not think this is because I have a slow computer, for I have a high end rig with a core i7 7700k and a gtx 1070. I tried executing the code in the console with the same result. I tried trimming down the code and again I achieved the same speed:
fs = require("fs");
fs.readFile('C:/Users/Brandt Winkler Prins/Documents/AAPL.json', 'utf8', function (err,data) {
for (i = 0; i < 12000; i++) {
var hex = JSON.parse(data)[i]._source.layers.data["data.data"];
var askPrice = parseInt(hex.substring(215, 239).split(":").reverse().join(""),16);
var bidPrice = parseInt(hex.substring(192, 215).split(":").reverse().join(""),16);
var price = String((+bidPrice+askPrice)/2);
var realprice = price.slice(0, price.length - 4) + "." + price.slice(price.length - 4);
if(+realprice <154 && +realprice >145) {
console.log(realprice);
}
}
});
How should I execute my code to get my data as fast as possible?
You're running JSON.parse(data) every iteration, that might take quite some time for a 500MB json file.
The solution would be to move it out of the loop and reuse the parsed object:
var obj = JSON.parse(data);
for (...

ActionScript - Formatting Zero With NumberFormatter?

i've assigned properties to a NumberFormatter object so that formatted values contain a leading zero, trailing zeros and a 2 decimal places.
the formatting works unless the number being formatted is 0. how can i format a 0 with the set properties so that 0 becomes 0.00?
var numFormat:NumberFormatter = new NumberFormatter(LocaleID.DEFAULT);
numFormat.leadingZero = true;
numFormat.trailingZeros = true;
numFormat.fractionalDigits = 2;
trace(numFormat.formatNumber(46)); //46.00
trace(numFormat.formatNumber(0.556849)); //0.56
trace(numFormat.formatNumber(0)); //0
[EDIT]
i've remedied this problem by manually appending the locale decimal separator with the desired number of fractionalDigits if the formatted number is 0:
if (myFormattedNumber.text == "0" && numFormat.fractionalDigits)
{
myFormattedNumber.appendText(numFormat.decimalSeparator);
for (var i:uint = 0; i < numFormat.fractionalDigits; i++)
myFormattedNumber.appendText("0");
}
i'm still very interested in knowing if this is a bug or a feature, but it seems like a oversight to me.
It's not sexy, but this was similar to what I used when I ran into a similar issue:
function numberFormat(number:*, maxDecimals:int = 2, forceDecimals:Boolean = false, siStyle:Boolean = true):String
{
var i:int = 0, inc:Number = Math.pow(10, maxDecimals), str:String = String(Math.round(inc * Number(number))/inc);
var hasSep:Boolean = str.indexOf(".") == -1, sep:int = hasSep ? str.length : str.indexOf(".");
var ret:String = (hasSep && !forceDecimals ? "" : (siStyle ? "," : ".")) + str.substr(sep+1);
if (forceDecimals) for (var j:int = 0; j <= maxDecimals - (str.length - (hasSep ? sep-1 : sep)); j++) ret += "0";
while (i + 3 < (str.substr(0, 1) == "-" ? sep-1 : sep)) ret = (siStyle ? "." : ",") + str.substr(sep - (i += 3), 3) + ret;
return str.substr(0, sep - i) + ret;
}
trace("zero: " + numberFormat(0, 2, true, false))
Full article here
How about Number(value).toFixed(2) ?