diff --git a/banana.py b/banana.py index 9d85a0d..cfb5f16 100755 --- a/banana.py +++ b/banana.py @@ -1,81 +1,81 @@ #!/usr/bin/env python3 -def dec2banana(num, dictstart = None, shiftend = None, minlength = None, dictionary = None): +def dec2banana(num, alphastart = None, shiftend = None, minlength = None, alphabet = None): #defaults - if dictstart is None: dictstart = 0 + if alphastart is None: alphastart = 0 if shiftend is None: shiftend = 0 if minlength is None: minlength = 0 - if dictionary is None: dictionary = [list("bcdfglmnprstvz"), list("aeiou")] + if alphabet is None: alphabet = [list("bcdfglmnprstvz"), list("aeiou")] - numdict = len(dictionary) + numdict = len(alphabet) v = num st = "" l = 0 - 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 = (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, dictstart = None, shiftend = None, dictionary = None): +def banana2dec(banana, alphastart = None, shiftend = None, alphabet = None): #defaults - if dictstart is None: dictstart = 0 + if alphastart is None: alphastart = 0 if shiftend is None: shiftend = 0 - if dictionary is None: dictionary = [list("bcdfglmnprstvz"), list("aeiou")] #, list("123456") + if alphabet is None: alphabet = [list("bcdfglmnprstvz"), list("aeiou")] #, list("123456") - numdict = len(dictionary) + numdict = len(alphabet) if (len(banana) - shiftend) % numdict != 0: return("Banana non valida") v = 0 for i in range(len(banana)): - r = (numdict + i + dictstart) % numdict + r = (numdict + i + alphastart) % numdict try: - v = v * len(dictionary[r]) + dictionary[r].index(banana[i]) + v = v * len(alphabet[r]) + alphabet[r].index(banana[i]) except: return("Carattere non valido in posizione", i+1) return(v) -def bananarandom(dictstart = None, shiftend = None, minlength = None, dictionary = None): +def bananarandom(alphastart = None, shiftend = None, minlength = None, alphabet = None): import random #defaults - if dictstart is None: dictstart = 0 + if alphastart is None: alphastart = 0 if shiftend is None: shiftend = 0 if minlength is None: minlength = 6 - if dictionary is None: dictionary = [list("bcdfglmnprstvz"), list("aeiou")] + if alphabet is None: alphabet = [list("bcdfglmnprstvz"), list("aeiou")] - numdict = len(dictionary) + numdict = len(alphabet) st = "" l = 0 - i = (numdict - 1 + dictstart + shiftend) % numdict - while not (i == (numdict - 1 + dictstart) % numdict and l >= minlength): - r = random.randint(0, len(dictionary[i]) - 1) - st = dictionary[i][r] + st + 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, dictstart = None, shiftend = None, dictionary = None): +def isbanana(banana, alphastart = None, shiftend = None, alphabet = None): #defaults - if dictstart is None: dictstart = 0 + if alphastart is None: alphastart = 0 if shiftend is None: shiftend = 0 - if dictionary is None: dictionary = [list("bcdfglmnprstvz"), list("aeiou")] #, list("123456") + if alphabet is None: alphabet = [list("bcdfglmnprstvz"), list("aeiou")] #, list("123456") - numdict = len(dictionary) + numdict = len(alphabet) if (len(banana) - shiftend) % numdict != 0: return(False) for i in range(len(banana)): - r = (numdict + i + dictstart) % numdict - if banana[i] not in dictionary[r]: + r = (numdict + i + alphastart) % numdict + if banana[i] not in alphabet[r]: return(False) return(True) diff --git a/banana2dec.py b/banana2dec.py index 840c887..8159647 100755 --- a/banana2dec.py +++ b/banana2dec.py @@ -5,9 +5,14 @@ import banana if __name__ == "__main__": 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='+') - parser.add_argument("--dictstart", help="Set starting dictionary", type=int) - parser.add_argument("--shiftend", help="Set shift for ending dictionary", type=int) + parser.add_argument("--alphabet", help="Set alphabet") + parser.add_argument("--alphastart", help="Set starting alphabet", type=int) + parser.add_argument("--shiftend", help="Set shift for ending alphabet", type=int) args = parser.parse_args() - print(banana.banana2dec(args.banana, args.dictstart, args.shiftend, args.dictionary)) + alphabet = None + if not args.alphabet is None: + alphabet = [list(i) for i in args.alphabet.split(",")] + + print(banana.banana2dec(args.banana, args.alphastart, args.shiftend, alphabet)) + \ No newline at end of file diff --git a/bananarandom.py b/bananarandom.py index d9c31ac..32a1322 100755 --- a/bananarandom.py +++ b/bananarandom.py @@ -4,10 +4,14 @@ import banana if __name__ == "__main__": parser = argparse.ArgumentParser(description="Generate random banana") - parser.add_argument("--dictstart", help="Set starting dictionary", type=int) - parser.add_argument("--shiftend", help="Set shift for ending dictionary", type=int) + parser.add_argument("--alphastart", help="Set starting alphabet", type=int) + parser.add_argument("--shiftend", help="Set shift for ending alphabet", type=int) parser.add_argument("--minlength", help="Set minimum length", type=int) - parser.add_argument("--dictionary", help="Set dictionary", type=list, nargs='+') + parser.add_argument("--alphabet", help="Set alphabet") args = parser.parse_args() - print(banana.bananarandom(args.dictstart, args.shiftend, args.minlength, args.dictionary)) + alphabet = None + if not args.alphabet is None: + alphabet = [list(i) for i in args.alphabet.split(",")] + + print(banana.bananarandom(args.alphastart, args.shiftend, args.minlength, alphabet)) diff --git a/dec2banana.py b/dec2banana.py index da26df4..ed5c424 100755 --- a/dec2banana.py +++ b/dec2banana.py @@ -5,10 +5,15 @@ 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("--dictstart", help="Set starting dictionary", type=int) - parser.add_argument("--shiftend", help="Set shift for ending dictionary", type=int) + parser.add_argument("--alphastart", help="Set starting alphabet", type=int) + parser.add_argument("--shiftend", help="Set shift for ending alphabet", type=int) parser.add_argument("--minlength", help="Set minimum length", type=int) - parser.add_argument("--dictionary", help="Set dictionary", type=list, nargs='+') + parser.add_argument("--alphabet", help="Set alphabet") args = parser.parse_args() - print(banana.dec2banana(args.num, args.dictstart, args.shiftend, args.minlength, args.dictionary)) + alphabet = None + if not args.alphabet is None: + alphabet = [list(i) for i in args.alphabet.split(",")] + + print(banana.dec2banana(args.num, args.alphastart, args.shiftend, args.minlength, alphabet)) + \ No newline at end of file diff --git a/isbanana.py b/isbanana.py index c4c9ddc..86e5fe3 100755 --- a/isbanana.py +++ b/isbanana.py @@ -5,9 +5,13 @@ import banana if __name__ == "__main__": parser = argparse.ArgumentParser(description="Checks if string is banana") parser.add_argument("banana", help="String to be checked") - parser.add_argument("--dictionary", help="Set dictionary", type=list, nargs='+') - parser.add_argument("--dictstart", help="Set starting dictionary", type=int) - parser.add_argument("--shiftend", help="Set shift for ending dictionary", type=int) + parser.add_argument("--alphabet", help="Set alphabet") + parser.add_argument("--alphastart", help="Set starting alphabet", type=int) + parser.add_argument("--shiftend", help="Set shift for ending alphabet", type=int) args = parser.parse_args() - print(banana.isbanana(args.banana, args.dictstart, args.shiftend, args.dictionary)) + alphabet = None + if not args.alphabet is None: + alphabet = [list(i) for i in args.alphabet.split(",")] + + print(banana.isbanana(args.banana, args.alphastart, args.shiftend, alphabet))