banana/banana.py

48 lines
1.3 KiB
Python
Raw Normal View History

2020-08-29 18:44:55 +02:00
#!/usr/bin/env python3
2020-08-04 09:59:27 +02:00
2020-08-31 18:21:24 +02:00
def dec2banana(num, dictstart = None, shiftend = None, minlength = None, dictionary = None):
#defaults
if dictstart is None: dictstart = 0
if shiftend is None: shiftend = 0
if minlength is None: minlength = 0
if dictionary is None: dictionary = [list("bcdfglmnprstvz"), list("aeiou")]
2020-08-04 09:59:27 +02:00
numdict = len(dictionary)
2020-08-30 14:59:07 +02:00
v = num
2020-08-04 09:59:27 +02:00
st = ""
2020-08-04 13:13:20 +02:00
l = 0
2020-08-04 09:59:27 +02:00
2020-08-30 14:59:07 +02:00
i = (numdict - 1 + dictstart + shiftend) % numdict
while not (v == 0 and i == (numdict - 1 + dictstart) % numdict and l >= minlength):
r = v % len(dictionary[i])
v = int(v / len(dictionary[i]))
st = dictionary[i][r] + st
i = (i - 1) % numdict
l += 1
return(st)
2020-08-04 09:59:27 +02:00
2020-08-29 18:44:55 +02:00
2020-08-31 18:21:24 +02:00
def banana2dec(banana, dictstart = None, shiftend = None, dictionary = None):
#defaults
if dictstart is None: dictstart = 0
if shiftend is None: shiftend = 0
if dictionary is None: dictionary = [list("bcdfglmnprstvz"), list("aeiou")] #, list("123456")
2020-08-29 18:44:55 +02:00
numdict = len(dictionary)
v = 0
for i in range(len(banana)):
2020-08-30 14:59:07 +02:00
r = (numdict + i + dictstart) % numdict
2020-08-29 18:44:55 +02:00
try:
v = v * len(dictionary[r]) + dictionary[r].index(banana[i])
except:
print("Carattere non valido in posizione", i+1)
return()
2020-08-30 14:59:07 +02:00
return(v)
2020-08-04 09:59:27 +02:00
if __name__ == "__main__":
2020-08-29 18:44:55 +02:00
print("Ciao sono la libreria banana")