From a3e975edbdbb620635acbe70eceb84c7d0e12cbc Mon Sep 17 00:00:00 2001 From: itec78 Date: Sat, 29 Aug 2020 18:44:55 +0200 Subject: [PATCH] banana2dec added --- .gitignore | 7 +++++-- .~lock.Banana.xls# | 1 - banana.py | 30 ++++++++++++++++++++++++++---- banana2dec.py | 5 +++++ dec2banana.py | 5 +++++ 5 files changed, 41 insertions(+), 7 deletions(-) delete mode 100644 .~lock.Banana.xls# mode change 100644 => 100755 banana.py create mode 100755 banana2dec.py create mode 100755 dec2banana.py diff --git a/.gitignore b/.gitignore index 4b1242b..ab8a108 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ -Banana.xls -BananaOrd.txt +__pycache__/ +*.txt +*.xls +.~lock.Banana.xls# + diff --git a/.~lock.Banana.xls# b/.~lock.Banana.xls# deleted file mode 100644 index d48b843..0000000 --- a/.~lock.Banana.xls# +++ /dev/null @@ -1 +0,0 @@ -,itec,otorottoc,03.08.2020 17:44,file:///home/itec/.config/libreoffice/4; \ No newline at end of file diff --git a/banana.py b/banana.py old mode 100644 new mode 100755 index 8987f37..8fc3822 --- a/banana.py +++ b/banana.py @@ -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() \ No newline at end of file + #dec2banana() + #banana2dec() + print("Ciao sono la libreria banana") diff --git a/banana2dec.py b/banana2dec.py new file mode 100755 index 0000000..4459743 --- /dev/null +++ b/banana2dec.py @@ -0,0 +1,5 @@ +#!/usr/bin/env python3 +import banana + +if __name__ == "__main__": + banana.banana2dec() diff --git a/dec2banana.py b/dec2banana.py new file mode 100755 index 0000000..ccfdbb3 --- /dev/null +++ b/dec2banana.py @@ -0,0 +1,5 @@ +#!/usr/bin/env python3 +import banana + +if __name__ == "__main__": + banana.dec2banana()