Bitcoin Forum
April 23, 2024, 07:33:59 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Bitcoin Morse  (Read 1564 times)
remotemass (OP)
Legendary
*
Offline Offline

Activity: 1116
Merit: 1016


ASMR El Salvador


View Profile WWW
February 13, 2013, 11:40:49 AM
Last edit: February 13, 2013, 12:19:29 PM by remotemass
 #1

Bitcoin addresses allow:
0 .. 9, A ..Z, a .. z, but without the four characters 0, O, I and l

I wanted to encode any bitcoin address using only numbers.
Because zeros are not allowed we will use it to encode letters like this,

preceding with zeros for a letter, like this:
01-A
001-a (double zero, one)
02-B
002-b
03-C
003-c
04-D
004-d
05-E
005-e
06-F
006-f
07-G
007-g
08-H
008-h
009-i
0001-J (triple zero, one)
00001-j (fourfold zero, one)
0002-K
00002-k
0003-L
0004-M
00004-m
0005-N
00005-n
00006-o
0007-P
00007-p
0008-Q
00008-q
0009-R
00009-r
000001-S (fivefold zero, one)
0000001-s (sixfold zero, one)
000002-T
0000002-t
000003-U
0000003-u
000004-V
0000004-v
000005-W
0000005-w
000006-X
0000006-x
000007-Y
0000007-y
000008-Z
0000008-z

So, best scenario you would encode a bitcoin address with 34 digits

and in the worst case scenario with 238 digits.
With this encoding the lengh would be very variable.

Let me try to encode one address with this 'Bitcoin Morse', as I call it.

Bitcoin Address:14jsRJx8HnKq9jyqfBQKgvvnFy3rNCbc3G
In Bitcoin Morse: 1400001000000100090001000000680800005000200008900001000000700008006020008000200 70000004000000400005060000007300009000503002003307

34 alphanumerics into 129 number digits.
Not too bad, is it?! And maybe vanity addresses could optimize your address to have as little lenght as it gets...

Inventor of: "Conic-Upward-Jet-Thrust 𝕊ℙ𝔸ℂ𝔼 𝔼𝕃𝔼𝕍𝔸𝕋𝕆ℝ" ¦¦ Monetize pics of in/out cash (with GPS metatag on and timestamp captions) ¦¦ archive.is/OMUJQ ¦¦ Forking LITECOIN: bitcointalk.org/index.php?topic=5362345 ¦¦ https://twitter.com/CubicPostcode/status/1782131590006477273
1713900839
Hero Member
*
Offline Offline

Posts: 1713900839

View Profile Personal Message (Offline)

Ignore
1713900839
Reply with quote  #2

1713900839
Report to moderator
1713900839
Hero Member
*
Offline Offline

Posts: 1713900839

View Profile Personal Message (Offline)

Ignore
1713900839
Reply with quote  #2

1713900839
Report to moderator
1713900839
Hero Member
*
Offline Offline

Posts: 1713900839

View Profile Personal Message (Offline)

Ignore
1713900839
Reply with quote  #2

1713900839
Report to moderator
The forum was founded in 2009 by Satoshi and Sirius. It replaced a SourceForge forum.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1713900839
Hero Member
*
Offline Offline

Posts: 1713900839

View Profile Personal Message (Offline)

Ignore
1713900839
Reply with quote  #2

1713900839
Report to moderator
jerfelix
Sr. Member
****
Offline Offline

Activity: 266
Merit: 250


View Profile
February 13, 2013, 11:55:44 AM
 #2

A more mathematically sound way to convert a Bitcoin address to a string of digits would be to take the Bitcoin Address, which is a Base-58 number, and simply convert it to decimal.  This would be trivial programmatically.

It wouldn't have the properties that you described, in that it's length would always be much smaller than what you described, and usually be nearly the same length (for all randomly generated Bitcoin Addresses).
ciphermonk
Newbie
*
Offline Offline

Activity: 50
Merit: 0



View Profile
February 13, 2013, 01:59:22 PM
Last edit: February 14, 2013, 07:10:13 AM by ciphermonk
 #3

Edit2: This example is flawed. See my post below for a better example.

Here's an example of base-10 encoding.

bitcoin address: msTuyWdqBoWFDhttLrqagzqi8n5KWaD3Pv
base 16 (hex) encoding: 830e533c2b8a12a1a06b56f08578645b72e324bb
base 10 encoding: 975382009484802281201214682924674052502252791847

Here's the perl script I used to calculate the base10 encoding from raw bitcoin data:

https://gist.github.com/ciphermonk/4944777

I did not do any verification if it's correct, but at least the spirit is there Wink

As far as classical information theory goes, this is the smallest base10 compression you can get.

Cheers!

Edit: This example above is wrong: The raw data I used ( from a raw transaction ) does not contain the bitcoin address version and does not contain the checksum. So the actual base 10 encoding would have a few more digits Wink Sorry about that. If anyone want to have an updated script, let me know I can work on it.
dserrano5
Legendary
*
Offline Offline

Activity: 1974
Merit: 1029



View Profile
February 13, 2013, 02:48:29 PM
 #4

Here's the perl script I used to calculate the base10 encoding from raw bitcoin data:

https://gist.github.com/ciphermonk/4944777

Why @b10 and %b10? $b10[n] == $b10{n} == n so they are useless (they make sense for other radices but not for <= 10). Also, the pack/unpack is redundant, and the result must be reversed:

Code:
use bigint;

sub encode_base10 {
    my $bigint = hex shift;
    my $result = '';
 
    while ($bigint > 0) {
        my ($quo, $rem) = $bigint->bdiv(10);
        $result .= $rem;
    }
 
    scalar reverse $result;
}
 
print encode_base10 '830e533c2b8a12a1a06b56f08578645b72e324bb';

The while loop can be written in one line while maintaining full readability but I'll leave that aside Tongue.
payb.tc
Hero Member
*****
Offline Offline

Activity: 812
Merit: 1000



View Profile
February 13, 2013, 03:08:41 PM
 #5

The while loop can be written in one line while maintaining full readability but I'll leave that aside Tongue.

please tell a complete perl novice (me) how you would write it Cheesy
ciphermonk
Newbie
*
Offline Offline

Activity: 50
Merit: 0



View Profile
February 13, 2013, 03:34:45 PM
 #6

Here's the perl script I used to calculate the base10 encoding from raw bitcoin data:

https://gist.github.com/ciphermonk/4944777

Why @b10 and %b10? $b10[n] == $b10{n} == n so they are useless (they make sense for other radices but not for <= 10). Also, the pack/unpack is redundant, and the result must be reversed:

Code:
use bigint;

sub encode_base10 {
    my $bigint = hex shift;
    my $result = '';
 
    while ($bigint > 0) {
        my ($quo, $rem) = $bigint->bdiv(10);
        $result .= $rem;
    }
 
    scalar reverse $result;
}
 
print encode_base10 '830e533c2b8a12a1a06b56f08578645b72e324bb';

The while loop can be written in one line while maintaining full readability but I'll leave that aside Tongue.

You are right, it's quite irrelevant to write that. The fact of the matter is that $bigint already holds the base10 representation, so there's no point going through the while loop. I simply wanted to demonstrate how you encode arbitrary data into a basex representation.

Thanks for improving the code.
dserrano5
Legendary
*
Offline Offline

Activity: 1974
Merit: 1029



View Profile
February 13, 2013, 05:32:52 PM
 #7

The fact of the matter is that $bigint already holds the base10 representation, so there's no point going through the while loop.

Doh, I completely overlooked that Smiley.

E&G: $result .= ($bigint->bdiv(10))[1] while $bigint;
ciphermonk
Newbie
*
Offline Offline

Activity: 50
Merit: 0



View Profile
February 14, 2013, 07:08:59 AM
Last edit: February 14, 2013, 07:20:23 AM by ciphermonk
 #8

$result .= ($bigint->bdiv(10))[1] while $bigint;

Thats cool. I like it, except that the ()[1] is somewhat obfuscated. Someone reading the code needs to open the bigint documentation to understand the behavior. It's a tradeoff between succinctness and readability. Both views can be defended Smiley

For completeness, I decided to run the OP's example address to base10: 14jsRJx8HnKq9jyqfBQKgvvnFy3rNCbc3G

If you run this through decode_base58, you get the following string ( hex representation ):

002903ef7df972ef94adeda53f0ccd24699de872041e4732cf

The first byte ( 00 ) is a bitcoin address version string. On production blockchain, this is 0x00 and on testnet blockchain, this is 0x6f ( or 111 in decimal representation ). We notice that this is a production address.

The last 4 bytes ( 1e4732cf ) is a checksum over the previous data. If you make a typo while manually entering a bitcoin address, you will create an invalid checksum and the bitcoin client will refuse to send money to it. So, we want to convert this hexadecimal representation into decimal representation. Turns out to be very easy in perl:

Code:
use bigint;
print hex '002903ef7df972ef94adeda53f0ccd24699de872041e4732cf';

The result is:

1005694022349920422888116886380815406116626226984035758799

I believe the result is correct now Wink

Cheers!

 
jerfelix
Sr. Member
****
Offline Offline

Activity: 266
Merit: 250


View Profile
February 14, 2013, 08:07:07 AM
 #9

It seems like about the correct length.

34 Base-58 digits should convert to about 60 decimal digits, since 34*ln(58)/ln(10) = 59.9.
Since the Bitcoin Address starts with leading zeros (a 1 in Base-58, where zero has been eliminated from the digit pool), your 59 digit number seems in the right range.
dserrano5
Legendary
*
Offline Offline

Activity: 1974
Merit: 1029



View Profile
February 14, 2013, 08:37:17 AM
 #10

Thats cool. I like it, except that the ()[1] is somewhat obfuscated. Someone reading the code needs to open the bigint documentation to understand the behavior. It's a tradeoff between succinctness and readability. Both views can be defended Smiley

It's not bigint-related, just standard syntax to access the second element in a list. Another example:

Code:
$ date; perl -le 'print join " ", (localtime)[2,1,0]'
Thu Feb 14 09:36:19 CET 2013
9 36 19

But we're way off topic now.
ciphermonk
Newbie
*
Offline Offline

Activity: 50
Merit: 0



View Profile
February 14, 2013, 11:26:33 AM
 #11

$result .= ($bigint->bdiv(10))[1] while $bigint;
Thats cool. I like it, except that the ()[1] is somewhat obfuscated. Someone reading the code needs to open the bigint documentation to understand the behavior. It's a tradeoff between succinctness and readability. Both views can be defended Smiley

I'm sorry, perhaps I didn't express myself correctly. What I meant is that someone reading the code might not know that the second element in the list is the remainder of the division. Either he knows it or he has to look up the documentation of bigint to see what is the second element returned by the division. I certainly wouldn't know it unless I looked it up.

Writing it like this gives the reader a clue as to what the function returns:

Code:
my ($quo, $rem) = $bigint->bdiv(10);

Again, I don't want to say that this is the correct and only way to do it. Both styles certainly have their merit and can be defended.

I agree however that we are somewhat off topic Wink
remotemass (OP)
Legendary
*
Offline Offline

Activity: 1116
Merit: 1016


ASMR El Salvador


View Profile WWW
March 24, 2023, 06:15:33 AM
 #12

Code:
<!DOCTYPE html>
<html>
<head>
<title>Bitcoin Morse Converter</title>
<script>
function convertToMorse() {
// Get the Bitcoin address from the input field
var bitcoinAddress = document.getElementById("bitcoinAddress").value;
// Remove any whitespace or extra characters from the address
bitcoinAddress = bitcoinAddress.replace(/\s/g, "").toUpperCase();
// Initialize an empty string to hold the Bitcoin Morse encoding
var bitcoinMorse = "";
// Loop through each character in the Bitcoin address
for (var i = 0; i < bitcoinAddress.length; i++) {
// Look up the corresponding Bitcoin Morse encoding for the current character
switch (bitcoinAddress.charAt(i)) {
case "0":
bitcoinMorse += "14";
break;
case "1":
bitcoinMorse += "01";
break;
case "2":
bitcoinMorse += "02";
break;
case "3":
bitcoinMorse += "03";
break;
case "4":
bitcoinMorse += "04";
break;
case "5":
bitcoinMorse += "05";
break;
case "6":
bitcoinMorse += "06";
break;
case "7":
bitcoinMorse += "07";
break;
case "8":
bitcoinMorse += "08";
break;
case "9":
bitcoinMorse += "09";
break;
case "A":
bitcoinMorse += "001";
break;
case "B":
bitcoinMorse += "002";
break;
case "C":
bitcoinMorse += "003";
break;
case "D":
bitcoinMorse += "004";
break;
case "E":
bitcoinMorse += "005";
break;
case "F":
bitcoinMorse += "006";
break;
case "G":
bitcoinMorse += "007";
break;
case "H":
bitcoinMorse += "008";
break;
case "I":
bitcoinMorse += "009";
break;
case "J":
bitcoinMorse += "0001";
break;
case "K":
bitcoinMorse += "0002";
break;
case "L":
bitcoinMorse += "0003";
break;
case "M":
bitcoinMorse += "0004";
break;
case "N":
bitcoinMorse += "0005";
break;
case "O":
bitcoinMorse += "00006";
break;
case "P":
bitcoinMorse += "0007";
break;
case "Q":
bitcoinMorse += "0008";
break;
case "R":
bitcoinMorse += "0009";
break;
case "S":
bitcoinMorse += "000001";
break;
case "T":
bitcoinMorse += "000002";
break;
case "U":
bitcoinMorse += "000003";
break;
case "V":
bitcoinMorse += "000004";
break;
case "W":
bitcoinMorse += "000005";
break;
case "X":
bitcoinMorse += "000006";
break;
case "Y":
bitcoinMorse += "000007";
break;
case "Z":
bitcoinMorse += "000008";
break;
}
}
// Set the value of the output field to the Bitcoin Morse encoding
document.getElementById("bitcoinMorse").value = bitcoinMorse;
}
</script>

</head>
<body>
<h1>Bitcoin Morse Converter</h1>
<p>Enter a Bitcoin address to convert it to the Bitcoin Morse encoding.</p>
<form>
<label for="bitcoinAddress">Bitcoin Address:</label>
<input type="text" id="bitcoinAddress" name="bitcoinAddress" size="40"><br><br>
<button type="button" onclick="convertToMorse()">Convert to Bitcoin Morse</button><br><br>
<label for="bitcoinMorse">Bitcoin Morse:</label>
<input type="text" id="bitcoinMorse" name="bitcoinMorse" size="160" readonly>
</form>
</body>
</html>

https://cubicpostcode.github.io/bitcoinMorse.html

Inventor of: "Conic-Upward-Jet-Thrust 𝕊ℙ𝔸ℂ𝔼 𝔼𝕃𝔼𝕍𝔸𝕋𝕆ℝ" ¦¦ Monetize pics of in/out cash (with GPS metatag on and timestamp captions) ¦¦ archive.is/OMUJQ ¦¦ Forking LITECOIN: bitcointalk.org/index.php?topic=5362345 ¦¦ https://twitter.com/CubicPostcode/status/1782131590006477273
odolvlobo
Legendary
*
Offline Offline

Activity: 4298
Merit: 3200



View Profile
March 24, 2023, 09:07:48 AM
 #13

Your encoding scheme is extremely inefficient. A variable length code is not helpful because all characters have the same frequency.

As others have mentioned, the most efficient scheme would be to convert the 25-byte value to a decimal number. The result is a 61 digit address.

Alternatively, if you want the address encoded directly, you could assign a two-digit number to each symbol.

Join an anti-signature campaign: Click ignore on the members of signature campaigns.
PGP Fingerprint: 6B6BC26599EC24EF7E29A405EAF050539D0B2925 Signing address: 13GAVJo8YaAuenj6keiEykwxWUZ7jMoSLt
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!