It was the Bitcointalk forum that inspired us to create Bitcointalksearch.org - Bitcointalk is an excellent site that should be the default page for anybody dealing in cryptocurrency, since it is a virtual gold-mine of data. However, our experience and user feedback led us create our site; Bitcointalk's search is slow, and difficult to get the results you need, because you need to log in first to find anything useful - furthermore, there are rate limiters for their search functionality.
The aim of our project is to create a faster website that yields more results and faster without having to create an account and eliminate the need to log in - your personal data, therefore, will never be in jeopardy since we are not asking for any of your data and you don't need to provide them to use our site with all of its capabilities.
We created this website with the sole purpose of users being able to search quickly and efficiently in the field of cryptocurrency so they will have access to the latest and most accurate information and thereby assisting the crypto-community at large.
if(preg_match('/^[1-9A-HJ-NP-Za-km-z]+$/', $address) && strlen($address) <= 34 && checkAddress($address))
address is valid
get_bcaddress_version(address)
include("base58.php"); ?>
btc address validator
$address = $_GET["address"];
if(preg_match('/^[1-9A-HJ-NP-Za-km-z]+$/', $address) && strlen($address) <= 34 && checkAddress($address)){
echo "address is valid
";
} else {
echo "address is NOT valid
";
}
?>
/*
*/
//hex input must be in uppercase, with no leading 0x
define("ADDRESSVERSION","00"); //this is a hex byte
function decodeHex($hex){
$hex=strtoupper($hex);
$chars="0123456789ABCDEF";
$return="0";
for($i=0;$i<strlen($hex);$i++){
$current=(string)strpos($chars,$hex[$i]);
$return=(string)bcmul($return,"16",0);
$return=(string)bcadd($return,$current,0);
}
return $return;
}
function encodeHex($dec){
$chars="0123456789ABCDEF";
$return="";
while (bccomp($dec,0)==1){
$dv=(string)bcdiv($dec,"16",0);
$rem=(integer)bcmod($dec,"16");
$dec=$dv;
$return=$return.$chars[$rem];
}
return strrev($return);
}
function decodeBase58($base58){
$origbase58=$base58;
$chars="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
$return="0";
for($i=0;$i<strlen($base58);$i++){
$current=(string)strpos($chars,$base58[$i]);
$return=(string)bcmul($return,"58",0);
$return=(string)bcadd($return,$current,0);
}
$return=encodeHex($return);
//leading zeros
for($i=0;$i<strlen($origbase58)&&$origbase58[$i]=="1";$i++){
$return="00".$return;
}
if(strlen($return)%2!=0){
$return="0".$return;
}
return $return;
}
function encodeBase58($hex){
if(strlen($hex)%2!=0){
die("encodeBase58: uneven number of hex characters");
}
$orighex=$hex;
$chars="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
$hex=decodeHex($hex);
$return="";
while (bccomp($hex,0)==1){
$dv=(string)bcdiv($hex,"58",0);
$rem=(integer)bcmod($hex,"58");
$hex=$dv;
$return=$return.$chars[$rem];
}
$return=strrev($return);
//leading zeros
for($i=0;$i<strlen($orighex)&&substr($orighex,$i,2)=="00";$i+=2){
$return="1".$return;
}
return $return;
}
function hash160ToAddress($hash160,$addressversion=ADDRESSVERSION){
$hash160=$addressversion.$hash160;
$check=pack("H*" , $hash160);
$check=hash("sha256",hash("sha256",$check,true));
$check=substr($check,0,8);
$hash160=strtoupper($hash160.$check);
return encodeBase58($hash160);
}
function addressToHash160($addr){
$addr=decodeBase58($addr);
$addr=substr($addr,2,strlen($addr)-10);
return $addr;
}
function checkAddress($addr,$addressversion=ADDRESSVERSION){
$addr=decodeBase58($addr);
if(strlen($addr)!=50){
return false;
}
$version=substr($addr,0,2);
if(hexdec($version)>hexdec($addressversion)){
return false;
}
$check=substr($addr,0,strlen($addr)-8);
$check=pack("H*" , $check);
$check=strtoupper(hash("sha256",hash("sha256",$check,true)));
$check=substr($check,0,8);
return $check==substr($addr,strlen($addr)-8);
}
function hash160($data){
$data=pack("H*" , $data);
return strtoupper(hash("ripemd160",hash("sha256",$data,true)));
}
function pubKeyToAddress($pubkey){
return hash160ToAddress(hash160($pubkey));
}
function remove0x($string){
if(substr($string,0,2)=="0x"||substr($string,0,2)=="0X"){
$string=substr($string,2);
}
return $string;
}
?>
// use with validator.php?refund=btc-address-here
$validateBTCURL = 'http://blockexplorer.com/q/checkaddress/' . $_GET["refund"];
//echo $validateBTCURL;
$validBTC = file_get_contents($validateBTCURL);
//echo $validBTC;
if($validBTC == "00"){
//do something
} else {
//do something else
}
?>
if(preg_match('/^[1-9A-HJ-NP-Za-km-z]+$/', $address) && strlen($address) <= 34 && checkAddress($address))
address is valid
module Main where
import Data.List
import Data.Maybe
import Data.Word
import Data.Tuple
import Control.Arrow
import Control.Monad
import qualified Crypto.Hash.SHA256 as SHA256
import qualified Data.ByteString as B
fromBase :: Integral a => Integer -> [a] -> Integer
fromBase b = foldl (\a c -> fromIntegral c + a * b) 0
toBase :: Num a => Integer -> Integer -> [a]
toBase b = reverse . unfoldr f where
f 0 = Nothing
f n = Just $ first fromInteger $ swap $ n `divMod` b
b58chars = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
b58encode :: [Word8] -> [Char]
b58encode l = replicate (length $ takeWhile(==0) l) '1' ++
(map (b58chars!!) . toBase 58 . fromBase 256) l
fromb58char c = fst . fromJust . find ((==c) . snd) $ zip [0..] b58chars
b58decode v =
case span (== b58chars !! 0) v of
(ones, v) ->
replicate (length ones) 0 ++
(toBase 256 . fromBase 58 . map fromb58char) v
b58decodeL l v =
let
res = b58decode v
in
guard (length res == l) >> return res
sha256x2 = B.unpack . SHA256.hash . SHA256.hash . B.pack where
checksum = take 4 . sha256x2
mkAddress :: Word8 -> [Word8] -> [Char]
mkAddress v d = b58encode $ v : d ++ checksum (v : d)
validateAddress :: [Char] -> Maybe (Word8, [Word8])
validateAddress addr = do
(version : d) <- b58decodeL 25 addr
case splitAt 20 d of
(d, check) -> do
guard $ checksum (version : d) == check
return (version, d)
Imports System.Security.Cryptography
Imports System.Numerics
Module ValidateBitCoinAddress
Function isValidBitcoinAddress(s As String) As Boolean
Dim regExPattern As String = "[a-zA-Z1-9]{27,35}$"
If MatchString(s, regExPattern) Then
If get_bcaddress_version(s) <> "" Then
isValidBitcoinAddress = True
Else
isValidBitcoinAddress = False
End If
Else
isValidBitcoinAddress = False
End If
End Function
Function MatchString(ByVal str As String, ByVal regexstr As String) As Boolean
str = str.Trim()
Dim pattern As New System.Text.RegularExpressions.Regex(regexstr)
Return pattern.IsMatch(str)
End Function
Function get_bcaddress_version(strAddress) As String
Dim addr As Byte()
Dim version As Byte
Dim checksum(3) As Byte
Dim h3(3) As Byte
Dim x As Integer
addr = b58decode(strAddress, 25)
If IsNothing(addr) Then
'fail
get_bcaddress_version = ""
Exit Function
End If
Dim lenAddr As Integer = addr.GetLength(0)
Dim vh160(lenAddr - 5) As Byte
Dim sha As New SHA256Managed()
version = addr(0)
checksum = {addr(lenAddr - 4), addr(lenAddr - 3), addr(lenAddr - 2), addr(lenAddr - 1)}
For x = 0 To vh160.GetLength(0) - 1
vh160(x) = addr(x)
Next
Dim Hash() As Byte = sha.ComputeHash(vh160)
Dim SecondHash() As Byte = sha.ComputeHash(Hash)
h3 = {SecondHash(0), SecondHash(1), SecondHash(2), SecondHash(3)}
If h3(0) = checksum(0) And h3(1) = checksum(1) And h3(2) = checksum(2) And h3(3) = checksum(3) Then
get_bcaddress_version = version.ToString
Else
'fail
get_bcaddress_version = ""
End If
End Function
Function b58encode(b() As Byte) As String
Dim b58chars As String = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
Dim b58base As BigInteger = 58
Dim x As BigInteger
Dim long_value As BigInteger = 0
Dim result As String = ""
Dim iMod As BigInteger = 0
Dim iDiv As BigInteger = 0
Dim b256base As BigInteger = 256
Dim c As Integer
Dim lv As Integer
lv = b.GetLength(0) - 1
c = 0
For x = lv To 0 Step -1
long_value = long_value + BigInteger.Pow(b256base, x) * b(c)
c = c + 1
Next
Do While long_value >= b58base
iMod = long_value Mod b58base
iDiv = long_value / b58base
result = b58chars(iMod) & result
long_value = iDiv
Loop
result = b58chars(long_value) & result
For x = 0 To lv
If b(x) = CByte(0) Then
result = b58chars(0) & result
Else
Exit For
End If
Next
Return result
End Function
Function insertat(b As Byte, bArr As Byte(), pos As Integer) As Byte()
If IsNothing(bArr) Then
'empty array; return single celled array
Dim tmpsomeOtherBarr(0) As Byte
tmpsomeOtherBarr(0) = b
insertat = tmpsomeOtherBarr
Exit Function
End If
Dim x As Integer
Dim tmpbArr(bArr.GetLength(0)) As Byte
If pos = -1 Then
'insert at end of array
For x = 0 To bArr.GetLength(0) - 1
tmpbArr(x) = bArr(x)
Next
tmpbArr(bArr.GetLength(0)) = b
Return tmpbArr
ElseIf pos = 0 Then
'insert at beginning
tmpbArr(0) = b
For x = 1 To bArr.GetLength(0)
tmpbArr(x) = bArr(x - 1)
Next
Return tmpbArr
Else
'insert in the middle
For x = 0 To pos - 1
tmpbArr(x) = bArr(x)
Next
tmpbArr(pos) = b
For x = pos + 1 To bArr.GetLength(0)
tmpbArr(x) = bArr(x)
Next
Return tmpbArr
End If
End Function
Function b58decode(v As String, l As Integer) As Byte()
Dim b58chars As String = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
Dim b58base As BigInteger = 58
Dim long_value As BigInteger = 0
Dim lv As Integer
Dim c As Integer
Dim x As BigInteger
Dim biPos As BigInteger = 0
Dim iMod As BigInteger = 0
Dim iDiv As BigInteger = 0
Dim result() As Byte
lv = Len(v) - 1
For x = lv To 0 Step -1
c = c + 1
biPos = b58chars.IndexOf(Mid(v, c, 1))
long_value = long_value + BigInteger.Pow(b58base, x) * biPos
Next
Do While long_value >= 256
iMod = long_value Mod 256
iDiv = long_value / 256
result = insertat(CByte(iMod), result, 0)
long_value = iDiv
Loop
result = insertat(CByte(long_value), result, 0)
For x = 1 To Len(v)
If Mid(v, x, 1) = b58chars(0) Then
result = insertat(CByte(0), result, 0)
Else
Exit For
End If
Next
If l > 0 And result.GetLength(0) <> l Then
Return Nothing
Else
Return result
End If
End Function
End Module
base58=({1..9} {A..H} {J..N} {P..Z} {a..k} {m..z})
bitcoinregex="^[$(printf "%s" "${base58[@]}")]{34}$"
decodeBase58() {
local s=$1
for i in {0..57}
do s="${s//${base58[i]}/ $i}"
done
dc <<< "16o0d${s// /+58*}+f"
}
checksum() {
xxd -p -r <<<"$1" |
openssl dgst -sha256 -binary |
openssl dgst -sha256 -binary |
xxd -p -c 80 |
head -c 8
}
checkBitcoinAddress() {
if [[ "$1" =~ $bitcoinregex ]]
then
h=$(decodeBase58 "$1")
checksum "00${h::${#h}-8}" |
grep -qi "^${h: -8}$"
else return 2
fi
}
$btc = decode_btc('1Eym7pyJcaambv8FG4ZoU8A4xsiL9us2zz');
var_dump($btc);
var_dump(encode_btc($btc));
$btc = decode_btc('1111111111111111111114oLvT2');
var_dump($btc);
var_dump(encode_btc($btc));
function hash_sha256($string) {
if (function_exists('hash')) return hash('sha256', $string, true);
if (function_exists('mhash')) return mhash(MHASH_SHA256, $string);
// insert native php implementation of sha256 here
throw new Exception('Too lazy to fallback when the guy who configured php was lazy too');
}
function encode_btc($btc) {
$btc = chr($btc['version']).pack('H*', $btc['hash']);
if (strlen($btc) != 21) return false;
$cksum = substr(hash_sha256(hash_sha256($btc)), 0, 4);
return base58_encode($btc.$cksum);
}
function decode_btc($btc) {
$btc = base58_decode($btc);
if (strlen($btc) != 25) return false; // invalid
$version = ord($btc[0]);
$cksum = substr($btc, -4);
// checksum is double sha256 (take 4 first bytes of result)
$good_cksum = substr(hash_sha256(hash_sha256(substr($btc, 0, -4))), 0, 4);
if ($cksum != $good_cksum) return false;
return array('version' => $version, 'hash' => bin2hex(substr($btc, 1, 20)));
}
function base58_encode($string) {
$table = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
$long_value = gmp_init(bin2hex($string), 16);
$result = '';
while(gmp_cmp($long_value, 58) > 0) {
list($long_value, $mod) = gmp_div_qr($long_value, 58);
$result .= $table[gmp_intval($mod)];
}
$result .= $table[gmp_intval($long_value)];
for($nPad = 0; $string[$nPad] == "\0"; ++$nPad);
return str_repeat($table[0], $nPad).strrev($result);
}
function base58_decode($string) {
$table = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
static $table_rev = null;
if (is_null($table_rev)) {
$table_rev = array();
for($i=0;$i<58;++$i) $table_rev[$table[$i]]=$i;
}
$l = strlen($string);
$long_value = gmp_init('0');
for($i=0;$i<$l;++$i) {
$c=$string[$l-$i-1];
$long_value = gmp_add($long_value, gmp_mul($table_rev[$c], gmp_pow(58, $i)));
}
// php is lacking binary output for gmp
$res = pack('H*', gmp_strval($long_value, 16));
for($nPad = 0; $string[$nPad] == $table[0]; ++$nPad);
return str_repeat("\0", $nPad).$res;
}
(address =~ /^[a-zA-Z1-9]{33,35}$/)
require 'digest'
class BitcoinAddressValidator < ActiveModel::EachValidator
def validate(record, field, value)
unless valid_bitcoin_address?(value)
record.errors[field] << "Bitcoin address is invalid"
end
end
private
B58Chars = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
B58Base = B58Chars.length
def self.valid_bitcoin_address?(address)
(address =~ /^[a-zA-Z1-9]{33,35}$/) and version(address)
end
def self.version(address)
decoded = b58_decode(address, 25)
version = decoded[0, 1]
checksum = decoded[-4, decoded.length]
vh160 = decoded[0, decoded.length - 4]
hashed = (Digest::SHA2.new << (Digest::SHA2.new << vh160).digest).digest
hashed[0, 4] == checksum ? version[0] : nil
end
def self.b58_decode(value, length)
long_value = 0
index = 0
result = ""
value.reverse.each_char do |c|
long_value += B58Chars.index(c) * (B58Base ** index)
index += 1
end
while long_value >= 256 do
div, mod = long_value.divmod 256
result = mod.chr + result
long_value = div
end
result = long_value.chr + result
if result.length < length
result = 0.chr * (length - result.length) + result
end
result
end
end
#
# DJango field type for a Bitcoin Address
#
import re
from django import forms
from django.forms.util import ValidationError
from Crypto.Hash import SHA256
class BCAddressField(forms.CharField):
default_error_messages = {
'invalid': 'Invalid Bitcoin address.',
}
def __init__(self, *args, **kwargs):
super(BCAddressField, self).__init__(*args, **kwargs)
def clean(self, value):
value = value.strip()
if re.match(r"[a-zA-Z1-9]{27,35}$", value) is None:
raise ValidationError(self.error_messages['invalid'])
version = get_bcaddress_version(value)
if version is None:
raise ValidationError(self.error_messages['invalid'])
return value
import math
__b58chars = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
__b58base = len(__b58chars)
def b58encode(v):
""" encode v, which is a string of bytes, to base58.
"""
long_value = 0L
for (i, c) in enumerate(v[::-1]):
long_value += (256**i) * ord(c)
result = ''
while long_value >= __b58base:
div, mod = divmod(long_value, __b58base)
result = __b58chars[mod] + result
long_value = div
result = __b58chars[long_value] + result
# Bitcoin does a little leading-zero-compression:
# leading 0-bytes in the input become leading-1s
nPad = 0
for c in v:
if c == '\0': nPad += 1
else: break
return (__b58chars[0]*nPad) + result
def b58decode(v, length):
""" decode v into a string of len bytes
"""
long_value = 0L
for (i, c) in enumerate(v[::-1]):
long_value += __b58chars.find(c) * (__b58base**i)
result = ''
while long_value >= 256:
div, mod = divmod(long_value, 256)
result = chr(mod) + result
long_value = div
result = chr(long_value) + result
nPad = 0
for c in v:
if c == __b58chars[0]: nPad += 1
else: break
result = chr(0)*nPad + result
if length is not None and len(result) != length:
return None
return result
def get_bcaddress_version(strAddress):
""" Returns None if strAddress is invalid. Otherwise returns integer version of address. """
addr = b58decode(strAddress,25)
if addr is None: return None
version = addr[0]
checksum = addr[-4:]
vh160 = addr[:-4] # Version plus hash160 is what is checksummed
h3=SHA256.new(SHA256.new(vh160).digest()).digest()
if h3[0:4] == checksum:
return ord(version)
return None