commit 106512b5ad5a6c905364ae4933b5e59323060fda Author: itec78 Date: Sun Mar 7 23:55:48 2021 +0100 first commit diff --git a/banana.js b/banana.js new file mode 100644 index 0000000..1f01165 --- /dev/null +++ b/banana.js @@ -0,0 +1,54 @@ +console.log(bananaencode(5000)); +console.log(bananaencode(10000)); +console.log(bananaencode(1000, 8)); + +console.log(bananarandom()); +console.log(bananarandom(10)); + + + +function bananaencode(num, minlength = 1) { + alphabets = Array("bcdfglmnprstvz".split(""), "aeiou".split("")); + shiftalpha = 0; + alphaend = 0; + + numalpha = alphabets.length; + v = num; + st = ""; + length = 0; + + idx = (numalpha - 1 + shiftalpha + alphaend) % numalpha; + while (!(v == 0 && idx == (numalpha - 1 + shiftalpha) % numalpha && length >= minlength)) { + al = alphabets[idx]; + r = v % al.length; + v = Math.floor(v / al.length); + st = al[r] + st; + + idx = (idx + numalpha - 1) % numalpha; + length = length + 1; + } + + return st; +} + +function bananarandom(minlength = 6) { + alphabets = Array("bcdfglmnprstvz".split(""), "aeiou".split("")); + shiftalpha = 0; + alphaend = 0; + + numalpha = alphabets.length; + st = ""; + + if (minlength < 1) { + return ""; + } + curr_alpha = (numalpha - 1 + shiftalpha + alphaend) % numalpha; + final_alpha = (numalpha - 1 + shiftalpha) % numalpha; + while (curr_alpha != final_alpha || st.length < minlength) { + al = alphabets[curr_alpha]; + st = al[Math.floor(Math.random() * al.length)] + st; + curr_alpha = (curr_alpha + numalpha - 1) % numalpha; + } + + return st; +} \ No newline at end of file diff --git a/banana.lua b/banana.lua new file mode 100755 index 0000000..28541dc --- /dev/null +++ b/banana.lua @@ -0,0 +1,64 @@ +#!/usr/bin/lua + +function bananaencode(num, minlength) + minlength = minlength or 1 + + alphabets = {{"b","c","d","f","g","l","m","n","p","r","s","t","v","z"}, {"a","e","i","o","u"}}; + shiftalpha = 0 + alphaend = 0 + + numalpha = #alphabets + v = num + st = "" + length = 0 + + idx = (numalpha - 1 + shiftalpha + alphaend) % numalpha + while (not (v == 0 and idx == (numalpha - 1 + shiftalpha) % numalpha and length >= minlength)) + do + al = alphabets[idx + 1] + r = v % #al + v = math.floor(v / #al) + st = al[r + 1] .. st + + idx = (idx + numalpha - 1) % numalpha; + length = length + 1 + end + + return st +end + + +function bananarandom(minlength) + minlength = minlength or 6 + math.randomseed(os.clock()*100000000000) + + alphabets = {{"b","c","d","f","g","l","m","n","p","r","s","t","v","z"}, {"a","e","i","o","u"}}; + shiftalpha = 0 + alphaend = 0 + + numalpha = #alphabets + st = "" + + if minlength < 1 then return "" end + curr_alpha = (numalpha - 1 + shiftalpha + alphaend) % numalpha + final_alpha = (numalpha - 1 + shiftalpha) % numalpha + while (curr_alpha ~= final_alpha or #st < minlength) + do + al = alphabets[curr_alpha + 1]; + st = al[math.floor(math.random() * #al + 1)] .. st + curr_alpha = (curr_alpha + numalpha - 1) % numalpha + end + + return st +end + + + + +print(bananaencode(5000)) +print(bananaencode(10000)) +print(bananaencode(1000, 8)) + +print(bananarandom()) +print(bananarandom(10)) + diff --git a/banana.php b/banana.php new file mode 100755 index 0000000..f6493c1 --- /dev/null +++ b/banana.php @@ -0,0 +1,59 @@ +#!/usr/bin/php += $minlength)) { + $al = $alphabets[$idx]; + $r = $v % count($al); + $v = intval($v / count($al)); + $st = $al[$r] . $st; + + $idx = ($idx + $numalpha - 1) % $numalpha; + $length = $length + 1; + } + + return $st; +} + +function bananarandom($minlength = 6) { + $alphabets = Array(str_split("bcdfglmnprstvz"), str_split("aeiou")); + $shiftalpha = 0; + $alphaend = 0; + + $numalpha = count($alphabets); + $st = ""; + + if ($minlength < 1) { + return ""; + } + $curr_alpha = ($numalpha - 1 + $shiftalpha + $alphaend) % $numalpha; + $final_alpha = ($numalpha - 1 + $shiftalpha) % $numalpha; + while ($curr_alpha != $final_alpha || strlen($st) < $minlength) { + $al = $alphabets[$curr_alpha]; + $st = $al[intval(rand(0, count($al) - 1))] . $st; + $curr_alpha = ($curr_alpha + $numalpha - 1) % $numalpha; + } + + return $st; +} + +?> \ No newline at end of file diff --git a/banana.sh b/banana.sh new file mode 100755 index 0000000..ddcacca --- /dev/null +++ b/banana.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +num=$1 +minlength=1 + + +alphabets=(bcdfglmnprstvz aeiou) +numalpha=${#alphabets[@]} +v=$num +st= +length=0 + +idx=$((($numalpha - 1) % $numalpha)) +while !( [ $v -eq 0 ] && [ $idx -eq $((($numalpha - 1) % $numalpha)) ] && [ $length -ge $minlength ] ) +do + al=${alphabets[idx]} + r=$(($v % ${#al})) + v=$(($v / ${#al})) + st="${al:$r:1}$st" + + idx=$((($idx + $numalpha - 1) % $numalpha)) + length=$(($length + 1)) +done + +echo $st