diff --git a/ananas2dec.py b/ananas2dec.py new file mode 100755 index 0000000..1b4ccb8 --- /dev/null +++ b/ananas2dec.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python3 +import argparse +import banana + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Convert ananas string to dec") + parser.add_argument("ananas", help="String to be converted") + args = parser.parse_args() + + print(banana.banana2dec(args.ananas, 1, 0)) diff --git a/banana.py b/banana.py index 8fc3822..102ab64 100755 --- a/banana.py +++ b/banana.py @@ -1,76 +1,36 @@ #!/usr/bin/env python3 -import argparse -def dec2banana(): - 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) - parser.add_argument("--minlength", help="Set minimum length", type=int, default=0) - 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 +def dec2banana(num, dictstart = 0, shiftend = 0, minlength = 0, dictionary = [list("bcdfglmnprstvz"), list("aeiou")]): numdict = len(dictionary) - minlength = args.minlength - - v = args.num + v = num st = "" l = 0 - - - if args.exactlength == 0: - i = (numdict - 1 + args.dictstart + args.shiftend) % numdict - while not (v == 0 and i == (numdict - 1 + args.dictstart) % numdict and l >= args.minlength): - r = v % len(dictionary[i]) - v = int(v / len(dictionary[i])) - st = dictionary[i][r] + st - i = (i - 1) % numdict - l += 1 - else: - i = (numdict - 1 + args.dictstart + args.shiftend + args.exactlength) % numdict - while not (l >= args.exactlength): - r = v % len(dictionary[i]) - v = int(v / len(dictionary[i])) - st = dictionary[i][r] + st - i = (i - 1) % numdict - l += 1 - if v > 0: - print("Error, result longer than exactlength") - return - - print(st) + 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) -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 +def banana2dec(banana, dictstart = 0, shiftend = 0, dictionary = [list("bcdfglmnprstvz"), list("aeiou")] ): numdict = len(dictionary) - banana = args.banana - v = 0 for i in range(len(banana)): - r = (numdict + i + args.dictstart) % numdict + r = (numdict + i + 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) + + return(v) if __name__ == "__main__": - #dec2banana() - #banana2dec() print("Ciao sono la libreria banana") diff --git a/banana2dec.py b/banana2dec.py index 4459743..a6611c5 100755 --- a/banana2dec.py +++ b/banana2dec.py @@ -1,5 +1,13 @@ #!/usr/bin/env python3 +import argparse import banana if __name__ == "__main__": - banana.banana2dec() + parser = argparse.ArgumentParser(description="Convert banana string to dec") + parser.add_argument("banana", help="String 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() + + print(banana.banana2dec(args.banana, args.dictstart, args.shiftend, args.dictionary)) diff --git a/dec2ananas.py b/dec2ananas.py new file mode 100755 index 0000000..275d2fd --- /dev/null +++ b/dec2ananas.py @@ -0,0 +1,11 @@ +#!/usr/bin/env python3 +import argparse +import banana + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Convert dec number to banana") + parser.add_argument("num", help="number to be converted", type=int) + parser.add_argument("--minlength", help="Set minimum length", type=int, default=0) + args = parser.parse_args() + + print(banana.dec2banana(args.num, 1, 0, args.minlength)) diff --git a/dec2banana.py b/dec2banana.py index ccfdbb3..03314eb 100755 --- a/dec2banana.py +++ b/dec2banana.py @@ -1,5 +1,14 @@ #!/usr/bin/env python3 +import argparse import banana if __name__ == "__main__": - banana.dec2banana() + parser = argparse.ArgumentParser(description="Convert dec number to banana") + parser.add_argument("num", help="number to be converted", type=int) + 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) + parser.add_argument("--minlength", help="Set minimum length", type=int, default=0) + parser.add_argument("--dictionary", help="Set dictionary", type=list, nargs='+', default=[list("bcdfglmnprstvz"), list("aeiou")]) # , list("123456") + args = parser.parse_args() + + print(banana.dec2banana(args.num, args.dictstart, args.shiftend, args.minlength, args.dictionary))