diff --git a/banana.py b/banana.py index 9c60a9d..c584776 100755 --- a/banana.py +++ b/banana.py @@ -41,6 +41,32 @@ def banana2dec(banana, dictstart = None, shiftend = None, dictionary = None): return(v) +def bananarandom(dictstart = None, shiftend = None, minlength = None, dictionary = None): + import random + + #defaults + if dictstart is None: dictstart = 0 + if shiftend is None: shiftend = 0 + if minlength is None: minlength = 6 + if dictionary is None: dictionary = [list("bcdfglmnprstvz"), list("aeiou")] + + numdict = len(dictionary) + 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 = (i - 1) % numdict + l += 1 + + return(st) + + + + + if __name__ == "__main__": diff --git a/bananarandom.py b/bananarandom.py new file mode 100755 index 0000000..d9c31ac --- /dev/null +++ b/bananarandom.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python3 +import argparse +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("--minlength", help="Set minimum length", type=int) + parser.add_argument("--dictionary", help="Set dictionary", type=list, nargs='+') + args = parser.parse_args() + + print(banana.bananarandom(args.dictstart, args.shiftend, args.minlength, args.dictionary))