我想跑
base58perl.pl
在我的终端中使用以下命令:
perl base58perl.pl
但是我收到以下错误:
Cannot decode! Invalid Base58 Character(s)!
以下是代码:
my $fileSrc = 'base58.txt';
open my $fhSrc, $fileSrc or die "Could not open $fileSrc: $!";
my $fileDest = 'hex.txt';
open( my $fhDest, '>>', $fileDest) or die "Could not open file $fileDest: $!";
while ( my $base58_encoded_address = <$fhSrc >) {
my $binary_address = decodebase58tohex($base58_encoded_address);
say $fhDest $binary_address;
}
close $fhSrc;
close $fhDest;
base58.txt
的内容是base58格式的BTC地址列表。
我也试过
chmod a+x base58perl.pl
perl base58perl.pl
base58.txt内容:
1E5PBfSaFawBy1RjBHkS6FDtCwXkYSsVTo
1DCgptTS2uY2occbVdW1qcVT72T75RXbyg
1CUNEBjYrCn2y1SdiUMohaKUi4wpP326Lb
我仍然得到同样的错误。
答案 0 :(得分:0)
该错误消息来自您已链接的代码中的unbase58
函数。
die "Cannot Decode! Invalid Base58 Character(s)!\n" unless $bitcoin_address =~ /^[1-9A-HJ-NP-Za-km-z]*$/;
该行检查输入是否仅包含字符组[1-9A-HJ-NP-Za-km-z]
的字符。既然你输入了,那就必须不喜欢别的东西了。
我的猜测是它不喜欢行尾的换行符。在将值传递给decodebase58tohex
之前,您需要chomp
关闭它们。
while( my $base58_encoded_address = <$fhSrc>) {
chomp $base58_encoded_address;
my $binary_address = decodebase58tohex($base58_encoded_address);
say $fhDest $binary_address;
}
答案 1 :(得分:0)
您可能需要删除空格。您似乎一次只将字符串的块传递给解码函数,这也可能是一个问题。将整个文件读入var,删除任何空格,然后解码。
my $base58_encoded_address = do { local $/; <$fhSrc> };
$base58_encoded_address =~ s/\s+//g;
my $binary_address = decodebase58tohex($base58_encoded_address);
say $fhDest $binary_address;
答案 2 :(得分:0)
脚本现在正常工作,问题是base58.txt
文件是使用记事本创建的。我使用不同的文本编辑器创建了一个新文件。
答案 3 :(得分:0)
import numpy as np
import matplotlib.pyplot as plt
N = 20
def arr(n):
return np.arange(n) + 1
def linear(features, y):
x = np.vstack(features).T
xT = np.transpose(x)
xTx = xT.dot(x)
return np.linalg.inv(xTx).dot(xT).dot(y)
def plot(x, y, dots_y):
plt.plot(x, y)
plt.plot(x, dots_y, marker='o', linestyle=' ', color='r')
plt.show()
y = arr(N) ** 2 + 3
theta = linear((np.ones(N), arr(N), arr(N) ** 2), y)
plot(arr(N), arr(N) ** theta[1] + theta[0], y)
正如其他人提到的,我认为你在处理空白。 chomp会为你照顾。
接下来要做的是打印你试图用引号解码的字符串,这将确认你只能解码你想要的东西。