From 0bd4c72b6e85d98eac1ecdf8e6afdeb8cb1be42e Mon Sep 17 00:00:00 2001 From: Alexandre Possebom Date: Sat, 20 Sep 2014 21:00:22 -0300 Subject: [PATCH] Added numeric password type --- README.md | 8 ++++++-- twik | 30 ++++++++++++++++++++---------- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index c3f0479..328c58d 100644 --- a/README.md +++ b/README.md @@ -13,5 +13,9 @@ positional arguments: -c C length of generated password -p {1,2,3} 1 for ALPHANUMERIC_AND_SPECIAL_CHAR, 2 for ALPHANUMERIC and 3 for NUMERIC -* TODO -* Need fix NUMERIC +Private Key is stored in ~/twik.conf you need change it to match with chrome extension and android app: + +[Profile] +private_key = TFCY2AJI-NBPU-V01E-F7CP-PJIZNRKPF25W + + diff --git a/twik b/twik index b614e28..1b735d3 100755 --- a/twik +++ b/twik @@ -86,12 +86,21 @@ def injectCharacter( input, offset, reserved, seed, length, cStart, cNum ): def removeSpecialCharacters(hash,seed,length): inputChars = list(hash) pivot = 0 - for i in range(0,len(inputChars)): + for i in range(0,length): if not inputChars[i].isdigit() and not inputChars[i].isalpha(): inputChars[i] = chr(((seed + pivot) % 26 + ord('A'))) pivot = i + 1 return "".join(inputChars) +def convertToDigits(hash,seed,length): + inputChars = list(hash) + pivot = 0 + for i in range(0,length): + if not inputChars[i].isdigit(): + inputChars[i] = chr(((seed + ord(inputChars[pivot])) % 10 + ord('0'))) + pivot = i + 1 + return "".join(inputChars) + def generateHash(tag,key,length,password_type): digest = hmac.new(key,tag,sha1).digest(); hash = digest.encode('base64')[:-2] @@ -100,16 +109,17 @@ def generateHash(tag,key,length,password_type): for i in range(0, len( hash )): seed += ord(hash[i]) - hash = injectCharacter(hash, 0, 4, seed, length, '0', 10) + if password_type == PasswordType.NUMERIC: + hash = convertToDigits(hash, seed, length) + else: + hash = injectCharacter(hash, 0, 4, seed, length, '0', 10) + if password_type == PasswordType.ALPHANUMERIC_AND_SPECIAL_CHARS: + hash = injectCharacter(hash, 1, 4, seed, length, '!', 15) + hash = injectCharacter(hash, 2, 4, seed, length, 'A', 26) + hash = injectCharacter(hash, 3, 4, seed, length, 'a', 26) - if password_type == PasswordType.ALPHANUMERIC_AND_SPECIAL_CHARS: - hash = injectCharacter(hash, 1, 4, seed, length, '!', 15) - - if password_type == PasswordType.ALPHANUMERIC: - hash = removeSpecialCharacters(hash, seed, length); - - hash = injectCharacter(hash, 2, 4, seed, length, 'A', 26) - hash = injectCharacter(hash, 3, 4, seed, length, 'a', 26) + if password_type == PasswordType.ALPHANUMERIC: + hash = removeSpecialCharacters(hash, seed, length); return hash[:length]