88 lines
2.6 KiB
Python
Executable file
88 lines
2.6 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
|
|
def dec2banana(num, alphastart = None, shiftend = None, minlength = None, alphabet = None):
|
|
#defaults
|
|
if alphastart is None: alphastart = 0
|
|
if shiftend is None: shiftend = 0
|
|
if minlength is None: minlength = 1
|
|
if alphabet is None: alphabet = [list("bcdfglmnprstvz"), list("aeiou")]
|
|
|
|
numdict = len(alphabet)
|
|
v = num
|
|
st = ""
|
|
l = 0
|
|
|
|
i = (numdict - 1 + alphastart + shiftend) % numdict
|
|
while not (v == 0 and i == (numdict - 1 + alphastart) % numdict and l >= minlength):
|
|
r = v % len(alphabet[i])
|
|
v = int(v / len(alphabet[i]))
|
|
st = alphabet[i][r] + st
|
|
i = (i - 1) % numdict
|
|
l += 1
|
|
|
|
return(st)
|
|
|
|
|
|
def banana2dec(banana, alphastart = None, shiftend = None, alphabet = None):
|
|
#defaults
|
|
if alphastart is None: alphastart = 0
|
|
if shiftend is None: shiftend = 0
|
|
if alphabet is None: alphabet = [list("bcdfglmnprstvz"), list("aeiou")] #, list("123456")
|
|
|
|
numdict = len(alphabet)
|
|
if (len(banana) - shiftend) % numdict != 0:
|
|
return("Banana non valida")
|
|
v = 0
|
|
for i in range(len(banana)):
|
|
r = (numdict + i + alphastart) % numdict
|
|
try:
|
|
v = v * len(alphabet[r]) + alphabet[r].index(banana[i])
|
|
except:
|
|
return("Carattere non valido in posizione", i+1)
|
|
|
|
return(v)
|
|
|
|
def bananarandom(alphastart = None, shiftend = None, minlength = None, alphabet = None):
|
|
import random
|
|
|
|
#defaults
|
|
if alphastart is None: alphastart = 0
|
|
if shiftend is None: shiftend = 0
|
|
if minlength is None: minlength = 6
|
|
if alphabet is None: alphabet = [list("bcdfglmnprstvz"), list("aeiou")]
|
|
|
|
numdict = len(alphabet)
|
|
st = ""
|
|
l = 0
|
|
|
|
i = (numdict - 1 + alphastart + shiftend) % numdict
|
|
while not (i == (numdict - 1 + alphastart) % numdict and l >= minlength):
|
|
r = random.randint(0, len(alphabet[i]) - 1)
|
|
st = alphabet[i][r] + st
|
|
i = (i - 1) % numdict
|
|
l += 1
|
|
|
|
return(st)
|
|
|
|
def isbanana(banana, alphastart = None, shiftend = None, alphabet = None):
|
|
#defaults
|
|
if alphastart is None: alphastart = 0
|
|
if shiftend is None: shiftend = 0
|
|
if alphabet is None: alphabet = [list("bcdfglmnprstvz"), list("aeiou")] #, list("123456")
|
|
|
|
numdict = len(alphabet)
|
|
if (len(banana) - shiftend) % numdict != 0:
|
|
return(False)
|
|
for i in range(len(banana)):
|
|
r = (numdict + i + alphastart) % numdict
|
|
if banana[i] not in alphabet[r]:
|
|
return(False)
|
|
|
|
return(True)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
print("Ciao sono la libreria banana")
|