Created
May 24, 2016 19:21
-
-
Save eliezio/79ed56cb07d8e25ed99a6851fc70ae90 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function hex2bin() { | |
local data=$1 | |
echo -n $data | xxd -r -ps | |
} | |
function bin2hex() { | |
xxd -ps -c1024 | |
} | |
function to_ascii() { | |
local data=$1 | |
echo -n $data | xxd -ps -c1024 | |
} | |
function sha1() { | |
local magic=$1 | |
local len=$2 | |
echo -n $magic | sha1sum | cut -c1-$((2 * $len)) | |
} | |
function sha2() { | |
local magic=$1 | |
local len=$2 | |
echo -n $magic | sha256sum | cut -c1-$((2 * $len)) | |
} | |
function des2_encrypt() { | |
local key=$1 | |
local data=$2 | |
hex2bin $data | openssl enc -e -des-ede -K $key -nopad | bin2hex | |
} | |
function bogus_rnd() { | |
local seed=$1 | |
local len=$2 | |
local result="" | |
local num=$seed | |
for ((i = 0; i < $len; i++)); do | |
num=$((($num * 125) % 2796203)) | |
num_hex=$(printf "%02x" $num) | |
result="$result${num_hex: -2}" | |
done | |
echo -n $result | |
} | |
# References: | |
# OpenSSL enc: | |
# https://www.openssl.org/docs/manmaster/apps/enc.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment