forked from itec/banana
Added isbanana
This commit is contained in:
parent
4ac67ffa83
commit
b4d57b16cf
2 changed files with 31 additions and 3 deletions
21
banana.py
21
banana.py
|
@ -30,15 +30,16 @@ def banana2dec(banana, dictstart = None, shiftend = None, dictionary = None):
|
|||
if dictionary is None: dictionary = [list("bcdfglmnprstvz"), list("aeiou")] #, list("123456")
|
||||
|
||||
numdict = len(dictionary)
|
||||
if (len(banana) - shiftend) % numdict != 0:
|
||||
return("Banana non valida")
|
||||
v = 0
|
||||
for i in range(len(banana)):
|
||||
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()
|
||||
|
||||
return("Carattere non valido in posizione", i+1)
|
||||
|
||||
return(v)
|
||||
|
||||
def bananarandom(dictstart = None, shiftend = None, minlength = None, dictionary = None):
|
||||
|
@ -63,7 +64,21 @@ def bananarandom(dictstart = None, shiftend = None, minlength = None, dictionary
|
|||
|
||||
return(st)
|
||||
|
||||
def isbanana(banana, dictstart = None, shiftend = None, dictionary = None):
|
||||
#defaults
|
||||
if dictstart is None: dictstart = 0
|
||||
if shiftend is None: shiftend = 0
|
||||
if dictionary is None: dictionary = [list("bcdfglmnprstvz"), list("aeiou")] #, list("123456")
|
||||
|
||||
numdict = len(dictionary)
|
||||
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]:
|
||||
return(False)
|
||||
|
||||
return(True)
|
||||
|
||||
|
||||
|
||||
|
|
13
isbanana.py
Executable file
13
isbanana.py
Executable file
|
@ -0,0 +1,13 @@
|
|||
#!/usr/bin/env python3
|
||||
import argparse
|
||||
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)
|
||||
args = parser.parse_args()
|
||||
|
||||
print(banana.isbanana(args.banana, args.dictstart, args.shiftend, args.dictionary))
|
Loading…
Reference in a new issue