first commit

This commit is contained in:
itec78 2021-03-07 23:55:48 +01:00
commit 106512b5ad
4 changed files with 202 additions and 0 deletions

54
banana.js Normal file
View file

@ -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;
}

64
banana.lua Executable file
View file

@ -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))

59
banana.php Executable file
View file

@ -0,0 +1,59 @@
#!/usr/bin/php
<?php
echo bananaencode(5000) . "\n";
echo bananaencode(10000) . "\n";
echo bananaencode(1000, 8) . "\n";
echo bananarandom() . "\n";
echo bananarandom(10) . "\n";
function bananaencode($num, $minlength = 1) {
$alphabets = Array(str_split("bcdfglmnprstvz"), str_split("aeiou"));
$shiftalpha = 0;
$alphaend = 0;
$numalpha = count($alphabets);
$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 % 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;
}
?>

25
banana.sh Executable file
View file

@ -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