1
0
Fork 0
forked from itec/banana

Changed dictionary to alphabet + argparse list

This commit is contained in:
itec78 2020-10-01 17:41:34 +02:00
parent 7f668fe8de
commit 9a38bf63a1
5 changed files with 63 additions and 45 deletions

View file

@ -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)

View file

@ -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))

View file

@ -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))

View file

@ -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))

View file

@ -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))