Skip to content

Instantly share code, notes, and snippets.

View GregTonoski's full-sized avatar

Greg Tonoski GregTonoski

View GitHub Profile
@GregTonoski
GregTonoski / install_Bitcoin_Knots_27_on_Debian.sh
Created September 16, 2024 07:14
Install Bitcoin Knots 27.1 on Debian Linux
#!/bin/sh
# root privileges may be needed to install software packages on a system. In such case prepand the script with the command sudo
# If the dependedencies are not pre-installed on a system, run initially: sudo apt-get install libevent-pthreads-2.1-7 libminiupnpc17 libnatpmp1
wget -q "https://launchpad.net/~luke-jr/+archive/ubuntu/bitcoinknots/+files/bitcoind_27.1.knots20240801-jammy1_amd64.deb" "https://launchpad.net/~bitcoin/+archive/ubuntu/bitcoin/+files/libdb4.8++_4.8.30-trusty1_amd64.deb" && dpkg -i libdb4.8++_4.8.30-trusty1_amd64.deb && dpkg -i bitcoind_27.1.knots20240801-jammy1_amd64.deb
@GregTonoski
GregTonoski / sha256.sh
Last active October 7, 2023 10:59
Calculate sha256 checksum for hex string input by user
#!/bin/bash
# sha256.sh: calculate sha256 checksum for hex string input by user. Hex string must be shorter than 110 nibbles (or 440 bits).
# Example:
# $ BIP39-XOR.sh 000ffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364139
fn_right_rotate_32(){
FN_RIGHT_ROTATE_32_RESULT=0
@GregTonoski
GregTonoski / bip39_eng_words_to_hex.sh
Created September 7, 2023 12:00
Convert BIP39 English words to hexadicimal number (HEX)
#!/bin/bash
# bip39_eng_words_to_hex.sh: convert BIP39 English words to hexadicimal number (HEX).
# Examples:
# $ bash bip39_eng_words_to_hex.sh "milk sad wage cup reward umbrella raven visa give list decorate bulb gold raise twenty fly manual stand float super gentle climb fold park"
hex_abandon=0x000
hex_ability=0x001
hex_able=0x002
hex_about=0x003
@GregTonoski
GregTonoski / hex_to_bip39.bash
Last active July 7, 2023 15:41
Convert hexadecimal numeral to a sentence of Bitcoin Improvement Proposal 0039 (BIP39)
#!/bin/bash
# hex_to_bip39.bash: convert a hexadecimal numeral to a sentence of Bitcoin Improvement Proposal 0039 (BIP39)
# Example:
# $ hex_to_bip39.bash FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364140
# $ hex_to_bip39.bash FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364140 38
declare hex_string="${1}${2}"
declare -i bits=0
declare -i tempvar=0
@GregTonoski
GregTonoski / hex_string_to_bytes.bash
Created July 6, 2023 15:32
Convert a hexadecimal string to bytes.
#!/bin/bash
# hex_string_to_bytes.bash: convert a hexadecimal string to bytes.
# Examples:
# $ bash hex_string_to_bytes FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364140
# $ bash hex_string_to_bytes FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364140 > output_file.bin
export LC_ALL=C
hex_string="$1"
@GregTonoski
GregTonoski / file_as_hex.bash
Created July 6, 2023 08:16
Display file content as hexadecimal string
#!/bin/bash
# file_as_hex.bash: display file content as hexadecimal string.
# Examples:
# $ bash file_as_hex.bash input_file.bin
export LC_ALL=C
exec 7< $1
while IFS= read -n 1 -d '' -r -u 7; do
@GregTonoski
GregTonoski / hex_to_base36.bash
Created May 25, 2023 07:59
Convert a number from base16 (hex) to base36 numeral.
#!/bin/bash
# hex_to_base36.bash: convert a number from base16 (hex) to base36 numeral.
# Examples:
# $ bash hex_to_base36.bash FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364140
declare STRING_HEX_INPUT="$1"
declare -i -r DIVISOR=36
declare -i -r FROM_BASE=256
declare dividend=${STRING_HEX_INPUT}
@GregTonoski
GregTonoski / base36_to_hex.bash
Created May 25, 2023 07:57
Convert a number from base36 to base16 (hexadecimal) numeral.
#!/bin/bash
# base36_to_hex.bash: convert a number from base36 to base16 (hexadecimal) numeral.
# Examples:
# $ bash base36_to_hex.bash ZYXWVTSRQPONMLKJIHGFEDCBA9876543210
declare STRING_BASE36_INPUT="$1"
declare -i -r FROM_BASE=36
declare -i -r DIVISOR=16
declare dividend=${STRING_BASE36_INPUT}
@GregTonoski
GregTonoski / Bitcoin_WIF_into_hex.bash
Last active June 5, 2023 14:06
Convert from Bitcoin Wallet Import Format (WIF) to hexadicimal number (HEX)
#!/bin/bash
# Bitcoin_WIF_into_hex.bash: convert from Bitcoin Wallet Import Format (WIF) to hexadicimal number (HEX)
# Examples:
# $ bash Bitcoin_WIF_into_hex.bash "L3wB8ytuxNS3SPX2CJnHqK48Zzqj1AnayDTrJomvNPDxuKvHyvpT" > private_key_bitcoin.hex
# $ bash Bitcoin_WIF_into_hex.bash "xprv9s21ZrQH143K31xYSDQpPDxsXRTUcvj2iNHm5NUtrGiGG5e2DtALGdso3pGz6ssrdK4PFmM8NSpSBHNqPqm55Qn3LqFtT2emdEXVYsCzC2U"
# $ zsh Bitcoin_WIF_into_hex.bash $(< private_key_bitcoin.wif )
declare INPUT_STRING_WIF="$1"
declare -i -r FROM_BASE=58
@GregTonoski
GregTonoski / bxor.bash
Last active October 9, 2023 13:07
bxor.bash: bitwise exclusive OR (XOR) of two numbers represented in hexadecimal numerals
#!/bin/bash
# bxor.bash: bitwise exclusive OR (XOR) of two numbers represented in hexadecimal numerals. Result is padded with leading zeros if the number is smaller than 2**256.
# The script could be used to encrypt or decrypt (Vernam cipher).
# Examples:
# $ bash bxor.bash "000ffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364139" "fedc09"
# $ for i in {1..8}; do printf "%08X" "$SRANDOM" >> b256random.key; done && bash ./bxor.bash 012345b $( < b256random.key )
# $ head -c 32 /dev/random >> b256random.key && bash ./bxor.bash $( head -c 32 plaindata.bin | basenc --base16 -w 0 ) $( basenc --base16 -w 0 < b256random.key )
# $ zsh bxor.bash "ffff" "011"
# $ sh bxor.bash "ffff" "011"