Skip to content

Instantly share code, notes, and snippets.

View kepocnhh's full-sized avatar

Stanley Wintergreen kepocnhh

View GitHub Profile
@kepocnhh
kepocnhh / flac2mp3.sh
Created September 24, 2024 12:41
Flac to MP3
#!/usr/local/bin/bash
if test $# -ne 2; then
echo "Script needs for 2 arguments but actual $#!"; exit 12; fi
SRC="$1"
DST="$2"
if [[ ! -d "$SRC" ]]; then echo "SRC: $SRC is not a dir!"; exit 1; fi
if [[ ! -d "$DST" ]]; then echo "DST: $DST is not a dir!"; exit 1; fi
fun toInt(b1: Byte, b2: Byte, b3: Byte, b4: Byte): Int {
return b1.toInt().and(0xff).shl(8 * 3)
.or(b2.toInt().and(0xff).shl(8 * 2))
.or(b3.toInt().and(0xff).shl(8 * 1))
.or(b4.toInt().and(0xff))
}
// 0 1 2 3
// 01234567 01234567 01234567 01234567
PU - Public Key
PK - Private Key
SK - Secret Key
SID - Session ID
P - Payload

@kepocnhh
kepocnhh / dh.sh
Created June 7, 2024 11:30
Diffie–Hellman key exchange cryptographic explanation.
#!/usr/local/bin/bash
# d=256
d=512
g="$(((RANDOM % d) + 1))"
p="$(((RANDOM % d) + 1))"
echo ''
echo 'public:'
echo "g = $g"
@kepocnhh
kepocnhh / sagp.sh
Created October 15, 2023 12:47
OS X security add generic password
#!/usr/local/bin/bash
echo 'Enter service name (default is common):'
read SERVICE_NAME || exit 1
if test -z "$SERVICE_NAME"; then
SERVICE_NAME='common'; fi
echo 'Enter account name:'
read ACCOUNT_NAME || exit 1
@kepocnhh
kepocnhh / osx_security_sample_tk.sh
Last active October 14, 2023 16:40
OS X security sample to keychain.
KEYCHAIN='keychain_baz'
# https://www.unix.com/man-page/osx/1/security/
security delete-keychain "$KEYCHAIN"
security create-keychain -P "$KEYCHAIN"
if test $? -ne 0; then
echo 'Create keychain error!'; exit 1; fi
SERVICE_NAME='service_foo'
@kepocnhh
kepocnhh / osx_security_sample_ww.sh
Created October 14, 2023 16:29
OS X security sample with warning.
SERVICE_NAME='service_foo'
ACCOUNT_NAME='account_bar'
PASSWORD_VALUE='password_bar'
security delete-generic-password -s "$SERVICE_NAME" -a "$ACCOUNT_NAME" &> /dev/null
# Add a generic password item to the default keychain.
security add-generic-password -s "$SERVICE_NAME" -a "$ACCOUNT_NAME" -w "$PASSWORD_VALUE" -T ''
if test $? -ne 0; then
@kepocnhh
kepocnhh / osx_security_sample.sh
Last active October 14, 2023 16:25
OS X security sample.
SERVICE_NAME='service_foo'
ACCOUNT_NAME='account_bar'
PASSWORD_VALUE='password_bar'
security delete-generic-password -s "$SERVICE_NAME" -a "$ACCOUNT_NAME" &> /dev/null
# Add a generic password item to the default keychain without warning.
security add-generic-password -s "$SERVICE_NAME" -a "$ACCOUNT_NAME" -w "$PASSWORD_VALUE"
if test $? -ne 0; then
@kepocnhh
kepocnhh / ExtraType.kt
Created October 11, 2023 18:58
ExtraType dictionary extensions
sealed interface ExtraType<T : Any>
object Str : ExtraType<String>
object Int32 : ExtraType<Int>
object Int64 : ExtraType<Long>
private fun <T : Any> Bundle.getOrNull(type: ExtraType<T>, key: String): T? {
if (!containsKey(key)) return null
return when (type) {
Str -> getString(key, null) as T?
Int64 -> getLong(key, -1) as T
@kepocnhh
kepocnhh / gpg_write.sh
Last active May 1, 2023 14:54
Rewrite encrypted.
#!/usr/local/bin/bash
if test $# -ne 2; then
echo "Script needs 2 arguments: ENCRYPTED, KEY. But actual is $#!"; exit 1; fi
ENCRYPTED="$1"
KEY="$2"
for it in ENCRYPTED KEY; do
if test -z "${!it}"; then echo "Argument \"$it\" is empty!"; exit 1; fi; done