banana2dec added

This commit is contained in:
itec78 2020-08-29 18:44:55 +02:00
parent 9b5bddd2c2
commit a3e975edbd
5 changed files with 41 additions and 7 deletions

7
.gitignore vendored
View file

@ -1,2 +1,5 @@
Banana.xls
BananaOrd.txt
__pycache__/
*.txt
*.xls
.~lock.Banana.xls#

View file

@ -1 +0,0 @@
,itec,otorottoc,03.08.2020 17:44,file:///home/itec/.config/libreoffice/4;

30
banana.py Normal file → Executable file
View file

@ -1,7 +1,8 @@
#!/usr/bin/env python3
import argparse
def dec2banana():
parser = argparse.ArgumentParser(description="Create banana words")
parser = argparse.ArgumentParser(description="Convert dec number to banana")
parser.add_argument("num", help="number to be converted", type=int)
parser.add_argument("--dictionary", help="Set dictionary", type=list, nargs='+', default=[list("bcdfglmnprstvz"), list("aeiou")]) # , list("123456")
parser.add_argument("--exactlength", help="Set exact length", type=int, default=0)
@ -43,12 +44,33 @@ def dec2banana():
print(st)
def banana2dec():
parser = argparse.ArgumentParser(description="Convert banana string to dec")
parser.add_argument("banana", help="strin to be converted")
parser.add_argument("--dictionary", help="Set dictionary", type=list, nargs='+', default=[list("bcdfglmnprstvz"), list("aeiou")]) # , list("123456")
parser.add_argument("--dictstart", help="Set starting dictionary", type=int, default=0)
parser.add_argument("--shiftend", help="Set shift for ending dictionary", type=int, default=0)
args = parser.parse_args()
dictionary = args.dictionary
numdict = len(dictionary)
banana = args.banana
v = 0
for i in range(len(banana)):
r = (numdict + i + args.dictstart) % numdict
try:
v = v * len(dictionary[r]) + dictionary[r].index(banana[i])
except:
print("Carattere non valido in posizione", i+1)
return()
print(v)
if __name__ == "__main__":
dec2banana()
#dec2banana()
#banana2dec()
print("Ciao sono la libreria banana")

5
banana2dec.py Executable file
View file

@ -0,0 +1,5 @@
#!/usr/bin/env python3
import banana
if __name__ == "__main__":
banana.banana2dec()

5
dec2banana.py Executable file
View file

@ -0,0 +1,5 @@
#!/usr/bin/env python3
import banana
if __name__ == "__main__":
banana.dec2banana()